Exemple #1
0
 public function preHandle(Action $action, $handler)
 {
     $arguments = $action->getArguments();
     if (!isset($arguments['optional'])) {
         return new RedirectModelAndView('http://github.com/marcelog/Ding');
     }
     return true;
 }
Exemple #2
0
 /**
  * Constructor.
  *
  * @param string $id        Url.
  * @param array  $arguments Arguments posted (or getted :P).
  *
  * @return void
  */
 public function __construct($id, array $arguments = array())
 {
     parent::__construct($id, $arguments);
     $this->_method = 'GET';
 }
Exemple #3
0
 /**
  * This will map an exception action to a controller. Will look for
  * an instance of the mapped exception to the thrown exception.
  *
  * @param Action $action Original action (exception).
  *
  * @return array [0] => Controller [1] => Method to call (With
  * 'Exception' appended to the end of the method name).
  */
 public function map(Action $action)
 {
     $exception = $action->getArguments();
     $exception = $exception['exception'];
     $this->_logger->debug('Exception mapper invoked with: ' . $action->getId());
     // Lookup a controller that can handle this url.
     foreach ($this->_map as $map) {
         $controllerException = $map[0];
         $controller = $map[1];
         if (!$exception instanceof $controllerException) {
             continue;
         }
         return new DispatchInfo($action, $controller, str_replace('\\', '_', $controllerException) . 'Exception');
     }
     return false;
 }
Exemple #4
0
 /**
  * This will map a full url, like /A/B/C to an HttpAction and will try to
  * find a controller that can handle it. This will isolate the baseUrl.
  *
  * @param Action $action Original action (coming from the frontcontroller,
  * the full url).
  *
  * @return DispatchInfo
  */
 public function map(Action $actionObject)
 {
     $url = $actionObject->getId();
     // Add a slash to the beginning is none is found after removing the
     // base url.
     if ($url[0] != '/') {
         $url = '/' . $url;
     }
     // Do not take into account the arguments part of the url.
     $url = explode('?', $url);
     $url = $url[0];
     // Add a trailing slash to the result.
     $len = strlen($url) - 1;
     if ($url[$len] != '/') {
         $url .= '/';
     }
     $this->_logger->debug('Trying to match: ' . $url);
     // Lookup a controller that can handle this url.
     $try = array_merge($this->_map, self::$_annotatedControllers);
     $candidates = array();
     foreach ($try as $map) {
         $controllerUrl = $map[0];
         $controller = $map[1];
         $interceptors = array();
         if (isset($map[2])) {
             $interceptors = $map[2];
         }
         if ($controllerUrl[0] != '/') {
             $controllerUrl = '/' . $controllerUrl;
         }
         $len = strlen($controllerUrl);
         if ($controllerUrl[$len - 1] != '/') {
             $controllerUrl = $controllerUrl . '/';
         }
         $controllerUrlStart = strpos($url, $controllerUrl);
         if (!($controllerUrlStart === 0)) {
             continue;
         }
         $start = $controllerUrlStart + strlen($controllerUrl);
         $action = substr($url, $start);
         if ($action === false) {
             $action = 'Main';
         }
         $action = explode('/', $action);
         $action = $action[0];
         if (!is_object($controller)) {
             $controller = $this->container->getBean($controller);
             $this->_logger->debug("Found as annotated controller: " . "{$controllerUrl} in " . get_class($controller));
         }
         if (!isset($candidates[$len])) {
             $candidates[$len] = array();
         }
         $candidates[$len][] = new DispatchInfo($actionObject, $controller, $action . 'Action', $interceptors);
     }
     if (empty($candidates)) {
         return false;
     }
     krsort($candidates);
     $controllers = array_shift($candidates);
     return array_shift($controllers);
 }