/** * @param string $service * * @return string */ public static function generateServiceExpression($service) { return '$kernel->getContainer()->get(' . WorkerBootstrapProfile::exportPhpValue($service) . ')'; }
/** * @param ContainerBuilder $container * @param string $name * * @return Definition */ private function createBootstrapProfileDefinition(ContainerBuilder $container, $name) { $killSwitchPath = dirname($container->getParameter('kernel.root_dir')) . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'exsyst_worker' . DIRECTORY_SEPARATOR . 'kill_switch.' . $name . '.json'; $definition = new Definition(WorkerBootstrapProfile::class, [false]); $definition->addMethodCall('addScriptToRequire', [dirname(dirname($container->getParameter('kernel.cache_dir'))) . '/bootstrap.php.cache']); $definition->addMethodCall('addScriptToRequire', [$container->getParameter('kernel.root_dir') . '/AppKernel.php']); $definition->addMethodCall('addStage2GlobalVariableWithExpression', ['kernel', 'new AppKernel(' . WorkerBootstrapProfile::exportPhpValue($container->getParameter('kernel.environment')) . ', ' . WorkerBootstrapProfile::exportPhpValue($container->getParameter('kernel.debug')) . ')']); $definition->addMethodCall('addStage2Part', ['$kernel->loadClassCache();']); $definition->addMethodCall('addStage2Part', ['$kernel->boot();']); $definition->addMethodCall('addStage3Part', ['if ($workerImpl instanceof ' . ContainerAwareInterface::class . ') {' . PHP_EOL . ' $workerImpl->setContainer($kernel->getContainer());' . PHP_EOL . '}']); $definition->addMethodCall('setAdminCookie', [rtrim(strtr(base64_encode(hash_hmac('sha512', $killSwitchPath, $container->getParameter('kernel.secret'), true)), '+/', '-_'), '=')]); $definition->addMethodCall('setKillSwitchPath', [$killSwitchPath]); $definition->setPublic(false); return $definition; }