Пример #1
0
 /**
  * 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;
 }