/** * Finds an entry of the container by its identifier and returns it. * * @param string $id Identifier of the entry to look for. * * @throws \Interop\Container\Exception\NotFoundException No entry was found for this identifier. * @throws \Interop\Container\Exception\ContainerException Error while retrieving the entry. * * @return mixed Entry. */ public function get($id) { if ('kernel' === $id) { return $this->kernel; } elseif ('event_dispatcher' === $id) { return $this->kernel->getDispatcher(); } throw new NotFoundException(sprintf("The service '%s' doesn't exist", $id)); }
/** * @return ContainerInterface * * Initialize the application container: builds kernel services and parameters. * * It must inject: * - services: * - kernel: the kernel * - 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 { return new DefaultContainer($kernel, $kernel->getConfig()->getCacheDir()); }
/** * Builds the service container. * * @param KernelInterface $kernel The kernel that is initializing the container * @return ContainerBuilder The compiled service container * * @throws \RuntimeException */ protected function buildContainer(KernelInterface $kernel) { $dir = $kernel->getConfig()->getCacheDir(); if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException(sprintf("Unable to create the cache directory (%s)\n", $dir)); } } elseif (!is_writable($dir)) { throw new \RuntimeException(sprintf("Unable to write in the cache directory (%s)\n", $dir)); } $container = $this->getContainerBuilder($kernel); $container->addObjectResource($this); $this->prepareContainer($container, $kernel); if (null !== ($cont = $this->registerContainerConfiguration($this->getContainerLoader($container)))) { $container->merge($cont); } return $container; }