Example #1
0
 /**
  * {@inheritdoc}
  */
 public function generate(array $params, Context $context)
 {
     $route = [];
     $module = isset($params[$context->getModuleKey()]) ? $params[$context->getModuleKey()] : $this->dispatcher->getDefaultModule();
     $controller = isset($params[$context->getControllerKey()]) ? $params[$context->getControllerKey()] : $this->dispatcher->getDefaultControllerName();
     $action = isset($params[$context->getActionKey()]) ? $params[$context->getActionKey()] : $this->dispatcher->getDefaultAction();
     unset($params[$context->getModuleKey()], $params[$context->getControllerKey()], $params[$context->getActionKey()]);
     if ($module != $this->dispatcher->getDefaultModule()) {
         $route[] = $module;
     }
     if (count($params) > 0 || $controller != $this->dispatcher->getDefaultControllerName() || $action != $this->dispatcher->getDefaultAction()) {
         $route[] = $controller;
     }
     if (count($params) > 0 || $action != $this->dispatcher->getDefaultAction()) {
         $route[] = $action;
     }
     foreach ($params as $key => $value) {
         $route[] = $key;
         $route[] = $value;
     }
     $route = array_map('urlencode', $route);
     return implode($this->separator, $route);
 }
Example #2
0
 /**
  * Fills up default values for module, controller and action
  *
  * @param Context $context
  * @param array $query
  * @return array
  */
 private function fillDefaults(Context $context, $query)
 {
     $defaults = [$context->getModuleKey() => $this->dispatcher->getDefaultModule(), $context->getControllerKey() => $this->dispatcher->getDefaultControllerName(), $context->getActionKey() => $this->dispatcher->getDefaultAction()];
     $query = array_merge($defaults, $query);
     return $query;
 }