/** * Create a new Irto\OAuth2Proxy\Server instance with $config * * @param array $config * * @return Irto\OAuth2Proxy\Server */ public static function create(array $config) { $server = new static(); isset($config['verbose']) && $server->setVerbose($config['verbose']); $server->singleton('config', function ($server) use($config) { return new Collection($config); }); $server->bind('Irto\\OAuth2Proxy\\Server', function ($server) { return $server; }); // Create main loop React\EventLoop based $server->singleton('React\\EventLoop\\LoopInterface', function ($server) { return React\EventLoop\Factory::create(); }); // DNS resolve, used for create async requests $server->singleton('React\\Dns\\Resolver\\Resolver', function ($server) { $dnsResolverFactory = new React\Dns\Resolver\Factory(); return $dnsResolverFactory->createCached('8.8.8.8', $server['React\\EventLoop\\LoopInterface']); //Google DNS }); // HTTP Client $server->singleton('React\\HttpClient\\Client', function ($server) { $factory = new React\HttpClient\Factory(); return $factory->create($server['React\\EventLoop\\LoopInterface'], $server['React\\Dns\\Resolver\\Resolver']); }); // Request handler to React\Http $server->singleton('React\\Socket\\Server', function ($server) { $socket = new React\Socket\Server($server['React\\EventLoop\\LoopInterface']); $socket->listen($server->get('port')); return $socket; }); // HTTP server for handle requests $server->singleton('React\\Http\\Server', function ($server) { return new React\Http\Server($server['React\\Socket\\Server']); }); // HTTP server for handle requests $server->singleton('SessionHandlerInterface', function ($server) { return $server->make('Irto\\OAuth2Proxy\\Session\\AsyncRedisSessionHandler', ['lifetime' => array_get($server['config']->all(), 'session.lifetime')]); }); $server->bind('Illuminate\\Session\\Store', 'Irto\\OAuth2Proxy\\Session\\Store'); $server->boot(); return $server; }
public static function invoke($app_class, $app_root_dir, $env, Handler $handler = null) { $app = new $app_class($app_root_dir, $env); $dispatcher = new static($app); $dispatcher->boot(); if ($app->isDebug()) { if (is_null($handler)) { $handler = new \Whoops\Handler\PrettyPageHandler(); } $whoops = new \Whoops\Run(); $whoops->pushHandler($handler); $whoops->register(); } try { $response = $dispatcher->handleRequest(); } catch (\Exception $e) { if ($app->isDebug()) { throw $e; } $response = $dispatcher->handleError($e); } }
public static function invoke($app_class, $app_root_dir, $env) { $app = new $app_class($app_root_dir, $env); $dispatcher = new static($app); $dispatcher->boot(); try { $response = $dispatcher->handleRequest(); } catch (\Exception $e) { // Please handle errors occurred on executing Dispatcher::handleError with your web server. // Dietcube doesn't care these errors. $response = $dispatcher->handleError($e); } }