/** * {@inheritDoc} */ public function assemble(array $params = array(), array $options = array()) { $mergedParams = array_merge($this->defaults, $params); $url = ''; if (!empty($mergedParams['slug'])) { $url = $this->encode($mergedParams['slug']); } elseif (!empty($mergedParams['name'])) { $url = $this->encode($mergedParams['name']); } elseif (!empty($mergedParams['id'])) { $url = (int) $mergedParams['id']; } if (empty($url)) { return $this->prefix; } $params = array(); $prefix = $this->prefix; $this->prefix .= $this->paramDelimiter . $url; $url = parent::assemble($params, $options); $this->prefix = $prefix; return $url; }
/** * {@inheritDoc} */ public function assemble(array $params = array(), array $options = array()) { if (!$params) { return $this->prefix; } $url = null; // Transform uid to id if (isset($params[$this->paramId]) && 'id' != $this->paramId) { $params['id'] = $params[$this->paramId]; unset($params[$this->paramId]); } $controller = isset($params['controller']) ? $params['controller'] : ''; $action = isset($params['action']) ? $params['action'] : ''; // /logout if ('logout' == $action) { $url = 'logout'; // /<...> } elseif ('' == $controller || 'index' == $controller) { $url = ''; // /home/<...> } elseif ('home' == $controller) { if ('' == $action || 'index' == $action || 'view' == $action) { // /home $url = 'home'; // /home/<id> if (!empty($params['id'])) { $url .= $this->paramDelimiter . $params['id']; unset($params['id']); } } // /profile/<...> } elseif ('profile' == $controller) { if ('' == $action || 'index' == $action || 'view' == $action) { // /profile $url = 'profile'; // /profile/<id> if (!empty($params['id'])) { $url .= $this->paramDelimiter . $params['id']; unset($params['id']); } } } if (null !== $url) { $part = $this->assembleParams($params); $url .= $part ? $this->paramDelimiter . $part : ''; $url = $url ? $this->prefix . $this->paramDelimiter . $url : $this->prefix; } else { $params['module'] = $this->defaults['module']; $url = parent::assemble($params, $options); $urlPrefix = $this->prefix . $this->paramDelimiter . $this->defaults['module']; $urlSuffix = substr($url, strlen($urlPrefix)); $url = $this->prefix . $urlSuffix; } return $url; }
/** * assemble(): Defined by Route interface. * * @see Route::assemble() * @param array $params * @param array $options * @return string */ public function assemble(array $params = array(), array $options = array()) { if (!$params) { return $this->prefix; } $url = null; $controller = isset($params['controller']) ? $params['controller'] : ''; $action = isset($params['action']) ? $params['action'] : ''; // /list/<root-id> if ('list' == $controller) { if ('' == $action || 'root' == $action) { if (!empty($params['root'])) { $url .= 'list' . $this->paramDelimiter . $params['root']; unset($params['root']); } } // /post/<post-id> } elseif ('post' == $controller) { if ('' == $action || 'index' == $action) { if (!empty($params['id'])) { $url .= 'post' . $this->paramDelimiter . $params['id']; unset($params['id']); } } } if ($url) { $part = $this->assembleParams($params); $url .= $part ? $this->paramDelimiter . $part : ''; $url = $this->prefix . $this->paramDelimiter . $url; } else { $params['module'] = $this->defaults['module']; $url = parent::assemble($params, $options); $urlPrefix = $this->prefix . $this->paramDelimiter . $this->defaults['module']; $urlSuffix = substr($url, strlen($urlPrefix)); $url = $this->prefix . $urlSuffix; } return $url; }