Example #1
0
 /**
  * Returns the container builder.
  *
  * @return ContainerBuilder The container builder.
  *
  * @throws CacheException If the cached configuration file does not exist.
  */
 public function getContainerBuilder()
 {
     if (null === $this->file) {
         throw CacheException::fileNotExist($this->file);
         // @codeCoverageIgnore
     }
     $container = new ContainerBuilder();
     $loader = new XmlFileLoader($container, new FileLocator());
     $loader->load($this->file);
     $extensions = $container->findTaggedServiceIds(Application::getId('extension'));
     foreach ($extensions as $id => $tag) {
         $container->registerExtension($container->get($id));
     }
     return $container;
 }
Example #2
0
 /**
  * Saves the application container to a cache file
  *
  * @param string  $file  The path to the cache file.
  * @param string  $class The container class name.
  * @param boolean $debug Enable debugging? (see class doc)
  *
  * @throws CacheException If the application could not be saved.
  */
 public function save($file, $class = 'ConsoleContainer', $debug = true)
 {
     $container = $this->getContainer();
     if (!$container instanceof ContainerBuilder) {
         throw CacheException::notBuilder();
         // @codeCoverageIgnore
     }
     $dir = dirname($file);
     if (!file_exists($dir) && !mkdir($dir, 0755, true)) {
         throw CacheException::cannotCreateDir($dir);
         // @codeCoverageIgnore
     }
     if (!$container->isFrozen()) {
         $container->compile();
     }
     $this->dumpXmlConfig($container, $file);
     $dumper = new PhpDumper($container);
     $cache = new ConfigCache($file, $debug);
     $cache->write($dumper->dump(array('class' => $class)), $container->getResources());
 }