compile() public method

This method passes the container to compiler passes whose job is to manipulate and optimize the container. The main compiler passes roughly do four things: * The extension configurations are merged; * Parameter values are resolved; * The parameter bag is frozen; * Extension loading is disabled.
public compile ( )
 /**
  * @param null $configPath
  * @param array $configFilenames
  */
 function __construct($configPath = null, $configFilenames = array())
 {
     $configPath = $configPath == null ? __DIR__ . '/../../../../../../app/config' : $configPath;
     $this->container = new ContainerBuilder();
     // Load app parameters and config files into container
     $loader = new YamlFileLoader($this->container, new FileLocator($configPath));
     $loader->load('parameters.yml');
     foreach ($configFilenames as $filename) {
         $loader->load($filename);
     }
     $appName = $this->container->getParameter('application_name');
     $appVersion = $this->container->getParameter('application_version');
     parent::__construct($appName, $appVersion);
     // Set dispatcher definition, register listeners and subscribers
     $dispatcherDef = $this->container->register('event_dispatcher', 'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher');
     $dispatcherDef->addArgument($this->container);
     $this->registerEventListeners();
     $this->container->compile();
     // Once container is compiled we can get the event_dispatcher from dic
     $this->dispatcher = $this->container->get('event_dispatcher');
     // Add console commands (services console.command tagged)
     foreach ($this->getTaggedCommands() as $id) {
         $command = $this->container->get($id);
         $this->add($command);
     }
 }
 public function testTemplatingConfiguration()
 {
     $this->loadConfiguration($this->container, 'simple');
     $this->container->compile();
     $helper = $this->container->get('fm_tinymce.templating.helper');
     $this->assertInstanceOf('FM\\TinyMCEBundle\\Templating\\TinyMCEHelper', $helper);
 }
 public function testReconnectConfiguration()
 {
     $this->initContainer();
     $this->loadConfiguration($this->container, 'reconnect_config');
     $this->container->compile();
     $this->assert->boolean($this->container->has('m6_redis'))->isIdenticalTo(true)->and()->object($serviceRedis = $this->container->get('m6_redis'))->isInstanceOf('M6Web\\Bundle\\RedisBundle\\Redis\\Redis');
 }
Example #4
0
 /**
  * Builds the container.
  * @param array $parameters
  */
 public function build($parameters = array())
 {
     // sort array by key to generate the container name
     ksort($parameters);
     // needed for new packages installed
     $composerClass = array_filter(get_declared_classes(), function ($item) {
         if (0 === strpos($item, 'ComposerAutoloaderInit')) {
             return true;
         }
     });
     $composerClass = array_pop($composerClass);
     // generate hash
     $parametersHash = md5(serialize($parameters) . $composerClass);
     $containerClass = 'Container' . $parametersHash;
     $isDebug = true;
     $file = sprintf('%s/ladybug_cache/%s.php', sys_get_temp_dir(), $parametersHash);
     $containerConfigCache = new ConfigCache($file, $isDebug);
     if (!$containerConfigCache->isFresh()) {
         $this->initializeContainer();
         $this->loadServices();
         $this->loadThemes();
         $this->loadPlugins();
         $this->setParameters($parameters);
         $this->container->compile();
         $dumper = new PhpDumper($this->container);
         $containerConfigCache->write($dumper->dump(array('class' => $containerClass)), $this->container->getResources());
     } else {
         require_once $file;
         $this->container = new $containerClass();
     }
 }
 /**
  * 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'));
 }
 /**
  * @return SymfonyContainerBuilder
  */
 public function compile()
 {
     $this->registerServices($this->parameters['services']);
     $this->builder->setResourceTracking(false);
     $this->builder->compile();
     return $this->builder;
 }
Example #7
0
 protected function boot()
 {
     if ($this->hasBooted()) {
         return;
     }
     // Nothing to do
     if ($this->debug) {
         $this->setContainer(new ContainerBuilder(new ParameterBag($this->getAppParameters())));
         $this->loadContainerConfiguration();
     } else {
         $filename = $this->getContainerCacheFilename();
         if (file_exists($filename)) {
             require_once $filename;
             $this->setContainer(new CachedContainer());
         } else {
             $this->setContainer(new ContainerBuilder(new ParameterBag($this->getAppParameters())));
             $this->loadContainerConfiguration();
             $this->container->compile();
             if ($this->containerIsCacheable()) {
                 $dumper = new PhpDumper($this->container);
                 file_put_contents($filename, $dumper->dump());
             }
         }
     }
 }
 public function testIfAServiceDefinitionIsNotCorrectAnExceptionWillBeThrown()
 {
     $loader = new XmlFileLoader($this->container, new FileLocator(__DIR__ . '/Fixtures'));
     $loader->load('incorrect_service_definitions.xml');
     $this->setExpectedException('Matthias\\SymfonyServiceDefinitionValidator\\Exception\\InvalidServiceDefinitionsException');
     $this->container->compile();
 }
 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'));
 }
 /**
  * @test
  */
 public function it_gets_cleaners()
 {
     $this->createCleaner('cleaner1');
     $this->createCleaner('cleaner2');
     $this->createCleaner('cleaner3');
     $this->container->compile();
     $this->resolverContainsCleaners(array('cleaner1', 'cleaner2', 'cleaner3'));
 }
 /**
  * @test
  */
 public function it_gets_fingers_crossed_handlers()
 {
     $this->createFingersCrossedHandler('monolog.handler.handler1');
     $this->createFingersCrossedHandler('monolog.handler.handler2');
     $this->createFingersCrossedHandler('monolog.handler.handler3');
     $this->container->compile();
     $this->resolverContainsFingersCrossedHandlers(array('monolog.handler.handler1', 'monolog.handler.handler2', 'monolog.handler.handler3'));
 }
