Bolt\Configuration\ResourceManager::getUrl PHP Method

getUrl() public method

Get a URL path definition.
public getUrl ( string $name, boolean $includeBasePath = true ) : string
$name string
$includeBasePath boolean
return string
    public function getUrl($name, $includeBasePath = true)
    {
        if (($name === 'canonical' || $name === 'canonicalurl') && isset($this->app['canonical'])) {
            if ($url = $this->app['canonical']->getUrl()) {
                return $url;
            }
        }
        if (array_key_exists($name . 'url', $this->urls) && $name !== 'root') {
            return $this->urls[$name . 'url'];
        }
        if (!array_key_exists($name, $this->urls)) {
            throw new \InvalidArgumentException("Requested url {$name} is not available", 1);
        }
        if (!$includeBasePath) {
            return $this->urls[$name];
        }
        return $this->urlPrefix . $this->urls[$name];
    }

Usage Example

Example #1
0
 /**
  * Add base snippets to the response.
  */
 protected function addSnippets()
 {
     $this->queue->add(Target::END_OF_HEAD, '<meta name="generator" content="Bolt">');
     if ($this->config->get('general/canonical')) {
         $canonical = $this->resources->getUrl('canonicalurl');
         $this->queue->add(Target::END_OF_HEAD, $this->encode('<link rel="canonical" href="%s">', $canonical));
     }
     if ($favicon = $this->config->get('general/favicon')) {
         $host = $this->resources->getUrl('hosturl');
         $theme = $this->resources->getUrl('theme');
         $this->queue->add(Target::END_OF_HEAD, $this->encode('<link rel="shortcut icon" href="%s%s%s">', $host, $theme, $favicon));
     }
 }
All Usage Examples Of Bolt\Configuration\ResourceManager::getUrl