示例#1
0
 public function __construct(Console $console)
 {
     $this->console = $console;
     if ($console->isArgDefined("color")) {
         $value = $console->getArg("color");
         $this->setAnsiColorOption($value);
     }
     if ($console->isArgDefined("log")) {
         $level = $console->getArg("log");
         $level = isset(self::LEVELS[$level]) ? self::LEVELS[$level] : $level;
         $this->setOutputLevel($level);
     }
 }
示例#2
0
 /**
  * Bootstrap a server from command line options
  *
  * @param \Aerys\Logger $logger
  * @param \Aerys\Console $console
  * @return \Aerys\Server
  */
 public function boot(Logger $logger, Console $console) : Server
 {
     $configFile = $this->selectConfigFile((string) $console->getArg("config"));
     $logger->info("Using config file found at {$configFile}");
     if (!(include $configFile)) {
         throw new \DomainException("Config file inclusion failure: {$configFile}");
     } elseif (!defined("AERYS_OPTIONS")) {
         $options = [];
     } elseif (is_array(AERYS_OPTIONS)) {
         $options = AERYS_OPTIONS;
     } else {
         throw new \DomainException("Invalid AERYS_OPTIONS constant: array expected, got " . gettype(AERYS_OPTIONS));
     }
     if ($console->isArgDefined("debug")) {
         $options["debug"] = true;
     }
     $options = $this->generateOptionsObjFromArray($options);
     $vhosts = new VhostContainer();
     $ticker = new Ticker($logger);
     $server = new Server($options, $vhosts, $logger, $ticker);
     $bootLoader = function (Bootable $bootable) use($server, $logger) {
         return $bootable->boot($server, $logger);
     };
     $hosts = \call_user_func($this->hostAggregator) ?: [new Host()];
     foreach ($hosts as $host) {
         $vhost = $this->buildVhost($host, $bootLoader);
         $vhosts->use($vhost);
     }
     return $server;
 }
示例#3
0
 protected function doStart(Console $console) : \Generator
 {
     if ($console->isArgDefined("restart")) {
         $this->logger->critical("You cannot restart a debug aerys instance via command");
         exit(1);
     }
     $server = (yield from $this->bootstrapper->boot($this->logger, $console));
     (yield $server->start());
     $this->server = $server;
 }
示例#4
0
 public function __construct(Console $console, $ipcSock)
 {
     if ($console->isArgDefined("color")) {
         $this->setAnsify($console->getArg("color"));
     }
     $level = $console->getArg("log");
     $level = isset(self::LEVELS[$level]) ? self::LEVELS[$level] : $level;
     $this->setOutputLevel($level);
     $onWritable = $this->makePrivateCallable("onWritable");
     $this->ipcSock = $ipcSock;
     $this->writeWatcherId = \Amp\onWritable($ipcSock, $onWritable, ["enable" => false]);
 }
示例#5
0
 protected function doStart(Console $console) : \Generator
 {
     if ($console->isArgDefined("restart")) {
         $this->logger->critical("You cannot restart a debug aerys instance via command");
         exit(1);
     }
     if (ini_get("zend.assertions") === "-1") {
         $this->logger->warning("Running aerys in debug mode with assertions disabled is not recommended; " . "enable assertions in php.ini (zend.assertions = 1) " . "or disable debug mode (-d) to hide this warning.");
     } else {
         ini_set("zend.assertions", 1);
     }
     $server = (yield from $this->bootstrapper->boot($this->logger, $console));
     (yield $server->start());
     $this->server = $server;
 }
示例#6
0
 /**
  * Bootstrap a server from command line options
  *
  * @param \Aerys\Logger $logger
  * @param \Aerys\Console $console
  * @return \Generator
  */
 public function boot(Logger $logger, Console $console) : \Generator
 {
     $configFile = self::selectConfigFile((string) $console->getArg("config"));
     $logger->info("Using config file found at {$configFile}");
     // may return Promise or Generator for async I/O inside config file
     $returnValue = (include $configFile);
     if (!$returnValue) {
         throw new \DomainException("Config file inclusion failure: {$configFile}");
     }
     if (is_callable($returnValue)) {
         $returnValue = \call_user_func($returnValue);
     }
     if ($returnValue instanceof \Generator) {
         yield from $returnValue;
     } elseif ($returnValue instanceof Promise) {
         (yield $returnValue);
     }
     if (!defined("AERYS_OPTIONS")) {
         $options = [];
     } elseif (is_array(AERYS_OPTIONS)) {
         $options = AERYS_OPTIONS;
     } else {
         throw new \DomainException("Invalid AERYS_OPTIONS constant: expected array, got " . gettype(AERYS_OPTIONS));
     }
     if ($console->isArgDefined("debug")) {
         $options["debug"] = true;
     }
     $options["configPath"] = $configFile;
     $options = $this->generateOptionsObjFromArray($options);
     $vhosts = new VhostContainer();
     $ticker = new Ticker($logger);
     $server = new Server($options, $vhosts, $logger, $ticker, [new Http1Driver(), new Http2Driver()]);
     $bootLoader = function (Bootable $bootable) use($server, $logger) {
         $booted = $bootable->boot($server, $logger);
         if ($booted !== null && !$booted instanceof Middleware && !is_callable($booted)) {
             throw new \InvalidArgumentException("Any return value of " . get_class($bootable) . '::boot() must return an instance of Aerys\\Middleware and/or be callable, got ' . gettype($booted) . ".");
         }
         return $booted ?? $bootable;
     };
     $hosts = \call_user_func($this->hostAggregator) ?: [new Host()];
     foreach ($hosts as $host) {
         $vhost = self::buildVhost($host, $bootLoader);
         $vhosts->use($vhost);
     }
     return $server;
 }
示例#7
0
 private function generateWorkerCommand(Console $console) : string
 {
     $parts[] = \PHP_BINARY;
     if ($ini = \get_cfg_var("cfg_file_path")) {
         $parts[] = "-c";
         $parts[] = $ini;
     }
     $parts[] = "-d";
     $parts[] = "zend.assertions=" . ini_get("zend.assertions");
     $parts[] = __DIR__ . "/../bin/aerys-worker";
     $parts[] = "-i";
     $parts[] = $this->ipcServerUri;
     if ($console->isArgDefined("config")) {
         $parts[] = "-c";
         $parts[] = $console->getArg("config");
     }
     if ($console->isArgDefined("color")) {
         $parts[] = "--color";
         $parts[] = $console->getArg("color");
     }
     if ($console->isArgDefined("log")) {
         $parts[] = "-l";
         $parts[] = $console->getArg("log");
     }
     return implode(" ", array_map("escapeshellarg", $parts));
 }
示例#8
0
 private function generateWorkerCommand(Console $console) : string
 {
     $parts[] = \PHP_BINARY;
     if ($ini = \get_cfg_var("cfg_file_path")) {
         $parts[] = "-c \"{$ini}\"";
     }
     $parts[] = "-d zend.assertions=" . ini_get("zend.assertions");
     $parts[] = __DIR__ . "/../bin/aerys-worker";
     $parts[] = "-i {$this->ipcServerUri}";
     if ($console->isArgDefined("config")) {
         $parts[] = "-c " . $console->getArg("config");
     }
     if ($console->isArgDefined("color")) {
         $parts[] = "--color " . $console->getArg("color");
     }
     if ($console->isArgDefined("log")) {
         $parts[] = "-l " . $console->getArg("log");
     }
     return implode(" ", $parts);
 }