/** * Merges the configuration given by an extension. * * @param $key string The extension tag to load (namespace.tag) * @param $values array An array of values to customize the extension * * @return BuilderConfiguration The current instance */ public function mergeExtension($key, array $values = array()) { list($namespace, $tag) = explode('.', $key); $config = Loader::getExtension($namespace)->load($tag, $values); $this->merge($config); return $this; }
public function buildContainer(ContainerInterface $container) { $kernelBundleDirs = $container->getParameter('kernel.bundle_dirs'); $kernelBundles = $container->getParameter('kernel.bundles'); $appName = $container->getParameter('kernel.name'); $cacheDir = $container->getParameter('kernel.cache_dir'); Loader::registerExtension(new MongoDBExtension($kernelBundleDirs, $kernelBundles, $appName, $cacheDir)); $metadataDirs = array(); $documentDirs = array(); $bundleDirs = $kernelBundleDirs; foreach ($kernelBundles as $className) { $tmp = dirname(str_replace('\\', '/', $className)); $namespace = str_replace('/', '\\', dirname($tmp)); $class = basename($tmp); if (isset($bundleDirs[$namespace])) { if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Resources/config/doctrine/metadata')) { $metadataDirs[] = realpath($dir); } if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class)) { $documentDirs[] = realpath($dir); } } } $container->setParameter('doctrine.odm.metadata_driver.mapping_dirs', $metadataDirs); $container->setParameter('doctrine.odm.document_dirs', $documentDirs); }
/** * Constructor. * * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance * @param string|array $paths A path or an array of paths where to look for resources */ public function __construct(ContainerBuilder $container, $paths = array()) { parent::__construct($container); if (!is_array($paths)) { $paths = array($paths); } $this->paths = $paths; }
public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new WebExtension()); $dirs = array('%kernel.root_dir%/views/%%bundle%%/%%controller%%/%%name%%%%format%%.php'); foreach ($container->getParameter('kernel.bundle_dirs') as $dir) { $dirs[] = $dir . '/%%bundle%%/Resources/views/%%controller%%/%%name%%%%format%%.php'; } $container->setParameter('templating.loader.filesystem.path', $dirs); }
/** * Customizes the Container instance. * * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance * * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance */ public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new KernelExtension()); $configuration = new BuilderConfiguration(); $loader = new XmlFileLoader(array(__DIR__ . '/../Resources/config', __DIR__ . '/Resources/config')); $configuration->merge($loader->load('services.xml')); if ($container->getParameter('kernel.debug')) { $configuration->merge($loader->load('debug.xml')); $configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher')); } return $configuration; }
/** * Customizes the Container instance. * * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance * * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance */ public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new WebExtension($container->getParameter('kernel.bundle_dirs'), $container->getParameter('kernel.bundles'))); $dirs = array('%kernel.root_dir%/views/%%bundle%%/%%controller%%/%%name%%%%format%%.%%renderer%%'); foreach ($container->getParameter('kernel.bundle_dirs') as $dir) { $dirs[] = $dir . '/%%bundle%%/Resources/views/%%controller%%/%%name%%%%format%%.%%renderer%%'; } $container->setParameter('templating.loader.filesystem.path', $dirs); $configuration = new BuilderConfiguration(); if ($container->getParameter('kernel.debug')) { $loader = new XmlFileLoader(__DIR__ . '/Resources/config'); $configuration->merge($loader->load('debug.xml')); } return $configuration; }
public function testExtensions() { Loader::registerExtension(new \ProjectExtension()); $loader = new ProjectLoader3(self::$fixturesPath . '/yaml'); $config = $loader->load('services10.yml'); $services = $config->getDefinitions(); $parameters = $config->getParameters(); $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements'); $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); try { $config = $loader->load('services11.yml'); $this->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (\InvalidArgumentException $e) { } try { $config = $loader->load('services12.yml'); $this->fail('->load() throws an InvalidArgumentException if an extension is not loaded'); } catch (\InvalidArgumentException $e) { } }
public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new DoctrineExtension($container->getParameter('kernel.bundle_dirs'), $container->getParameter('kernel.bundles'))); $metadataDirs = array(); $entityDirs = array(); $bundleDirs = $container->getParameter('kernel.bundle_dirs'); foreach ($container->getParameter('kernel.bundles') as $className) { $tmp = dirname(str_replace('\\', '/', $className)); $namespace = str_replace('/', '\\', dirname($tmp)); $class = basename($tmp); if (isset($bundleDirs[$namespace])) { if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Resources/config/doctrine/metadata')) { $metadataDirs[] = realpath($dir); } if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Entities')) { $entityDirs[] = realpath($dir); } } } $container->setParameter('doctrine.orm.metadata_driver.mapping_dirs', $metadataDirs); $container->setParameter('doctrine.orm.entity_dirs', $entityDirs); }
public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new MongoDBExtension($container->getParameter('kernel.bundles'))); }
public function testUseMulitpleDocumentManagers() { $container = $this->createContainer(); $bundle = new Bundle(); $bundle->buildContainer($container); $mongoExtension = Loader::getExtension('mongodb'); $config = $this->defaultConfiguration; $config['document_managers']['test'] = array('connection' => 'test'); $config['connections']['test'] = array('server' => 'localhost/testing'); $configuration = $mongoExtension->odmLoad($config); $container->merge($configuration); $dmDefault = $container->getDoctrine_ODM_DefaultDocumentManagerService(); $dmTest = $container->getDoctrine_ODM_TestDocumentManagerService(); $this->assertTrue($dmDefault !== $dmTest); }
public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new SwiftmailerExtension()); }
$t->ok(!$services['non_shared']->isShared(), '->load() parses the shared attribute'); $t->is($services['constructor']->getConstructor(), 'getInstance', '->load() parses the constructor attribute'); $t->is($services['file']->getFile(), '%path%/foo.php', '->load() parses the file tag'); $t->is($services['arguments']->getArguments(), array('foo', new Reference('foo'), array(true, false)), '->load() parses the argument tags'); $t->is($services['configurator1']->getConfigurator(), 'sc_configure', '->load() parses the configurator tag'); $t->is($services['configurator2']->getConfigurator(), array(new Reference('baz'), 'configure'), '->load() parses the configurator tag'); $t->is($services['configurator3']->getConfigurator(), array('BazClass', 'configureStatic'), '->load() parses the configurator tag'); $t->is($services['method_call1']->getMethodCalls(), array(array('setBar', array())), '->load() parses the method_call tag'); $t->is($services['method_call2']->getMethodCalls(), array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), '->load() parses the method_call tag'); $aliases = $config->getAliases(); $t->ok(isset($aliases['alias_for_foo']), '->load() parses aliases'); $t->is($aliases['alias_for_foo'], 'foo', '->load() parses aliases'); // extensions $t->diag('extensions'); Loader::registerExtension(new ProjectExtension()); $loader = new ProjectLoader($fixturesPath.'/yaml'); $config = $loader->load('services10.yml'); $services = $config->getDefinitions(); $parameters = $config->getParameters(); $t->ok(isset($services['project.service.bar']), '->load() parses extension elements'); $t->ok(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); try { $config = $loader->load('services11.yml'); $t->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (InvalidArgumentException $e) {
public function testExtensions() { Loader::registerExtension(new \ProjectExtension()); $loader = new ProjectLoader2(self::$fixturesPath . '/xml'); $config = $loader->load('services10.xml'); $services = $config->getDefinitions(); $parameters = $config->getParameters(); $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements'); $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements'); $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements'); try { $config = $loader->load('services11.xml'); $this->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertStringStartsWith('There is no extension able to load the configuration for "foobar:foobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid'); } try { $config = $loader->load('services12.xml'); $this->fail('->load() throws an InvalidArgumentException if an extension is not loaded'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if an extension is not loaded'); $this->assertStringStartsWith('The "foobar" tag is not valid (in', $e->getMessage(), '->load() throws an InvalidArgumentException if an extension is not loaded'); } }
public function testExtensions() { Loader::registerExtension(new \ProjectExtension()); Loader::registerExtension(new \ProjectWithXsdExtension()); $loader = new ProjectLoader2(self::$fixturesPath . '/xml'); // extension without an XSD $config = $loader->load('extensions/services1.xml'); $services = $config->getDefinitions(); $parameters = $config->getParameterBag()->all(); $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements'); $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements'); $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements'); // extension with an XSD $config = $loader->load('extensions/services2.xml'); $services = $config->getDefinitions(); $parameters = $config->getParameterBag()->all(); $this->assertTrue(isset($services['project.service.bar']), '->load() parses extension elements'); $this->assertTrue(isset($parameters['project.parameter.bar']), '->load() parses extension elements'); $this->assertEquals('BAR', $services['project.service.foo']->getClass(), '->load() parses extension elements'); $this->assertEquals('BAR', $parameters['project.parameter.foo'], '->load() parses extension elements'); // extension with an XSD (does not validate) try { $config = $loader->load('extensions/services3.xml'); $this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); $this->assertRegexp('/The attribute \'bar\' is not allowed/', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD'); } // non-registered extension try { $config = $loader->load('extensions/services4.xml'); $this->fail('->load() throws an InvalidArgumentException if the tag is not valid'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid'); $this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid'); } // non-existent tag for a known extension try { $config = $loader->load('extensions/services5.xml'); $this->fail('->load() throws an InvalidArgumentException if a tag is not valid for a given extension'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if a tag is not valid for a given extension'); $this->assertStringStartsWith('The tag "projectwithxsd:foobar" is not defined in the "projectwithxsd" extension.', $e->getMessage(), '->load() throws an InvalidArgumentException if a tag is not valid for a given extension'); } }
/** * @param Symfony\Components\DependencyInjection\ContainerInterface $container * @return Symfony\Components\DependencyInjection\ContainerInterface */ public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new ServerExtension($container)); return $container; }
public function buildContainer(ContainerInterface $container) { Loader::registerExtension(new PropelExtension()); }