예제 #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;
 }
예제 #2
0
 /**
  * Loads an application using its cached container.
  *
  * @param string  $file  The path to the cache file.
  * @param string  $class The container class name.
  * @param boolean $debug Enable debugging? (see class doc)
  *
  * @return ApplicationCache The loaded application.
  *
  * @throws CacheException If the application could not be loaded.
  */
 public static function load($file, $class = 'ConsoleContainer', $debug = true)
 {
     if (!file_exists($file)) {
         throw CacheException::fileNotExist($file);
         // @codeCoverageIgnore
     }
     $cache = new ConfigCache($file, $debug);
     if (!$cache->isFresh()) {
         throw CacheException::cacheStale($file);
         // @codeCoverageIgnore
     }
     /** @noinspection PhpIncludeInspection */
     require_once $file;
     if (!class_exists($class)) {
         throw CacheException::classNotExist($class, $file);
         // @codeCoverageIgnore
     }
     return new static(new $class());
 }