Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / ServerCommand.php
index e306ceecad63b0db5d82a4f086f96a895b008ac4..92b17d58b9c58429967caecc7df8c765ee566c6b 100644 (file)
@@ -12,9 +12,7 @@ use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Process\ProcessBuilder;
 use Symfony\Component\Process\PhpExecutableFinder;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Console\Core\Command\Command;
 use \Drupal\Console\Core\Utils\ConfigurationManager;
 
 /**
@@ -24,8 +22,6 @@ use \Drupal\Console\Core\Utils\ConfigurationManager;
  */
 class ServerCommand extends Command
 {
-    use CommandTrait;
-
     /**
      * @var string
      */
@@ -63,7 +59,7 @@ class ServerCommand extends Command
                 InputArgument::OPTIONAL,
                 $this->trans('commands.server.arguments.address'),
                 '127.0.0.1:8088'
-            );
+            )->setAliases(['serve']);
     }
 
     /**
@@ -71,76 +67,53 @@ class ServerCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
         $address = $this->validatePort($input->getArgument('address'));
 
         $finder = new PhpExecutableFinder();
         if (false === $binary = $finder->find()) {
-            $io->error($this->trans('commands.server.errors.binary'));
+            $this->getIo()->error($this->trans('commands.server.errors.binary'));
             return 1;
         }
 
-        $router = $this->getRouterPath();
+        $router = $this->configurationManager
+            ->getVendorCoreDirectory() . 'router.php';
+
         $processBuilder = new ProcessBuilder([$binary, '-S', $address, $router]);
         $processBuilder->setTimeout(null);
         $processBuilder->setWorkingDirectory($this->appRoot);
         $process = $processBuilder->getProcess();
 
-        $io->success(
+        $this->getIo()->success(
             sprintf(
                 $this->trans('commands.server.messages.executing'),
                 $binary
             )
         );
 
-        $io->commentBlock(
+        $this->getIo()->commentBlock(
             sprintf(
                 $this->trans('commands.server.messages.listening'),
                 'http://'.$address
             )
         );
 
+        if ($this->getIo()->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
+            $callback = [$this, 'outputCallback'];
+        } else {
+            $callback = null;
+        }
+
         // Use the process helper to copy process output to console output.
-        $this->getHelper('process')->run($output, $process, null, null);
+        $this->getHelper('process')->run($output, $process, null, $callback);
 
         if (!$process->isSuccessful()) {
-            $io->error($process->getErrorOutput());
+            $this->getIo()->error($process->getErrorOutput());
             return 1;
         }
 
         return 0;
     }
 
-    /**
-     * @return null|string
-     */
-    private function getRouterPath()
-    {
-        $routerPath = [
-            sprintf(
-                '%s/.console/router.php',
-                $this->configurationManager->getHomeDirectory()
-            ),
-            sprintf(
-                '%s/console/router.php',
-                $this->configurationManager->getApplicationDirectory()
-            ),
-            sprintf(
-                '%s/%s/config/dist/router.php',
-                $this->configurationManager->getApplicationDirectory(),
-                DRUPAL_CONSOLE_CORE
-            )
-        ];
-
-        foreach ($routerPath as $router) {
-            if (file_exists($router)) {
-                return $router;
-            }
-        }
-
-        return null;
-    }
-
     /**
      * @param string $address
      * @return string
@@ -168,4 +141,10 @@ class ServerCommand extends Command
 
         return $address;
     }
+
+    public function outputCallback($type, $buffer)
+    {
+        // TODO: seems like $type is Process::ERR always
+        echo $buffer;
+    }
 }