/** * Boots the configuration module. * * @throws ModuleException If config file doesn't exist. * @param Application $application Calling application. * @return self */ public function boot(Application $application = null) : Module { // calling the config module without any application makes no sense if (isset($application) === false) { throw new ModuleException('The configuration module is expected to run within an application.'); } // check for available configuration files // $configs = new GenericDirectory($application->getConfigsPath()); // try to locate configuration file for current running application $file = new GenericFile([$application->getConfigsPath(), 'config.json']); // try to read config file $config = FileConfig::create($file); // different internal character encoding given by config if ($config->has('charset')) { $charset = $config->get('charset'); function_exists('mb_internal_encoding') && mb_internal_encoding($charset); function_exists('mb_http_output') && mb_http_output($charset); } // different timezone given by config if ($config->has('timezone')) { date_default_timezone_set($config->get('timezone')); } // keep instance $this->config = $config; return $this; }
/** * Dispatches the resource that awaits behind an internal server error. */ protected function dispatch() { // create request/response $request = new GenericRequest(); $response = new GenericResponse(); // going to use the internal server error status $response->setStatusCode(Response::STATUS_INTERNAL_SERVER_ERROR); // since verbosity is set to non-silent, we are going to use the // internal target and bail out early if ($this->getVerbosity() > Debug::VERBOSITY_SILENT) { try { return $this->getInternalTarget()->generate($request, $response); // looks like the own view of the debug module has been deleted, wtf? } catch (Throwable $t) { return $response->setBody(sprintf('<pre>%s</pre>', print_r($this->getThrown(), true)))->send(); } } // no application given? bye if ($this->application === null) { return $response->send(); } // get application container $container = $this->application->getContainer(); // there is no front module if (($front = $container->get('JohnnyOS\\Modules\\Front')) === null) { return $response->send(); } // get target for current status code if (($target = $front->getStatusCodeTarget($response->getStatusCode())) === null) { return $response->send(); } $target->generate($request, $response); }
/** * Boot database module. * * @param Application $application Calling application. * @return self */ public function boot(Application $application = null) : Module { // calling the database module without any application makes no sense if (isset($application) === false) { throw new ModuleException('The database module is expected to run within an application.'); } // try to get config module try { $config = $application->getContainer()->get('JohnnyOS\\Modules\\Config'); } catch (ContainerException $e) { return $this; } // config content is not quite usable if (is_callable($config) && ($config = $config()) instanceof Config === false) { return $this; } // everything is perfect, try to setup database connection $this->instance = new PDODatabase($config); return $this; }
/** * Boot session module. * * @param Application $application Calling application. * @return self */ public function boot(Application $application = null) : Module { // calling the session module without any application makes no sense if (isset($application) === false) { throw new ModuleException('The session module is expected to run within an application.'); } // try to get database module try { $database = $application->getContainer()->get('JohnnyOS\\Modules\\Database'); } catch (ContainerException $e) { return $this; } // database content is not quite usable if (is_callable($database) && ($database = $database()) instanceof Database === false) { return $this; } // everything is perfect, try to initialize session $this->instance = new DatabaseSession($database, new GenericRequest()); // start session $this->instance->start(); return $this; }