vendor/symfony/web-server-bundle/Command/ServerStopCommand.php line 35

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\Bundle\WebServerBundle\Command;
  11. use Symfony\Bundle\WebServerBundle\WebServer;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. use Symfony\Component\Console\Style\SymfonyStyle;
  18. /**
  19.  * Stops a background process running a local web server.
  20.  *
  21.  * @author Christian Flothmann <christian.flothmann@xabbuh.de>
  22.  *
  23.  * @deprecated since Symfony 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
  24.  */
  25. class ServerStopCommand extends Command
  26. {
  27.     protected static $defaultName = 'server:stop';
  28.     private $pidFileDirectory;
  29.     public function __construct(string $pidFileDirectory = null)
  30.     {
  31.         $this->pidFileDirectory = $pidFileDirectory;
  32.         parent::__construct();
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     protected function configure()
  38.     {
  39.         $this
  40.             ->setDefinition([
  41.                 new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
  42.             ])
  43.             ->setDescription('Stop the local web server that was started with the server:start command')
  44.             ->setHelp(<<<'EOF'
  45. <info>%command.name%</info> stops the local web server:
  46.   <info>php %command.full_name%</info>
  47. EOF
  48.             )
  49.         ;
  50.     }
  51.     /**
  52.      * {@inheritdoc}
  53.      */
  54.     protected function execute(InputInterface $input, OutputInterface $output)
  55.     {
  56.         @trigger_error('Using the WebserverBundle is deprecated since Symfony 4.4. The new Symfony local server has more features, you can use it instead.', \E_USER_DEPRECATED);
  57.         $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
  58.         try {
  59.             $server = new WebServer($this->pidFileDirectory);
  60.             $server->stop($input->getOption('pidfile'));
  61.             $io->success('Stopped the web server.');
  62.         } catch (\Exception $e) {
  63.             $io->error($e->getMessage());
  64.             return 1;
  65.         }
  66.         return 0;
  67.     }
  68. }