コード例 #1
0
 public function testIsFrozen()
 {
     $sc = new Container(new ParameterBag(array('foo' => 'bar')));
     $this->assertFalse($sc->isFrozen(), '->isFrozen() returns false if the parameters are not frozen');
     $sc->compile();
     $this->assertTrue($sc->isFrozen(), '->isFrozen() returns true if the parameters are frozen');
 }
コード例 #2
0
 private function getDumpedContainer()
 {
     static $i = 0;
     $class = 'WebProfilerExtensionTestContainer' . $i++;
     $this->container->compile();
     $dumper = new PhpDumper($this->container);
     eval('?>' . $dumper->dump(array('class' => $class)));
     $container = new $class();
     $container->set('kernel', $this->kernel);
     return $container;
 }
コード例 #3
0
 /**
  * Returns ContainerBuilder by including the default file 'containerBuilder.php' from settings directory.
  *
  * @throws \RuntimeException
  */
 protected function getContainer()
 {
     if ($this->innerContainer instanceof ContainerInterface) {
         // Do nothing
     } elseif (!is_readable($this->innerContainer)) {
         throw new RuntimeException(sprintf("Unable to read file %s\n", $this->innerContainer));
     } else {
         // 'containerBuilder.php' file expects $installDir variable to be set by caller
         $installDir = $this->installDir;
         $this->innerContainer = (require_once $this->innerContainer);
     }
     // Compile container if necessary
     if ($this->innerContainer instanceof ContainerBuilder && !$this->innerContainer->isFrozen()) {
         $this->innerContainer->compile();
     }
 }
コード例 #4
0
 /**
  * Compiles the container.
  *
  * 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 function compile()
 {
     $compiler = $this->getCompiler();
     if ($this->trackResources) {
         foreach ($compiler->getPassConfig()->getPasses() as $pass) {
             $this->addObjectResource($pass);
         }
     }
     $compiler->compile($this);
     if ($this->trackResources) {
         foreach ($this->definitions as $definition) {
             if ($definition->isLazy() && ($class = $definition->getClass()) && class_exists($class)) {
                 $this->addClassResource(new \ReflectionClass($class));
             }
         }
     }
     $this->extensionConfigs = array();
     parent::compile();
 }
コード例 #5
0
ファイル: ContainerBuilder.php プロジェクト: hykz/Depot
 /**
  * Compiles the container.
  *
  * 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.
  *
  * @api
  */
 public function compile()
 {
     if (null === $this->compiler) {
         $this->compiler = new Compiler();
     }
     foreach ($this->compiler->getPassConfig()->getPasses() as $pass) {
         $this->addObjectResource($pass);
     }
     $this->compiler->compile($this);
     $this->extensionConfigs = array();
     parent::compile();
 }
コード例 #6
0
ファイル: ContainerBuilder.php プロジェクト: notbrain/symfony
 /**
  * Compiles the container.
  *
  * 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 function compile()
 {
     $this->compiler->compile($this);
     $this->setExtensionConfigs(array());
     parent::compile();
 }
コード例 #7
0
ファイル: ContainerBuilder.php プロジェクト: kmiladi/symfony
 /**
  * Compiles the container.
  *
  * 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 function compile()
 {
     $compiler = $this->getCompiler();
     if ($this->trackResources) {
         foreach ($compiler->getPassConfig()->getPasses() as $pass) {
             $this->addObjectResource($pass);
         }
     }
     $compiler->compile($this);
     $this->compiled = true;
     foreach ($this->definitions as $id => $definition) {
         if (!$definition->isPublic()) {
             $this->privates[$id] = true;
         }
         if ($this->trackResources && $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class)) {
             $this->addClassResource(new \ReflectionClass($class));
         }
     }
     $this->extensionConfigs = array();
     $bag = $this->getParameterBag();
     parent::compile();
     $this->envPlaceholders = $bag instanceof EnvPlaceholderParameterBag ? $bag->getEnvPlaceholders() : array();
 }
コード例 #8
0
 protected function createTranslator($em, $cacheDir)
 {
     $listener = new GetDatabaseResourcesListener($this->getORMStorage($em), 'xxxxx');
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener('lexik_translation.event.get_database_resources', array($listener, 'onGetDatabaseResources'));
     $container = new Container();
     $container->set('event_dispatcher', $dispatcher);
     $container->compile();
     $loaderIds = array();
     $options = array('cache_dir' => $cacheDir);
     return new TranslatorMock($container, new MessageSelector(), $loaderIds, $options);
 }
コード例 #9
0
 /**
  * Compiles the container.
  *
  * 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 function compile()
 {
     if (null === $this->compiler) {
         $this->initializeCompiler();
     }
     $this->compiler->compile($this);
     $this->setExtensionConfigs(array());
     parent::compile();
 }
コード例 #10
0
 /**
  * Dump a container
  * @param Container $container
  * @param $class
  * @param $location
  * @param string $baseClass
  * @throws \RuntimeException
  */
 public static function dumpContainer(Container $container, $class, $location, $baseClass = 'Symfony\\Component\\DependencyInjection\\Container')
 {
     if (!file_exists($location)) {
         throw new RuntimeException('Dump location does not exist');
     }
     $container->compile();
     $dumper = new PhpDumper($container);
     file_put_contents(realpath($location) . "/{$class}.php", $dumper->dump(array('class' => $class, 'base_class' => $baseClass)));
 }