Exemplo n.º 1
0
 /**
  * Executes a route action, given a callable and a context.
  * 
  * @param callable $targetFunc The target function to be executed.
  * @param Context $context The context the target function should be executed under (for dependency injection).
  * @return mixed The function's return value.
  * @throws \Exception If an exception is raised during execution, it will be rethrown.
  */
 private function executeAction(callable $targetFunc, Context $context)
 {
     $returnValue = null;
     $paramValues = $context->determineParamValues($targetFunc);
     try {
         $returnValue = call_user_func_array($targetFunc, $paramValues);
     } catch (\Exception $ex) {
         $context->registerInstance($ex);
         $this->filters->trigger(Filters::ON_EXCEPTION, $context);
         if (!$this->filters->anyHandlersForEvent(Filters::ON_EXCEPTION)) {
             // If this exception was unhandled, rethrow it so it can be handled in the global scope
             throw $ex;
         }
     }
     return $returnValue;
 }
Exemplo n.º 2
0
 /**
  * Registers a filter function that is called when routing fails (404 error).
  *
  * @param callable $filter
  * @return $this
  */
 public function notFound(callable $filter)
 {
     $this->filters->register(Filters::NO_ROUTE_FOUND, $filter);
     return $this;
 }
Exemplo n.º 3
0
 public function testContinueIsTrueByDefault()
 {
     $filters = new Filters();
     $this->assertTrue($filters->trigger('myEventType'), 'Continue should be true if no filters are triggered');
 }