Example #12
0
 public function __construct()
 {
     $this->container = new ContainerBuilder();
     $this->container->addCompilerPass(new CommandBusCompilerPass());
     $this->container->addCompilerPass(new QueryBusCompilerPass());
     $this->getConfigServices();
     $this->container->compile();
 }
 /**
  * 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'));
 }
 public function testSharedService()
 {
     $this->loader->load(__DIR__ . '/Fixtures/sharedService.yml');
     $this->container->compile();
     $one = $this->container->get('foo');
     $two = $this->container->get('foo');
     $this->assertNotSame($one, $two);
 }
 /**
  * @test
  */
 public function it_configures_a_chain_of_buses_according_to_the_given_priorities()
 {
     $this->createBusDefinition('middleware100', 100);
     $this->createBusDefinition('middleware-100', -100);
     $this->createBusDefinition('middleware200', 200);
     $this->container->compile();
     $this->commandBusContainsMiddlewares(array('middleware200', 'middleware100', 'middleware-100'));
 }
 /**
  * Tests the rest client configuration
  *
  * @test
  *
  * @covers Ci\RestClientBundle\DependencyInjection\CiRestClientExtension::load
  * @covers Ci\RestClientBundle\DependencyInjection\Configuration::getConfigTreeBuilder
  */
 public function configuration()
 {
     $preConfigs = array('ci_rest_client' => array('curl' => array('defaults' => array('CURLOPT_MAXREDIRS' => 30))));
     $this->loadConfiguration($this->container, $preConfigs);
     $this->container->compile();
     $this->assertTrue($this->container->hasParameter('ci.restclient.curl.defaults'));
     $this->assertSame($preConfigs['ci_rest_client']['curl']['defaults']['CURLOPT_MAXREDIRS'], $this->container->getParameter('ci.restclient.curl.defaults')[CURLOPT_MAXREDIRS]);
 }
 /**
  * @expectedException \LogicException
  */
 public function testInvalidProcessorNotConnected()
 {
     $def = new Definition('error_handler.test.processor');
     $def->setClass(get_class(new InvalidProcessor()));
     $def->addTag('error_handler.processor');
     $this->container->setDefinition('error_handler.test.processor', $def);
     $this->container->compile();
 }
