/** * Generates a url for Sorter * * @param string $field * @param null|string $path * @param boolean $appends * */ public function url($field, $path = null, $appends = true) { if ($path === null) { $path = $this->url->current(); } $queryString = [$this->getFieldIndex() => $field, $this->getDirectionIndex() => $this->getConditionallyDirection($field)]; $appends && ($queryString += $this->request->query()); $url = $path . '?' . http_build_query($queryString); return $this->url->to($url); }
/** * @param array $value * @param string $route * @param UrlGenerator $router * * @return mixed|string */ protected function calculateFullPath(array &$value, $route, UrlGenerator $router) { if (!empty($value['as_id'])) { preg_match_all('/{(.*?)}/', $route, $matches); $route = str_replace($matches[0], '{' . $value['as_id'] . '}', $route); } $port = parse_url($router->current(), PHP_URL_PORT); $port = null == $port ? '' : ':' . $port; $scheme = parse_url($router->current(), PHP_URL_SCHEME); $host = parse_url($router->current(), PHP_URL_HOST) . $port; return sprintf('%s://%s/%s', $scheme, $host, $route); }
/** * Return true if current page is $page. */ public function isPage(string $page, array $parameters = []) : bool { // Check if $page is a route name if ($this->route->has($page)) { if ($parameters) { return $this->url->current() == $this->url->route($page, $parameters); } return $this->route->currentRouteName() == $page; } return str_replace($this->request->root() . '/', '', $this->url->full()) == $page; }
/** * @param $link * @return bool */ private function itemShouldBeActive($link) { if (is_string($link)) { return false; } $auto = $this->autoroute && $this->url->current() == $link['link']; $manual = isset($link['active']) && $link['active']; return $auto || $manual; }
/** * Get the form action from the options. * * @param array $options * @return string */ protected function getAction(array $options) { // We will also check for a "route" or "action" parameter on the array so that // developers can easily specify a route or controller action when creating // a form providing a convenient interface for creating the form actions. if (isset($options['url'])) { return $this->getUrlAction($options['url']); } if (isset($options['route'])) { return $this->getRouteAction($options['route']); } elseif (isset($options['action'])) { return $this->getControllerAction($options['action']); } return $this->url->current(); }
/** * Get the form action from the options. * * @param array $options * * @return string */ protected function getAction(array $options) { // We will also check for a "route" or "action" parameter on the array so that // developers can easily specify a route or controller action when creating // a form providing a convenient interface for creating the form actions. if (isset($options['url'])) { return $this->getUrlAction($options['url']); } // If an action is available, we are attempting to open a form to a controller // action route. So, we will use the URL generator to get the path to these // actions and return them from the method. Otherwise, we'll use current. if (isset($options['route'])) { return $this->getRouteAction($options['route']); } elseif (isset($options['action'])) { return $this->getControllerAction($options['action']); } return $this->url->current(); }
/** * Get the current URL for the request. * * @return string * @static */ public static function current() { return \Illuminate\Routing\UrlGenerator::current(); }
/** * @inheritdoc */ public function getCurrentUrl() { return $this->url->current(); }
function it_implements_routes_with_dynamic_parameters(UrlGenerator $url) { // Having $user_id = 20; $year = 2015; $month = 07; $day = 11; $account = "http://example.com/account/{$user_id}"; $calendar = "http://example.com/calendar/{$year}/{$month}/{$day}"; $url->current()->shouldBeCalled()->willReturn($account); $url->to('')->shouldBeCalled()->willReturn('http://example/'); $url->route('account', [$user_id])->shouldBeCalled()->willReturn($account); $url->route('calendar', [$year, $month, $day])->shouldBeCalled()->willReturn($calendar); // Generate new menu $menu = $this->make(['account' => ['route' => ['account', ':user_id']], 'calendar' => ['route' => ['calendar', ':year', ':month', ':day']]]); // With dynamic parameters $menu->setParams(compact('year', 'month', 'day')); $menu->setParam('user_id', $user_id); $items = ['account' => ['class' => 'active', 'submenu' => null, 'id' => 'account', 'active' => true, 'title' => 'Account', 'url' => $account], 'calendar' => ['class' => '', 'submenu' => null, 'id' => 'calendar', 'active' => false, 'title' => 'Calendar', 'url' => $calendar]]; $menu->getItems()->shouldReturn($items); }
function let(UrlGenerator $url) { $url->current()->willReturn('link'); $this->beConstructedWith($url); }
private function urlOrCurrent($url = null) { return $url === null ? $this->urlGenerator->current() : $url; }
/** * Return true if current breadcrumb item is active. * * @return bool */ public function isActive() { return $this->url == $this->routing->current(); }
/** * Add current page to the breadcrumbs array. * * @param string $title * * @return $this */ public function addCurrent($title) { return $this->add($this->url->current(), $title); }