Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfony/runtime/SymfonyRuntime.php line 131

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Runtime;
  11. use Symfony\Component\Console\Application;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\ArgvInput;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\ConsoleOutput;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. use Symfony\Component\Dotenv\Dotenv;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\HttpKernel\HttpKernelInterface;
  21. use Symfony\Component\Runtime\Internal\MissingDotenv;
  22. use Symfony\Component\Runtime\Internal\SymfonyErrorHandler;
  23. use Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner;
  24. use Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner;
  25. use Symfony\Component\Runtime\Runner\Symfony\ResponseRunner;
  26. // Help opcache.preload discover always-needed symbols
  27. class_exists(MissingDotenv::class, false) || class_exists(Dotenv::class) || class_exists(MissingDotenv::class);
  28. /**
  29.  * Knows the basic conventions to run Symfony apps.
  30.  *
  31.  * In addition to the options managed by GenericRuntime, it accepts the following options:
  32.  *  - "env" to define the name of the environment the app runs in;
  33.  *  - "disable_dotenv" to disable looking for .env files;
  34.  *  - "dotenv_path" to define the path of dot-env files - defaults to ".env";
  35.  *  - "prod_envs" to define the names of the production envs - defaults to ["prod"];
  36.  *  - "test_envs" to define the names of the test envs - defaults to ["test"];
  37.  *  - "use_putenv" to tell Dotenv to set env vars using putenv() (NOT RECOMMENDED.)
  38.  *  - "dotenv_overload" to tell Dotenv to override existing vars
  39.  *
  40.  * When the "debug" / "env" options are not defined, they will fallback to the
  41.  * "APP_DEBUG" / "APP_ENV" environment variables, and to the "--env|-e" / "--no-debug"
  42.  * command line arguments if "symfony/console" is installed.
  43.  *
  44.  * When the "symfony/dotenv" component is installed, .env files are loaded.
  45.  * When "symfony/error-handler" is installed, it is registered in debug mode.
  46.  *
  47.  * On top of the base arguments provided by GenericRuntime,
  48.  * this runtime can feed the app-callable with arguments of type:
  49.  *  - Request from "symfony/http-foundation" if the component is installed;
  50.  *  - Application, Command, InputInterface and/or OutputInterface
  51.  *    from "symfony/console" if the component is installed.
  52.  *
  53.  * This runtime can handle app-callables that return instances of either:
  54.  *  - HttpKernelInterface,
  55.  *  - Response,
  56.  *  - Application,
  57.  *  - Command,
  58.  *  - int|string|null as handled by GenericRuntime.
  59.  *
  60.  * @author Nicolas Grekas <p@tchwork.com>
  61.  */
  62. class SymfonyRuntime extends GenericRuntime
  63. {
  64.     private $input;
  65.     private $output;
  66.     private $console;
  67.     private $command;
  68.     /**
  69.      * @param array {
  70.      *   debug?: ?bool,
  71.      *   env?: ?string,
  72.      *   disable_dotenv?: ?bool,
  73.      *   project_dir?: ?string,
  74.      *   prod_envs?: ?string[],
  75.      *   dotenv_path?: ?string,
  76.      *   test_envs?: ?string[],
  77.      *   use_putenv?: ?bool,
  78.      *   runtimes?: ?array,
  79.      *   error_handler?: string|false,
  80.      *   env_var_name?: string,
  81.      *   debug_var_name?: string,
  82.      *   dotenv_overload?: ?bool,
  83.      * } $options
  84.      */
  85.     public function __construct(array $options = [])
  86.     {
  87.         $envKey $options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV';
  88.         $debugKey $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG';
  89.         if (isset($options['env'])) {
  90.             $_SERVER[$envKey] = $options['env'];
  91.         } elseif (isset($_SERVER['argv']) && class_exists(ArgvInput::class)) {
  92.             $this->options $options;
  93.             $this->getInput();
  94.         }
  95.         if (!($options['disable_dotenv'] ?? false) && isset($options['project_dir']) && !class_exists(MissingDotenv::class, false)) {
  96.             (new Dotenv($envKey$debugKey))
  97.                 ->setProdEnvs((array) ($options['prod_envs'] ?? ['prod']))
  98.                 ->usePutenv($options['use_putenv'] ?? false)
  99.                 ->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']), $options['dotenv_overload'] ?? false);
  100.             if ($this->input && ($options['dotenv_overload'] ?? false)) {
  101.                 if ($this->input->getParameterOption(['--env''-e'], $_SERVER[$envKey], true) !== $_SERVER[$envKey]) {
  102.                     throw new \LogicException(sprintf('Cannot use "--env" or "-e" when the "%s" file defines "%s" and the "dotenv_overload" runtime option is true.'$options['dotenv_path'] ?? '.env'$envKey));
  103.                 }
  104.                 if ($_SERVER[$debugKey] && $this->input->hasParameterOption('--no-debug'true)) {
  105.                     putenv($debugKey.'='.$_SERVER[$debugKey] = $_ENV[$debugKey] = '0');
  106.                 }
  107.             }
  108.             $options['debug'] ?? $options['debug'] = '1' === $_SERVER[$debugKey];
  109.             $options['disable_dotenv'] = true;
  110.         } else {
  111.             $_SERVER[$envKey] ?? $_SERVER[$envKey] = $_ENV[$envKey] ?? 'dev';
  112.             $_SERVER[$debugKey] ?? $_SERVER[$debugKey] = $_ENV[$debugKey] ?? !\in_array($_SERVER[$envKey], (array) ($options['prod_envs'] ?? ['prod']), true);
  113.         }
  114.         $options['error_handler'] ?? $options['error_handler'] = SymfonyErrorHandler::class;
  115.         parent::__construct($options);
  116.     }
  117.     public function getRunner(?object $application): RunnerInterface
  118.     {
  119.         if ($application instanceof HttpKernelInterface) {
  120.             return new HttpKernelRunner($applicationRequest::createFromGlobals());
  121.         }
  122.         if ($application instanceof Response) {
  123.             return new ResponseRunner($application);
  124.         }
  125.         if ($application instanceof Command) {
  126.             $console $this->console ?? $this->console = new Application();
  127.             $console->setName($application->getName() ?: $console->getName());
  128.             if (!$application->getName() || !$console->has($application->getName())) {
  129.                 $application->setName($_SERVER['argv'][0]);
  130.                 $console->add($application);
  131.             }
  132.             $console->setDefaultCommand($application->getName(), true);
  133.             $console->getDefinition()->addOptions($application->getDefinition()->getOptions());
  134.             return $this->getRunner($console);
  135.         }
  136.         if ($application instanceof Application) {
  137.             if (!\in_array(\PHP_SAPI, ['cli''phpdbg''embed'], true)) {
  138.                 echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
  139.             }
  140.             set_time_limit(0);
  141.             $defaultEnv = !isset($this->options['env']) ? ($_SERVER[$this->options['env_var_name']] ?? 'dev') : null;
  142.             $output $this->output ?? $this->output = new ConsoleOutput();
  143.             return new ConsoleApplicationRunner($application$defaultEnv$this->getInput(), $output);
  144.         }
  145.         if ($this->command) {
  146.             $this->getInput()->bind($this->command->getDefinition());
  147.         }
  148.         return parent::getRunner($application);
  149.     }
  150.     /**
  151.      * @return mixed
  152.      */
  153.     protected function getArgument(\ReflectionParameter $parameter, ?string $type)
  154.     {
  155.         switch ($type) {
  156.             case Request::class:
  157.                 return Request::createFromGlobals();
  158.             case InputInterface::class:
  159.                 return $this->getInput();
  160.             case OutputInterface::class:
  161.                 return $this->output ?? $this->output = new ConsoleOutput();
  162.             case Application::class:
  163.                 return $this->console ?? $this->console = new Application();
  164.             case Command::class:
  165.                 return $this->command ?? $this->command = new Command();
  166.         }
  167.         return parent::getArgument($parameter$type);
  168.     }
  169.     protected static function register(GenericRuntime $runtime): GenericRuntime
  170.     {
  171.         $self = new self($runtime->options + ['runtimes' => []]);
  172.         $self->options['runtimes'] += [
  173.             HttpKernelInterface::class => $self,
  174.             Request::class => $self,
  175.             Response::class => $self,
  176.             Application::class => $self,
  177.             Command::class => $self,
  178.             InputInterface::class => $self,
  179.             OutputInterface::class => $self,
  180.         ];
  181.         $runtime->options $self->options;
  182.         return $self;
  183.     }
  184.     private function getInput(): ArgvInput
  185.     {
  186.         if (null !== $this->input) {
  187.             return $this->input;
  188.         }
  189.         $input = new ArgvInput();
  190.         if (isset($this->options['env'])) {
  191.             return $this->input $input;
  192.         }
  193.         if (null !== $env $input->getParameterOption(['--env''-e'], nulltrue)) {
  194.             putenv($this->options['env_var_name'].'='.$_SERVER[$this->options['env_var_name']] = $_ENV[$this->options['env_var_name']] = $env);
  195.         }
  196.         if ($input->hasParameterOption('--no-debug'true)) {
  197.             putenv($this->options['debug_var_name'].'='.$_SERVER[$this->options['debug_var_name']] = $_ENV[$this->options['debug_var_name']] = '0');
  198.         }
  199.         return $this->input $input;
  200.     }
  201. }