/** * Translates the given arguments into either an absolute or a * relative HTTP URI string. * * The argument $args is essentially the URI path segments to be * appended to the base path. * * @param array $args Arguments to generate the URI. * @param HTTPURIInterface $baseHTTPURI You can use this copy of * the base HTTP URI to build the HTTPURIInterface object * to be returned. * @param bool $absolute If TRUE, this method should return an * absolute URI string, otherwise this method returns a * relative URI string. * @return string * */ public function getURI(array $args, HTTPURIInterface $baseHTTPURI, $absolute = FALSE) { $isPathToStaticAsset = (isset($args[0]) and $args[0] == 'assets'); $pathToBeAppended = implode('/', $args); $pathToBeAppended = ltrim($pathToBeAppended, '/'); $pathToBeAppended = $this->path . $pathToBeAppended; if ($isPathToStaticAsset == FALSE) { $pathToBeAppended = rtrim($pathToBeAppended, '/'); $pathToBeAppended .= '/'; } $baseHTTPURI->appendPath($pathToBeAppended); if ($absolute) { return $baseHTTPURI->getPathEncoded(); } return $baseHTTPURI->get(); }
/** * Translates the given arguments into either an absolute or a * relative HTTP URI string. * * When calling this method (via the Router or otherwise), pass * the arguments array with placeholder labels as index and the * values as the content. For example, in this route pattern: * * <code> * /post/<d:id>/<r:lang><(en|de|fr)>/ * </code> * * You will have to provide two arguments, 'id', and 'lang', as * in: * * <code> * $args = array( * '458934', * 'de' * ); * </code> * * This method will not validate your arguments, so make sure to * pass the arguments in the correct order. * * @param array $args Arguments to generate the URI. * @param HTTPURIInterface $baseHTTPURI Used generate the URI. * @param bool $absolute If TRUE, this method should return an * absolute URI string, otherwise this method returns a * relative URI string. * @return string * */ public function getURI(array $args, HTTPURIInterface $baseHTTPURI, $absolute = FALSE) { if (empty($args) == FALSE) { $patterns = array_fill(0, count($args), '/<[^\\/>]+>/u'); $pathToBeAppended = preg_replace($patterns, $args, $this->config['pattern'], 1); } else { $pathToBeAppended = $this->config['pattern']; } if ($pathToBeAppended != '') { $baseHTTPURI->appendPath($pathToBeAppended); } if ($absolute) { return $baseHTTPURI->get(); } else { return $baseHTTPURI->getPathEncoded(); } }