Example #18
0
 /**
  * @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;
 }
Example #19
0
 public function testEnumTypeDefinitionsFromBundles()
 {
     $this->container->setParameter('kernel.bundles', ['FooBundle', 'BarBundle']);
     require_once $this->root->getChild('src/FooBundle/FooBundle.php')->url();
     require_once $this->root->getChild('src/BarBundle/BarBundle.php')->url();
     $this->container->compile();
     $this->assertAddTypeCalls(['foobar' => FooBarType::class, 'onetwo' => OneTwoType::class, 'threefour' => OneTwoType::class]);
 }
 /**
  * @test
  */
 public function it_gets_close_buffer_handlers()
 {
     $this->createBufferHandler('monolog.handler.handler1');
     $this->createBufferHandler('monolog.handler.handler2');
     $this->createBufferHandler('monolog.handler.handler3');
     $this->container->compile();
     $this->resolverContainsBufferHandler(array('monolog.handler.handler1', 'monolog.handler.handler2', 'monolog.handler.handler3'));
 }
 protected function initContainer($resource, $debug = false)
 {
     $this->container = new ContainerBuilder();
     $this->container->register('event_dispatcher', new EventDispatcher());
     $this->container->registerExtension(new BaseM6WebStatsdExtension());
     $this->loadConfiguration($this->container, $resource);
     $this->container->setParameter('kernel.debug', $debug);
     $this->container->compile();
 }
 public function testFormExtensions()
 {
     $this->container->compile();
     $services = $this->container->findTaggedServiceIds('form.type_extension');
     $this->assertArrayHasKey('ivory_ordered_form.form_extension', $services);
     $this->assertArrayHasKey('ivory_ordered_form.button_extension', $services);
     $this->assertInstanceOf('Ivory\\OrderedForm\\Extension\\OrderedFormExtension', $this->container->get('ivory_ordered_form.form_extension'));
     $this->assertInstanceOf('Ivory\\OrderedForm\\Extension\\OrderedButtonExtension', $this->container->get('ivory_ordered_form.button_extension'));
 }
 /**
  * @test
  */
 public function it_configures_a_chain_of_buses_according_to_the_given_priorities()
 {
     $this->createBusDefinition('bus100', 100);
     $this->createBusDefinition('bus-100', -100);
     $this->createBusDefinition('bus200', 200);
     $this->container->compile();
     $this->busChainContains(array('bus200', 'bus100', 'bus-100'));
     $this->mainBusIs('bus200');
 }
 /**
  * Test normal config
  */
 public function testTest()
 {
     $this->loadConfiguration($this->container, 'test');
     $this->container->compile();
     $this->assertTrue($this->container->hasParameter('robots_txt'));
     $robotsTxt = $this->container->getParameter('robots_txt');
     $this->assertNotEmpty($robotsTxt);
     $this->assertEquals($robotsTxt[0], 'User-agent: *');
 }
 /**
  * @test
  */
 public function it_gets_mailers()
 {
     $this->createMailer('mailer1', true);
     $this->createMailer('mailer2');
     $this->createMailer('mailer3');
     $this->container->compile();
     $this->matchSpools(array('swiftmailer.mailer.mailer1.spool', 'swiftmailer.mailer.mailer2.spool', 'swiftmailer.mailer.mailer3.spool'));
     $this->matchTransports(array('swiftmailer.mailer.mailer1.transport.real', 'swiftmailer.mailer.mailer2.transport.real', 'swiftmailer.mailer.mailer3.transport.real'));
     $this->matchNames();
 }
Example #26
0
 /**
  * @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;
 }
Example #27
0
 /**
  * Runs a command and returns the exit status.
  *
  * If an output manager is not provided, a new one will be created. The
  * new output stream will use a memory stream, and the instance will be
  * set as the `$output` argument by reference.
  *
  * @param InputInterface  $input   The input manager.
  * @param OutputInterface &$output The output manager.
  *
  * @return integer The exit status.
  */
 public function runCommand(InputInterface $input = null, OutputInterface &$output = null)
 {
     if ($this->container instanceof ContainerBuilder && !$this->container->isFrozen()) {
         $this->container->compile();
     }
     if (null === $output) {
         $output = new StreamOutput(fopen('php://memory', 'r+'));
     }
     return $this->application->run($input, $output);
 }
 /**
  * Ensures that the compiler pass is also able to decorate an aliased translator.
  */
 public function testPassDecoratesAliasedTranslator()
 {
     $translatorClass = $this->getMockClass('Symfony\\Component\\Translation\\TranslatorInterface');
     $translatorDefinition = new Definition($translatorClass);
     $this->container->setDefinition('translator.default', $translatorDefinition);
     $this->container->setAlias('translator', 'translator.default');
     $this->container->compile();
     $translator = $this->container->get('translator');
     $this->assertInstanceOf('Webfactory\\IcuTranslationBundle\\Translator\\FormatterDecorator', $translator);
 }
Example #29
0
 public function compile()
 {
     /**
      * @var $pass tubepress_spi_ioc_CompilerPassInterface
      */
     foreach ($this->_tubePressCompilerPasses as $pass) {
         $pass->process($this);
     }
     $compilerConfig = $this->_delegateContainerBuilder->getCompilerPassConfig();
     $compilerConfig->setRemovingPasses(array(new \Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass(), new \Symfony\Component\DependencyInjection\Compiler\RemoveAbstractDefinitionsPass(), new \Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass(), new \Symfony\Component\DependencyInjection\Compiler\RepeatedPass(array(new \Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass(), new \Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass())), new \Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass()));
     $this->_delegateContainerBuilder->compile();
 }
 /**
  * @test PrestaDeploymentExtension::load()
  */
 public function testLoadWithYamlConfiguration()
 {
     $loader = new YamlFileLoader($this->container, new FileLocator(__DIR__ . '/Fixtures/'));
     $loader->load('config.yml');
     $this->container->compile();
     $this->assertTrue($this->container->has('presta_deployment.manager.configuration'));
     $configurationManager = $this->container->get('presta_deployment.manager.configuration');
     $this->assertTrue($configurationManager->isOrmEnabled());
     $this->assertTrue($configurationManager->isPhpcrEnabled());
     $this->assertTrue($configurationManager->isMigrationEnabled());
     $this->assertTrue($configurationManager->isDeployRebuildEnabled());
 }