示例#1
0
 /**
  * {@inheritdoc}
  */
 public function cache($file, $callback)
 {
     if (!is_callable($callback)) {
         throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback)));
     }
     $cache = new ConfigCache($file, $this->debug);
     if (!$cache->isFresh()) {
         call_user_func($callback, $cache);
     }
     return $cache;
 }
 /**
  * @return ContainerInterface
  *
  * Initialize the application container: builds kernel services and parameters.
  *
  * It must inject:
  * - services:
  *     - kernel: the kernel
  *     - kernel.task_collection: The kernel task collection. It must implement TaskCollectionInterface
  *     - event_dispatcher: the kernel event dispatcher
  * - parameters: (If handles parameter)
  *     - kernel.cache_dir: the cache directory (from $kernel->getConfig()->getCacheDir())
  *
  * It should inject specific environment variable as parameters.
  */
 public function initializeContainer(KernelInterface $kernel) : ContainerInterface
 {
     $config = $kernel->getConfig();
     $class = $this->getContainerClassName($config->getEnvironment(), $config->isDebug());
     $cache = new ConfigCache($kernel->getConfig()->getCacheDir() . DIRECTORY_SEPARATOR . $class . '.php', $kernel->getConfig()->isDebug());
     $fresh = true;
     if (!$cache->isFresh()) {
         $container = $this->buildContainer($kernel);
         $container->compile();
         $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass(), $kernel);
         $fresh = false;
     }
     require_once $cache->getPath();
     /** @var \Symfony\Component\DependencyInjection\ContainerInterface $container */
     $container = new $class();
     $container->set('kernel', $kernel);
     if (!$fresh && $container->has('cache_warmer')) {
         $container->get('cache_warmer')->warmUp($container->getParameter('kernel.cache_dir'));
     }
     return new SfInteropContainer($container);
 }
示例#3
0
 protected function initializeContainer()
 {
     $class = $this->getContainerClass();
     $cache = new ConfigCache($this->getCacheDir() . '/' . $class . '.php', $this->debug);
     $fresh = true;
     if (!$cache->isFresh()) {
         $container = $this->buildContainer();
         $container->compile();
         $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
         $fresh = false;
     }
     require_once $cache->getPath();
     $this->container = new $class();
     $this->container->set('kernel', $this);
     if (!$fresh && $this->container->has('cache_warmer')) {
         $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'));
     }
 }