Exemplo n.º 1
0
 /**
  * Returns a controller and an action for the request's target.
  *
  * @param string $controller   $he controller class name. (Outgoing parameter)
  * @param string $action       The action name in the controller class. (Outgoing parameter)
  * @param string $uri          The uri to check. If not given, the current uri will be used.
  *
  * @return string   The controller and action separated by a '/' character.
  *
  * @throws \YapepBase\Exception\RouterException   On errors. (Including if the route is not found)
  */
 public function getRoute(&$controller = null, &$action = null, $uri = null)
 {
     $uri = empty($uri) ? $this->request->getTarget() : $uri;
     $target = explode('/', trim($uri, '/ '));
     $controller = array_shift($target);
     if (empty($controller)) {
         $controller = 'Index';
     } else {
         $controller = $this->convertPathPartToName($controller);
     }
     if (empty($target)) {
         $action = 'Index';
     } else {
         $action = $this->convertPathPartToName(array_shift($target));
     }
     foreach ($target as $key => $value) {
         $this->request->setParam($key, $value);
     }
     return $controller . '/' . $action;
 }
Exemplo n.º 2
0
 /**
  * Returns the current language from the request object.
  *
  * @param IRequest $request
  *
  * @return string
  */
 public function getCurrentLanguageFromRequest(IRequest $request, array $usableLanguages, $defaultLanguage)
 {
     $uri = $request->getTarget();
     $uriParts = explode('/', trim($uri, '/'));
     return in_array($uriParts[0], $usableLanguages) ? $uriParts[0] : $defaultLanguage;
 }
Exemplo n.º 3
0
 /**
  * Returns the target of the request.
  *
  * @return string
  */
 protected function getTarget()
 {
     return $this->request->getTarget();
 }