Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / robo / src / Task / Development / PhpServer.php
1 <?php
2 namespace Robo\Task\Development;
3
4 use Robo\Task\Base\Exec;
5
6 /**
7  * Runs PHP server and stops it when task finishes.
8  *
9  * ``` php
10  * <?php
11  * // run server in /public directory
12  * $this->taskServer(8000)
13  *  ->dir('public')
14  *  ->run();
15  *
16  * // run with IP 0.0.0.0
17  * $this->taskServer(8000)
18  *  ->host('0.0.0.0')
19  *  ->run();
20  *
21  * // execute server in background
22  * $this->taskServer(8000)
23  *  ->background()
24  *  ->run();
25  * ?>
26  * ```
27  */
28 class PhpServer extends Exec
29 {
30     /**
31      * @var int
32      */
33     protected $port;
34
35     /**
36      * @var string
37      */
38     protected $host = '127.0.0.1';
39
40     /**
41      * {@inheritdoc}
42      */
43     protected $command = 'php -S %s:%d ';
44
45     /**
46      * @param int $port
47      */
48     public function __construct($port)
49     {
50         $this->port = $port;
51
52         if (strtolower(PHP_OS) === 'linux') {
53             $this->command = 'exec php -S %s:%d ';
54         }
55     }
56
57     /**
58      * @param string $host
59      *
60      * @return $this
61      */
62     public function host($host)
63     {
64         $this->host = $host;
65         return $this;
66     }
67
68     /**
69      * @param string $path
70      *
71      * @return $this
72      */
73     public function dir($path)
74     {
75         $this->command .= "-t $path";
76         return $this;
77     }
78
79     /**
80      * {@inheritdoc}
81      */
82     public function getCommand()
83     {
84         return sprintf($this->command . $this->arguments, $this->host, $this->port);
85     }
86 }