Gregwar\RST\Environment::canonicalUrl PHP Method

canonicalUrl() public method

Gets a canonical URL from the given one
public canonicalUrl ( $url )
    public function canonicalUrl($url)
    {
        if (strlen($url)) {
            if ($url[0] == '/') {
                // If the URL begins with a "/", the following is the
                // canonical URL
                return substr($url, 1);
            } else {
                // Else, the canonical name is under the current dir
                if ($this->getDirName()) {
                    return $this->canonicalize($this->getDirName() . '/' . $url);
                } else {
                    return $this->canonicalize($url);
                }
            }
        }
        return null;
    }

Usage Example

Esempio n. 1
0
File: Doc.php Progetto: cmsilex/rst
 public function resolve(Environment $environment, $data)
 {
     $metas = $environment->getMetas();
     $file = $environment->canonicalUrl($data);
     if ($metas) {
         $entry = $metas->get($file);
         $entry['url'] = $environment->relativeUrl('/' . $entry['url']);
     } else {
         $entry = array('title' => '(unresolved)', 'url' => '#');
     }
     return $entry;
 }