/** * @param KernelInterface $parent * @param string $namespace * @param string $parentClass * @param string $warmupDir * * @return KernelInterface */ protected function getTempKernel(KernelInterface $parent, $namespace, $parentClass, $warmupDir) { $cacheDir = var_export($warmupDir, true); $rootDir = var_export(realpath($parent->getRootDir()), true); $logDir = var_export(realpath($parent->getLogDir()), true); // the temp kernel class name must have the same length than the real one // to avoid the many problems in serialized resources files $class = substr($parentClass, 0, -1) . '_'; // the temp kernel name must be changed too $name = var_export(substr($parent->getName(), 0, -1) . '_', true); $code = <<<EOF <?php namespace {$namespace} { class {$class} extends {$parentClass} { public function getCacheDir() { return {$cacheDir}; } public function getName() { return {$name}; } public function getRootDir() { return {$rootDir}; } public function getLogDir() { return {$logDir}; } protected function buildContainer() { \$container = parent::buildContainer(); // filter container's resources, removing reference to temp kernel file \$resources = \$container->getResources(); \$filteredResources = array(); foreach (\$resources as \$resource) { if ((string) \$resource !== __FILE__) { \$filteredResources[] = \$resource; } } \$container->setResources(\$filteredResources); return \$container; } } } EOF; $this->getContainer()->get('filesystem')->mkdir($warmupDir); file_put_contents($file = $warmupDir . '/kernel.tmp', $code); require_once $file; $class = "{$namespace}\\{$class}"; return new $class($parent->getEnvironment(), $parent->isDebug()); }
/** * {@inheritdoc} */ public function getLogDir() { return $this->kernel->getLogDir(); }