.. otherwise we have a mess of LoD violations due to CLImate's exposure public property behavior objects.
Example #1
0
 /**
  * Bootstrap a server from command line options
  *
  * @param PsrLogger $logger
  * @param \Aerys\Console $console
  * @return \Generator
  */
 public function boot(PsrLogger $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 (array_key_exists("debug", $options)) {
         throw new \DomainException('AERYS_OPTIONS constant contains "debug" key; "debug" option is read-only and only settable to true via the -d command line option');
     }
     $options["debug"] = $console->isArgDefined("debug");
     $options["configPath"] = $configFile;
     return $this->init($logger, $options);
 }
Example #2
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;
 }
Example #3
0
 protected function doStart(Console $console) : \Generator
 {
     // Shutdown the whole server in case we needed to stop during startup
     register_shutdown_function(function () use($console) {
         if (!$this->server) {
             // ensure a clean reactor for clean shutdown
             $reactor = \Amp\reactor();
             $filesystem = \Amp\File\filesystem();
             \Amp\reactor(\Amp\driver());
             \Amp\File\filesystem(\Amp\File\driver());
             \Amp\wait((new CommandClient((string) $console->getArg("config")))->stop());
             \Amp\File\filesystem($filesystem);
             \Amp\reactor($reactor);
         }
     });
     $server = (yield from $this->bootstrapper->boot($this->logger, $console));
     (yield $server->start());
     $this->server = $server;
     \Amp\onReadable($this->ipcSock, function ($watcherId) {
         \Amp\cancel($watcherId);
         yield from $this->stop();
     });
 }
Example #4
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));
 }