addScheme() public static method

Add 'http://' to a link, if it has no protocol already.
public static addScheme ( string $url, string $scheme = 'http://' ) : string
$url string
$scheme string
return string
Exemplo n.º 1
0
 public function testAddScheme()
 {
     $this->assertEquals('http://example.org', Html::addScheme('example.org'));
     $this->assertEquals('http://example.org', Html::addScheme('http://example.org'));
     $this->assertEquals('https://example.org', Html::addScheme('https://example.org'));
     $this->assertEquals('mailto:bob@bolt.cm', Html::addScheme('mailto:bob@bolt.cm'));
 }
Exemplo n.º 2
0
 /**
  * Create an HTML link to a given URL or contenttype/slug pair.
  *
  * @param string $location
  * @param string $label
  *
  * @return string
  */
 public function link($location, $label = '[link]')
 {
     if ((string) $location === '') {
         return '';
     }
     if (Html::isURL($location)) {
         $location = Html::addScheme($location);
     } elseif ($record = $this->app['storage']->getContent($location)) {
         $location = $record->link();
     }
     return sprintf('<a href="%s">%s</a>', $location, $label);
 }