Loads the configuration for an extension.
public loadFromExtension ( string $extension, array $values = [] ) : |
||
$extension | string | The extension alias or namespace |
$values | array | An array of values that customizes the extension |
Результат | The current instance |
/** * Test load extension * @throws \LogicException * @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException */ public function testLoadExtension() { $this->container->loadFromExtension($this->extension->getAlias()); $this->container->compile(); // Check that services have been loaded static::assertTrue($this->container->has('timestamp.type')); }
/** * {@inheritdoc} */ protected function setUp() { $this->container = new ContainerBuilder(); $extension = new FakerExtension(); $this->container->registerExtension($extension); $this->container->loadFromExtension($extension->getAlias()); }
/** * Configures the container. * * You can register extensions: * * $c->loadFromExtension('framework', array( * 'secret' => '%secret%' * )); * * Or services: * * $c->register('halloween', 'FooBundle\HalloweenProvider'); * * Or parameters: * * $c->setParameter('halloween', 'lot of fun'); * * @param ContainerBuilder $c * @param LoaderInterface $loader */ protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { $session = ['handler_id' => 'session.handler.predis', 'name' => 'santaSession']; if ($c->getParameter('kernel.environment') === 'test') { $session['storage_id'] = 'session.storage.filesystem'; $session['handler_id'] = 'session.handler.native_file'; } $c->loadFromExtension('framework', ['secret' => 'NotSoRandom...:)', 'session' => $session]); $c->loadFromExtension('twig', ['paths' => [__DIR__ . '/../views/']]); if (empty($_ENV['SLACK_CLIENT_SECRET']) || empty($_ENV['SLACK_CLIENT_ID'])) { $_ENV['SLACK_CLIENT_SECRET'] = 'dummy'; $_ENV['SLACK_CLIENT_ID'] = 'dummy'; } if (empty($_ENV['REDIS_URL'])) { $_ENV['REDIS_URL'] = 'redis://localhost:6379'; } // Slack application credentials $c->setParameter('slack.client_secret', $_ENV['SLACK_CLIENT_SECRET']); $c->setParameter('slack.client_id', $_ENV['SLACK_CLIENT_ID']); $controller = $c->register('santa.controller', SantaController::class); $controller->setAutowired(true); $controller->addArgument(new Parameter('slack.client_id')); $controller->addArgument(new Parameter('slack.client_secret')); $sessionHandler = $c->register('session.handler.predis', Handler::class); $sessionHandler->setPublic(false); $sessionHandler->setAutowired(true); $predis = $c->register('predis', Client::class); $predis->setPublic(false); $predis->addArgument($_ENV['REDIS_URL']); }
public function testWithoutConfiguration() { // An extension is only loaded in the container if a configuration is provided for it. // Then, we need to explicitely load it. $this->container->loadFromExtension($this->extension->getAlias()); $this->container->compile(); $this->assertFalse($this->container->hasParameter('google_tag_manager')); }
/** * Test load extension */ public function testLoadExtension() { $this->container->prependExtensionConfig($this->extension->getAlias(), ['login' => 'XXX']); $this->container->loadFromExtension($this->extension->getAlias()); $this->container->compile(); // Check that services have been loaded $this->assertTrue($this->container->has('hellosign.client')); }
/** * {@ineritdoc} */ protected function setUp() { $this->container = new ContainerBuilder(); $this->container->setParameter('bundle.dir', realpath(__DIR__ . '/../../')); $this->container->registerExtension($extension = new WidopHttpAdapterExtension()); $this->container->loadFromExtension($extension->getAlias()); $this->container->registerExtension(new RequestLabXitiAnalyticsExtension()); }
/** * @return \Ikwattro\GithubEvent\EventHandler */ public function build() { $extension = new GithubEventExtension(); $this->serviceContainer->registerExtension($extension); $this->serviceContainer->loadFromExtension($extension->getAlias(), $this->getConfiguration()); $this->serviceContainer->compile(); return $this; }
public function testDefaultConfiguration() { // An extension is only loaded in the container if a configuration is provided for it. // Then, we need to explicitely load it. $this->container->loadFromExtension($this->extension->getAlias()); $this->container->compile(); $this->assertTrue($this->container->getParameterBag()->has('gg_team_breadcrumb')); }
private function initServiceProxyBundle() { $bundle = new OpenClassroomsServiceProxyBundle(); $serviceProxyExtension = $bundle->getContainerExtension(); $this->container->registerExtension($serviceProxyExtension); $this->container->loadFromExtension('openclassrooms_service_proxy'); $bundle->build($this->container); }
/** * @return \Neoxygen\Neogen\Neogen */ public function build() { $extension = new NeogenExtension(); $this->serviceContainer->registerExtension($extension); $this->serviceContainer->loadFromExtension($extension->getAlias(), $this->getConfiguration()); $this->serviceContainer->compile(); $this->getParserManager()->registerParser(new YamlFileParser()); $this->getParserManager()->registerParser(new CypherPattern()); return $this; }
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { // load bundles' configuration $c->loadFromExtension('framework', ['secret' => '12345', 'profiler' => ['enabled' => true], 'templating' => ['engines' => ['twig']]]); $c->loadFromExtension('web_profiler', ['toolbar' => true]); // add configuration parameters $c->setParameter('mail_sender', '*****@*****.**'); // register services $c->register('app.markdown', 'AppBundle\\Service\\Parser\\Markdown'); }
/** * {@inheritdoc} */ protected function setUp() { $this->assetsHelperMock = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); $this->routerMock = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $this->container = new ContainerBuilder(); $this->container->set('templating.helper.assets', $this->assetsHelperMock); $this->container->set('router', $this->routerMock); $this->container->setParameter('templating.engines', array('php', 'twig')); $this->container->registerExtension($extension = new IvoryCKEditorExtension()); $this->container->loadFromExtension($extension->getAlias()); }
public function testParameters() { $path = Path::join([DATAFIXTURES_DIR, 'config', 'test-parameters.json']); $this->locator->locate('test-parameters.json')->willReturn($path); $this->container->addResource(Argument::that(function (FileResource $resource) use($path) { return $resource->getResource() === $path; }))->shouldBeCalled(); $this->container->loadFromExtension('test-parameters', ['name' => 'test'])->shouldBeCalled(); $this->container->setParameter('test', 'value')->shouldBeCalled(); $this->loader->load('test-parameters.json'); }
/** * {@inheritdoc} */ protected function setUp() { $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $this->container = new ContainerBuilder(); $this->container->addScope(new Scope('request')); $this->container->setParameter('templating.engines', array('php', 'twig')); $this->container->set('request', $this->requestMock); $this->container->registerExtension(new IvoryGoogleMapExtension()); $this->container->registerExtension($httpAdapterExtension = new WidopHttpAdapterExtension()); $this->container->loadFromExtension($httpAdapterExtension->getAlias()); }
/** * @test PrestaDeploymentExtension::load() */ public function testLoadWithoutConfiguration() { $this->container->loadFromExtension($this->extension->getAlias()); $this->container->compile(); $this->assertTrue($this->container->has('presta_deployment.manager.configuration')); $configurationManager = $this->container->get('presta_deployment.manager.configuration'); $this->assertFalse($configurationManager->isOrmEnabled()); $this->assertFalse($configurationManager->isPhpcrEnabled()); $this->assertFalse($configurationManager->isMigrationEnabled()); $this->assertFalse($configurationManager->isDeployRebuildEnabled()); }
/** * @return array */ protected function setUp() { $this->container = new ContainerBuilder(); $this->extension = new ErrorHandlerExtension(); $this->bundle = new ErrorHandlerBundle(); $this->container->setParameter('kernel.environment', 'test'); $this->container->setParameter('kernel.root_dir', sys_get_temp_dir()); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); $this->bundle->build($this->container); }
/** * {@inheritdoc} */ protected function setUp() { $this->menuFactory = $this->createMenuFactoryMock(); $this->eventDispatcher = $this->createEventDispatcherMock(); $this->extension = new LugUiExtension(); $this->container = new ContainerBuilder(); $this->container->set('knp_menu.factory', $this->menuFactory); $this->container->set('event_dispatcher', $this->eventDispatcher); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * {@inheritdoc} */ protected function setUp() { $this->eventDispatcher = $this->createEventDispatcherMock(); $this->logger = $this->createLoggerMock(); $this->producer = $this->createProducerMock(); $this->container = new ContainerBuilder(); $this->container->set('event_dispatcher', $this->eventDispatcher); $this->container->set('logger', $this->logger); $this->container->set('old_sound_rabbit_mq.webhook_producer', $this->producer); $this->container->registerExtension($this->extension = new LugWebhookExtension()); $this->container->loadFromExtension($this->extension->getAlias()); }
protected function setUp() { $this->root = vfsStream::setup('enum'); vfsStream::create(['app' => ['config' => []], 'var' => ['cache' => []], 'src' => ['FooBundle' => ['Resources' => ['config' => ['enum.yml' => "foobar: test\\Enum\\Fixtures\\FooBarType"]], 'FooBundle.php' => '<?php class FooBundle {}'], 'BarBundle' => ['Resources' => ['config' => ['enum.yml' => "onetwo: test\\Enum\\Fixtures\\OneTwoType\nthreefour: test\\Enum\\Fixtures\\OneTwoType"]], 'BarBundle.php' => '<?php class BarBundle {}']]], $this->root); $this->extension = new EnumExtension(); $this->container = new ContainerBuilder(); $this->container->setParameter('kernel.root_dir', $this->root->getChild('app')->path()); $this->container->setParameter('kernel.bundles', []); $this->container->setParameter('kernel.cache_dir', $this->root->getChild('var/cache')->path()); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * {@inheritdoc} */ protected function setUp() { $this->menuFactory = $this->createMenuFactoryMock(); $this->eventDispatcher = $this->createEventDispatcherMock(); $this->extension = new LugAdminExtension(); $this->container = new ContainerBuilder(); $this->container->setParameter('kernel.bundles', ['LugGridBundle' => LugGridBundle::class]); $this->container->set($menuFactoryName = 'knp_menu.factory', $this->menuFactory); $this->container->set($eventDispatcherName = 'event_dispatcher', $this->eventDispatcher); $this->container->setDefinition('lug.ui.menu.builder', (new Definition(AbstractMenuBuilder::class, [new Reference($menuFactoryName), new Reference($eventDispatcherName)]))->setAbstract(true)); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * {@inheritdoc} */ protected function setUp() { $this->extension = new LugAsseticExtension(); $this->kernelRootDir = __DIR__ . '/Fixtures/app'; $this->packages = $this->createPackagesMock(); $this->filesystem = $this->createFilesystemMock(); $this->container = new ContainerBuilder(); $this->container->setParameter('kernel.root_dir', $this->kernelRootDir); $this->container->set('assets.packages', $this->packages); $this->container->set('filesystem', $this->filesystem); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
public function testUserParametersAreMostImportantThanDefaultOne() { $container = new ContainerBuilder(); $container->getParameterBag()->set('key', 'user_value'); $container->registerExtension(new ExtensionA()); $container->loadFromExtension('a'); $container->registerExtension($b = new ExtensionB()); $container->loadFromExtension('b'); $pass = new MergeExtensionConfigurationPass(); $pass->process($container); $this->assertSame('user_value', $container->getParameter('key')); $this->assertSame('user_value', $b->parameterKey); }
/** * Configures the dev environment container. * * @param ContainerBuilder $container */ private function configureDevContainer(ContainerBuilder $container) { // framework configuration $container->loadFromExtension('framework', ['router' => ['resource' => '%kernel.root_dir%/config/routing_dev.yml', 'strict_requirements' => true], 'profiler' => ['only_exceptions' => false]]); // web profile configuration $container->loadFromExtension('web_profiler', ['toolbar' => true, 'intercept_redirects' => false]); // check if there is a default delivery address if ($container->hasParameter('mailer_delivery_address')) { $mailerDeliveryAddress = $container->getParameter('mailer_delivery_address'); if (filter_var($mailerDeliveryAddress, FILTER_VALIDATE_EMAIL)) { $container->loadFromExtension('swiftmailer', ['delivery_address' => $mailerDeliveryAddress]); } } }
protected function setUp() { if (class_exists('Symfony\\Component\\Asset\\Packages')) { $this->assetsHelperMock = $this->getMockBuilder('Symfony\\Component\\Asset\\Packages')->disableOriginalConstructor()->getMock(); } else { $this->assetsHelperMock = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); } $this->routerMock = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $this->container = new ContainerBuilder(); $this->container->set('assets.packages', $this->assetsHelperMock); $this->container->set('router', $this->routerMock); $this->container->registerExtension($framework = new FrameworkExtension()); $this->container->loadFromExtension($framework->getAlias()); $this->container->registerExtension($tinymce = new FMTinyMCEExtension()); $this->container->loadFromExtension($tinymce->getAlias()); }
public static function createContainer(array $parameters = array(), array $extensions = array(), array $compilerPasses = array()) { $container = new ContainerBuilder(); foreach ($extensions as $extension) { if ($extension instanceof ExtensionInterface) { $container->registerExtension($extension); if (!method_exists($extension, 'getAutoload') || $extension->getAutoload()) { $container->loadFromExtension($extension->getAlias(), $parameters); } } } $container->getParameterBag()->add($parameters); foreach ($compilerPasses as $compilerPass) { if ($compilerPass instanceof CompilerPassInterface) { $container->addCompilerPass($compilerPass); } } // $loader = new YamlFileLoader( // $container, // new FileLocator(__DIR__ . '/../../../config/') // ); // $loader->load('config.yml'); $container->compile(); return $container; }
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { $loader->load(__DIR__ . '/config/config.yml'); if (isset($this->bundles['WebProfilerBundle'])) { $c->loadFromExtension('web_profiler', ['toolbar' => TRUE, 'intercept_redirects' => FALSE]); } }
public function testShouldAutoregisterSwiftmailerMailers() { $swiftExtension = $this->prophesize(ExtensionInterface::class); $swiftExtension->getAlias()->willReturn('swiftmailer'); $swiftExtension->getNamespace()->willReturn(__NAMESPACE__); $this->container->setParameter('fazland.notifire.emails.autoconfigure_swiftmailer', true); $this->container->setParameter('kernel.debug', true); $this->container->registerExtension($swiftExtension->reveal()); $this->container->loadFromExtension('swiftmailer', ['mailers' => ['first' => ['transport' => 'smtp'], 'second' => ['transport' => 'custom_transport']]]); $this->container->register('fazland.notifire.handler.swiftmailer.prototype', SwiftMailerHandler::class)->setAbstract(true)->setPublic(false)->setArguments([null, null]); $this->pass->process($this->container); $this->assertTrue($this->container->has('fazland.notifire.handler.email.first')); $this->assertTrue($this->container->has('fazland.notifire.handler.email.second')); $this->assertEquals(SwiftMailerHandler::class, $this->container->getDefinition('fazland.notifire.handler.email.first')->getClass()); $this->assertEquals(SwiftMailerHandler::class, $this->container->getDefinition('fazland.notifire.handler.email.second')->getClass()); }
/** * {@inheritdoc} */ protected function setUp() { $this->authorizationChecker = $this->createAuthorizationCheckerMock(); $this->translator = $this->createTranslatorMock(); $this->propertyAccessor = $this->createPropertyAccessorMock(); $this->session = $this->createSessionMock(); $this->formFactory = $this->createFormFactoryMock(); $this->formRenderer = $this->createFormRendererMock(); $this->registry = $this->createRegistryMock(); $this->router = $this->createRouterMock(); $this->requestStack = $this->createRequestStackMock(); $this->gridHandler = $this->createGridHandler(); $this->extension = new LugResourceExtension(); $this->container = new ContainerBuilder(); $this->container->set('security.authorization_checker', $this->authorizationChecker); $this->container->set('translator', $this->translator); $this->container->set('property_accessor', $this->propertyAccessor); $this->container->set('session', $this->session); $this->container->set('form.factory', $this->formFactory); $this->container->set('twig.form.renderer', $this->formRenderer); $this->container->set('doctrine', $this->registry); $this->container->set('router', $this->router); $this->container->set('request_stack', $this->requestStack); $this->container->set('lug.grid.handler', $this->gridHandler); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * @param ContainerBuilder $container */ private function prepareContainer(ContainerBuilder $container) { foreach ($this->getDefaultExtensions() as $ext) { $container->registerExtension($ext); $container->loadFromExtension($ext->getAlias()); } }
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) { $parser = new \Symfony\Component\Yaml\Parser(); $parametersFile = file_get_contents($this->getRootDir() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'parameters.yml'); $parameters = $parser->parse($parametersFile); $c->loadFromExtension('framework', ['secret' => 'none']); $c->addDefinitions(['git_automation.jira_api' => $this->createJiraApiService($parameters['parameters'])]); }