Example #1
0
 public function getRouter()
 {
     return $this->_container->getRouter();
 }
Example #2
0
 /**
  * Run all modules that are hooked onto this particular hook. This emulates Apache's
  * APR_IMPLEMENT_EXTERNAL_HOOK_RUN_* macro's.
  *
  * There are 3 different modes we can run:
  *   RUNHOOK_ALL: run until we hit something that is not DECLINED or OK
  *   RUNHOOK_FIRST: run until we hit the first non DECLINED
  *   RUNHOOK_VOID: run everything, always. We throw away any status we get from the modules.
  *
  * @param mixed $hook Hook to run
  * @param int $runtype The type of running
  * @param \HTRouter\HTDIContainer $container
  * @return int Status
  * @throws LogicException When something wrong happens
  */
 function runHook($hook, $runtype = self::RUNHOOK_ALL, \HTRouter\HTDIContainer $container)
 {
     // Check if something is actually registered to this hook.
     if (!isset($this->_hooks[$hook])) {
         return \HTRouter::STATUS_OK;
     }
     foreach ($this->_hooks[$hook] as $hook) {
         // Every hook as 0 or more "modules" hooked
         foreach ($hook as $module) {
             // Run the callback
             $class = $module[0];
             $method = $module[1];
             $retval = $class->{$method}($container->getRequest());
             // @TODO: Old style return, can be removed when everything is refactored
             if (!is_numeric($retval)) {
                 throw new \LogicException("Return value must be a STATUS_* constant: found in " . get_class($class) . " ->{$method}!");
             }
             if ($runtype == self::RUNHOOK_VOID) {
                 // Don't care about result. Just continue with the next
                 continue;
             }
             if ($runtype == self::RUNHOOK_ALL && ($retval != \HTRouter::STATUS_OK && $retval != \HTRouter::STATUS_DECLINED)) {
                 // Only HTTP STATUS will return
                 return $retval;
             }
             if ($runtype == self::RUNHOOK_FIRST && $retval != \HTRouter::STATUS_DECLINED) {
                 // OK and HTTP STATUS will return
                 return $retval;
             }
         }
     }
     return \HTRouter::STATUS_OK;
 }
Example #3
0
 function __construct(\HTRouter\HTDIContainer $container)
 {
     // Initialize logger
     $config = $container->getRouterConfig("logger");
     $this->_init($config);
 }