Skip to content

Commit

Permalink
[symfony2-bundle] removed name attribute, used key as name
Browse files Browse the repository at this point in the history
  • Loading branch information
liuggio committed Sep 9, 2013
1 parent 8861eb2 commit e5bdf33
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ Modify the `app/config/config.yml` only if you need:
godfather:
contexts:
manager:
name: manager
fallback: %manager.standard.class%
fallback: @manager_standard # need a reference to a service
interface: %manager.interface.class%
cart: ~
cart:
interface: %cart.interface.class%
```

Set your strategies:
Expand Down Expand Up @@ -150,12 +150,4 @@ take a look at the coverage as well it should be pretty high :)
composer create-project pugx/godfather --dev -s dev
cd godfather
bin/phpunit
```

## TODO

please help me.

1. improve Context Factory
2. gather feedback
3. annotation
```
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private function addContextSection(ArrayNodeDefinition $rootNode)
->arrayNode('contexts')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->end()
->scalarNode('interface')->defaultNull()->end()
->scalarNode('fallback')->defaultNull()->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

foreach ($config['contexts'] as $context) {
$this->addContext($context, $container);
foreach ($config['contexts'] as $name => $context) {
$this->addContext($name, $context, $container);
}
}

/**
* add a Context.
*
* @param array $context A client configuration
* @param string $name The context name
* @param array $context A client configuration
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function addContext(array $context, ContainerBuilder $container)
protected function addContext($name, array $context, ContainerBuilder $container)
{
$godfather = $container->getDefinition(
'godfather'
);

$contextName = $context['name'];
$contextInterface = isset($context['interface'])?$context['interface']:null;
$fallback = null;
if (isset($context['fallback'])) {
$fallback = new Reference($context['fallback']);
}

$godfather->addMethodCall('addContext', array($contextName, $contextInterface, $fallback));
$godfather->addMethodCall('addContext', array($name, $contextInterface, $fallback));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,26 @@ public function testContextCreated()
{
$container = new ContainerBuilder();
$loader = new GodfatherExtension();
$loader->load(array(array('contexts' => array('manager'=>array('name'=>'manager', 'interface'=>'interface', 'fallback'=>'fallback')))), $container);
$loader->load(array(array('contexts' => array('manager'=>array('interface'=>'interface', 'fallback'=>'fallback')))), $container);

$this->assertTrue($container->hasDefinition('godfather'), 'The godfather is loaded');
$godfather = $container->getDefinition('godfather');

$found = false;
foreach ($godfather->getMethodCalls() as $call) {
if ($call[0] == 'addContext' && $call[1][0] == 'manager') {
$found = true;
}
}
$this->assertTrue($found);
}


public function testFallbackService()
{
$container = new ContainerBuilder();
$loader = new GodfatherExtension();
$loader->load(array(array('contexts' => array('manager'=>array('interface'=>'interface', 'fallback'=>'fallback')))), $container);

$this->assertTrue($container->hasDefinition('godfather'), 'The godfather is loaded');
$godfather = $container->getDefinition('godfather');
Expand Down
1 change: 0 additions & 1 deletion tests/PUGX/Godfather/Test/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function setUp()

$this->godfather = new Godfather();
$this->godfather->addContext('cart', 'PUGX\Godfather\Test\Fixture\CartItemInterface', new StandardCartItem());

// start adding billion of strategy
$this->godfather->addStrategy('cart', 'PUGX\Godfather\Test\Fixture\Entity\Ticket', new TicketCartItem());
$this->godfather->addStrategy('cart', 'PUGX\Godfather\Test\Fixture\Entity\Socket', new SocketCartItem());
Expand Down

0 comments on commit e5bdf33

Please sign in to comment.