Source of file Ahref.php
Size: 1,357 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/View/Helper/Ahref.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\View\Helper; use Bluz\Proxy\Request; use Bluz\Proxy\Translator; use Bluz\View\View; /** * Generate HTML for <a> element * * @author ErgallM * * @var View $this * * @param string $text * @param string|array $href * @param array $attributes HTML attributes * * @return string */ return function ($text, $href, array $attributes = []) { // if href is settings for url helper if (is_array($href)) { $href = $this->url(...$href); } // href can be null, if access is denied if (null === $href) { return ''; } $current = Request::getUri()->getPath(); if (Request::getUri()->getQuery()) { $current .= sprintf('?%s', Request::getUri()->getQuery()); } if ($href === $current) { if (isset($attributes['class'])) { $attributes['class'] .= ' active'; } else { $attributes['class'] = 'active'; } } $attributes = $this->attributes($attributes); return '<a href="' . $href . '" ' . $attributes . '>' . Translator::translate($text) . '</a>'; }; |