public function testInstanceName() { $container = new ContainerBuilder(); $loader = new GodfatherExtension(); $loader->load(array($this->getConfigWithCamelCaseNamedContext()), $container); $this->assertTrue($container->hasAlias('godfather.object_manager')); }
private function defineGodfatherConfiguration($config, ContainerBuilder $container) { $godfatherConfiguration = array(); foreach ($config['roles'] as $roleName => $role) { $roleStrategy = array('contexts' => array('item_handler' => array())); if (isset($role['fallback_strategy'])) { $roleStrategy['contexts']['handler']['fallback'] = $role['fallback_strategy']; } $godfatherConfiguration['godfather'][$roleName] = $roleStrategy; } $strategy = new GodfatherExtension(); $strategy->load($godfatherConfiguration, $container); }
*/ function getRandomEntityProduct() { switch (rand(0, 2)) { case 0: return new Entity\Mug(); case 1: return new Entity\Tshirt(); case 2: return new \stdClass(); } } // loading config $config = array('default' => array('contexts' => array('manager' => array('fallback' => 'manager.default')))); $container = new ContainerBuilder(); $loader = new GodfatherExtension(); $loader->load(array($config), $container); // loading strategies $loader = new YamlFileLoader($container, new FileLocator(__DIR__)); $loader->load('services.yml'); // loading tagged services $container->addCompilerPass(new CompilerPass()); $container->compile(); // working with strategy $product = getRandomEntityProduct(); // getting the correct manager $strategy = $container->get('godfather')->getManager($product); echo "Random entity class\t" . get_class($product) . PHP_EOL; echo " the manager class\t" . get_class($strategy) . PHP_EOL; echo " manager::getName()\t" . $strategy->getName() . PHP_EOL . PHP_EOL; echo "Please run it again the result may change :) " . PHP_EOL . PHP_EOL;