PageRenderTime 31ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Aura/Framework/Cli/Server/Command.php

https://bitbucket.org/harikt/aura.framework
PHP | 96 lines | 37 code | 12 blank | 47 comment | 1 complexity | 559c7f56c4f3d644ad5e70a5f246461c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. *
  4. * This file is part of the Aura project for PHP.
  5. *
  6. * @package Aura.Framework
  7. *
  8. * @license http://opensource.org/licenses/bsd-license.php BSD
  9. *
  10. */
  11. namespace Aura\Framework\Cli\Server;
  12. use Aura\Framework\Cli\AbstractCommand;
  13. use Aura\Cli\Option;
  14. /**
  15. *
  16. * Setup and run a development server.
  17. *
  18. * @package Aura.Framework
  19. *
  20. */
  21. class Command extends AbstractCommand
  22. {
  23. /**
  24. *
  25. * The path to the PHP executable.
  26. *
  27. * @var string
  28. *
  29. */
  30. protected $php = 'php';
  31. /**
  32. *
  33. * Getopt definitions.
  34. *
  35. * @var array
  36. *
  37. */
  38. protected $options = [
  39. 'port' => [
  40. 'long' => 'port',
  41. 'short' => 'p',
  42. 'param' => Option::PARAM_REQUIRED,
  43. 'multi' => false,
  44. 'default' => 8000,
  45. ],
  46. ];
  47. /**
  48. *
  49. * Set the path to the PHP executable.
  50. *
  51. * @param string $php The path to PHP.
  52. *
  53. * @return void
  54. *
  55. */
  56. public function setPhp($php)
  57. {
  58. $this->php = $php;
  59. }
  60. /**
  61. *
  62. * Setup and run the server.
  63. *
  64. * @return void
  65. *
  66. */
  67. public function action()
  68. {
  69. $url = "http://localhost:{$this->getopt->port}/";
  70. $msg = "Starting the Aura development server @ {$url}";
  71. $this->stdio->outln($msg);
  72. $root = substr(__DIR__, 0, strrpos(__DIR__, 'package'));
  73. $root = $root . 'web';
  74. // change to the web root directory
  75. chdir($root);
  76. $router = __DIR__ . DIRECTORY_SEPARATOR . 'router.php';
  77. $cmd = "{$this->php} -S 0.0.0.0:{$this->getopt->port} {$router}";
  78. $pipe = popen($cmd, 'r');
  79. while (! feof($pipe)) {
  80. $this->stdio->outln(fread($pipe, 2048));
  81. }
  82. pclose($pipe);
  83. }
  84. }