Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = \rtrim($this->directory ?? \getcwd(), '/\\') . '/' . $input->getArgument('app');
     if (!\is_file($file)) {
         throw new \RuntimeException(\sprintf('App file not found: "%s"', $file));
     }
     if (!$this->boot->isWorker() && $input->getOption('dev')) {
         $this->executeDev($input, $output);
     } else {
         $peer = \sprintf('%s:%u', $input->getOption('address'), $input->getOption('port'));
         $http = $this->factory->createHttpEndpoint($peer);
         if (!$this->boot->isWorker()) {
             $this->console->disableLogger();
             $logger = new ProcessLogHandler('php://stdout', $this->console->computeLogThreshold($output));
             LoopConfig::getLogger()->addHandler($logger);
         }
         try {
             $this->k1->run(require $file, $http);
         } finally {
             if (!$this->boot->isWorker()) {
                 LoopConfig::getLogger()->removeHandler($logger);
                 $this->console->enableLogger();
             }
         }
     }
 }
Esempio n. 2
0
 public function __construct(string $url, $server, string $bootstrap, int $workerCount = null)
 {
     $this->url = $url;
     $this->server = $server;
     $this->bootstrap = $bootstrap;
     $this->workerCount = $workerCount;
     $this->logger = LoopConfig::getLogger();
     \register_shutdown_function(function () {
         @fclose($this->server);
         foreach ($this->workers as $worker) {
             $worker->stop();
         }
     });
 }
Esempio n. 3
0
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     if (!$this->boot->isWorker()) {
         $this->logger = new ConsoleLogHandler($output, $this->computeLogThreshold($output));
         LoopConfig::getLogger()->addHandler($this->logger);
     }
     try {
         return parent::doRun($input, $output);
     } finally {
         if (!$this->boot->isWorker()) {
             LoopConfig::getLogger()->removeHandler($this->logger);
         }
     }
 }
Esempio n. 4
0
 protected function createContainer() : array
 {
     $builder = new ContainerBuilder();
     $builder->bindInstance(clone $this);
     $builder->bindInstance(new Environment($this->env));
     $builder->share(LoggerInterface::class)->instance(LoopConfig::getLogger());
     $locator = new ResourceLocator($this->providers, $this->resourcePaths, $this->publicResourcePaths);
     $builder->bindInstance($locator);
     $builder->bindInstance(new Assets($this->env['K1_RESOURCE_PATH'], $locator));
     foreach ($this->providers as $provider) {
         $builder->bindInstance($provider);
     }
     $configs = new \SplPriorityQueue();
     $bindings = new \SplPriorityQueue();
     $paths = [\dirname(__DIR__) . '/config'];
     $this->collectPhpFiles($paths, $configs, 300);
     $this->collectPhpFiles($paths, $configs, 250, $this->contextName);
     $paths = [\dirname(__DIR__) . '/bind'];
     $this->collectPhpFiles($paths, $bindings, 300);
     $this->collectPhpFiles($paths, $bindings, 250, $this->contextName);
     foreach ($this->providers as $provider) {
         $this->collectPhpFiles($provider->getConfigPaths(), $configs, 200);
         $this->collectPhpFiles($provider->getConfigPaths(), $configs, 150, $this->contextName);
         $this->collectPhpFiles($provider->getBindingPaths(), $bindings, 200);
         $this->collectPhpFiles($provider->getBindingPaths(), $bindings, 150, $this->contextName);
     }
     $this->collectPhpFiles($this->configPaths, $configs, 100);
     $this->collectPhpFiles($this->configPaths, $configs, 50, $this->contextName);
     $this->collectPhpFiles($this->bindingPaths, $bindings, 100);
     $this->collectPhpFiles($this->bindingPaths, $bindings, 50, $this->contextName);
     $settings = new Settings();
     while (!$configs->isEmpty()) {
         $settings = $settings->mergeWith($this->loadSettings($configs->extract()));
     }
     while (!$bindings->isEmpty()) {
         $this->bind($bindings->extract(), $builder);
     }
     return [$builder, $settings];
 }
Esempio n. 5
0
 protected function processLogs() : \Generator
 {
     // Store reference to the correct channel as the property will be re-initialized when calling stop().
     $channel = $this->channel;
     LoopConfig::getLogger()->addHandler($logger = new ChannelLogHandler($this->channel));
     try {
         while (null !== ($message = (yield $channel->receive()))) {
             yield from $this->transmitter->send($message, self::TYPE_LOG);
         }
     } finally {
         LoopConfig::getLogger()->removeHandler($logger);
         Loop::stop();
     }
 }