diff --git a/README.md b/README.md index 3cd9de7..9fb0bd6 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 +``` \ No newline at end of file diff --git a/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/Configuration.php b/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/Configuration.php index 7e9169d..22c0f48 100755 --- a/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/Configuration.php +++ b/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/Configuration.php @@ -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() diff --git a/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/GodfatherExtension.php b/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/GodfatherExtension.php index fefb95e..bcdd654 100644 --- a/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/GodfatherExtension.php +++ b/sf2-bundle/PUGX/GodfatherBundle/DependencyInjection/GodfatherExtension.php @@ -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)); } } diff --git a/sf2-bundle/PUGX/GodfatherBundle/Tests/DependencyInjection/GodfatherExtensionTest.php b/sf2-bundle/PUGX/GodfatherBundle/Tests/DependencyInjection/GodfatherExtensionTest.php index be3450a..35a85ab 100755 --- a/sf2-bundle/PUGX/GodfatherBundle/Tests/DependencyInjection/GodfatherExtensionTest.php +++ b/sf2-bundle/PUGX/GodfatherBundle/Tests/DependencyInjection/GodfatherExtensionTest.php @@ -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'); diff --git a/tests/PUGX/Godfather/Test/FunctionalTest.php b/tests/PUGX/Godfather/Test/FunctionalTest.php index 64c60fc..8e3e14c 100644 --- a/tests/PUGX/Godfather/Test/FunctionalTest.php +++ b/tests/PUGX/Godfather/Test/FunctionalTest.php @@ -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());