public function runConsole(InputInterface $input = null, OutputInterface $output = null) { \ini_set('display_errors', '1'); while (\ob_get_level()) { \ob_end_clean(); } \ob_implicit_flush(1); \set_error_handler(function ($severity, $message, $file, $line) { if ($severity & \error_reporting()) { throw new \ErrorException($message, 0, $severity, $file, $line); } }); $this->container->get(Console::class)->run($input, $output); }
public function __construct(Container $container, Routable $routable, RouteCompiler $compiler) { $this->container = $container; $this->routable = $routable; $this->compiler = $compiler; $this->logger = $container->get(LoggerInterface::class, true, static::class); }
public function getDispatcher(Container $container, RouteCompiler $compiler) : Dispatcher { if ($this->dispatcher === null) { if ($this->routable instanceof Routable) { $this->dispatcher = new Dispatcher($container, $this->routable, $compiler); } else { $routable = $this->routable; if (!$routable instanceof Routable && \is_callable($routable)) { if (\is_array($routable)) { $ref = new \ReflectionMethod(\is_object($routable[0]) ? \get_class($routable[0]) : $routable[0], $routable[1]); } elseif (\is_object($routable) && !$routable instanceof \Closure) { $ref = new \ReflectionMethod(\get_class($routable), '__invoke'); } else { $ref = new \ReflectionFunction($routable); } $routable = $routable(...$container->populateArguments($ref)); } else { $routable = $container->get($this->routable); } $this->dispatcher = new Dispatcher($container, $routable, $compiler); } } return $this->dispatcher; }
public function run(Container $container, callable $action) { $logger = LoopConfig::getLogger(); if ($this->running === 0) { foreach ($this->loggers as $handler) { $logger->addHandler($handler); } } $this->running++; try { $buffer = ''; if ($this->ipc) { ob_start(function (string $data, int $phase) use(&$buffer) { $buffer .= $data; return ''; }, 1, \PHP_OUTPUT_HANDLER_FLUSHABLE); } Loop::execute(function () use($container, $action, $logger, &$buffer) { Loop::setErrorHandler(function (\Throwable $e) use($logger) { $logger->critical('', ['exception' => $e]); }); $watcher = Loop::repeat(500, function () use(&$buffer, $logger) { if ($buffer !== '') { try { $this->ipc->sendOutput($buffer); } finally { $buffer = ''; } } }); Loop::unreference($watcher); if ($this->contextName === 'development') { $locator = $container->get(ResourceLocator::class); $watcher = Loop::repeat(5000, function () use($locator) { $locator->syncFiles(); }); Loop::unreference($watcher); } if ($this->ipc) { $this->ipc->run(); } $signal = function () { if ($this->ipc) { $this->ipc->stop(); } Loop::stop(); }; // Shutdown on SIGTERM. try { Loop::onSignal(15, $signal); } catch (UnsupportedFeatureException $e) { // signal handling is not available... } $action(); }); } finally { if ($this->ipc) { \ob_end_clean(); } $this->running--; if ($this->running === 0) { foreach ($this->loggers as $handler) { $logger->removeHandler($handler); } } } }