Example #1
0
 /**
  * Init the module.
  */
 public function init()
 {
     if (method_exists($this, 'setup')) {
         $result = $this->setup();
         if ($result === false) {
             $this->api->getLogger()->debug('Module initialisation canceled. The module will remain loaded.');
             return;
         }
     }
     // Set up predefined events, then.
     $this->handleListeners();
 }
Example #2
0
 /**
  * This function is called when the script is shutdown
  * In this function we check if the script was expired and if so
  * we send an expired message back
  * 
  * @return void
  */
 public final function shutdown()
 {
     // Check if it is a timeout
     $execution_time = $this->microtimeFloat() - $this->_start_execution;
     if ($execution_time > $this->_ttl + 0.01) {
         $this->_api->getLogger()->note("Service timeout " . get_class($this) . " (" . $execution_time . " seconds)");
         $response['code'] = 504;
         $response['error'] = "The service took too long to execute.";
         $this->_api->send($response);
     }
 }
Example #3
0
 /**
  * Load a module and its dependencies.
  *
  * @param string $class The module class.
  * @return bool True upon success.
  * @throws UnableToLoadModuleException when a module could not be loaded.
  */
 public function load($class)
 {
     if ($this->getStatus($class) === false) {
         throw new UnableToLoadModuleException('The Module Manager was unable to load module ' . $class);
     }
     if ($this->isLoaded($class)) {
         return true;
     }
     $this->api->getLogger()->debug('Loading module {module}...', ['module' => $class]);
     // Uh, so this module does not exist. We can't load a module that does not exist...
     if (!class_exists($class)) {
         throw new UnableToLoadModuleException('The Module Manager was unable to load module ' . $class);
     }
     // Okay, so the class exists.
     try {
         $this->loadedModules[$class] = new $class($this->api);
         $this->loadedModules[$class]->init();
     } catch (\Exception $e) {
         $this->api->getLogger()->warning('Kicking module {module} off the stack because an exception was triggered during initialization: {exception}. You might want to fix this.', array('module' => $class, 'exception' => $e->getMessage()));
         $this->kick($class);
     }
     $this->api->getLogger()->info('Module {module} loaded and initialised.', ['module' => $class]);
     return $this->setStatus($class, true);
 }