Bolt\Twig\Handler\HtmlHandler::link PHP Метод

    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);
    }

Usage Example

Пример #1
0
 public function testLink()
 {
     $app = $this->getApp();
     $handler = new HtmlHandler($app);
     $result = $handler->link('http://google.com', 'click');
     $this->assertSame('<a href="http://google.com">click</a>', $result);
     $result = $handler->link('google.com');
     $this->assertSame('<a href="http://google.com">[link]</a>', $result);
     $result = $handler->link('mailto:[email protected]', 'mail');
     $this->assertSame('<a href="mailto:[email protected]">mail</a>', $result);
     $result = $handler->link('gooblycook', 'click');
     $this->assertSame('<a href="gooblycook">click</a>', $result);
 }