public function withBrand($brand, $link = null) { if (!isset($link)) { $link = $this->url->to('/'); } $this->brand = compact('brand', 'link'); return $this; }
protected function getHomeUrl() { // wrap in value() to allow closures $enableHomeLink = value($this->config->get('c::enable-home-link', false)); if ($enableHomeLink) { $url = $this->config->get('c::redirect-login', '/'); return $this->url->to($url); } return null; }
/** * Guess the HREF for a button. * * @param TableBuilder $builder */ public function guess(TableBuilder $builder) { $buttons = $builder->getButtons(); if (!($section = $this->sections->active())) { return; } if (!($module = $this->modules->active())) { return; } $stream = $builder->getTableStream(); foreach ($buttons as &$button) { // If we already have an HREF then skip it. if (isset($button['attributes']['href'])) { continue; } switch (array_get($button, 'button')) { case 'restore': $button['attributes']['href'] = $this->url->to('entry/handle/restore/' . $module->getNamespace() . '/' . $stream->getNamespace() . '/' . $stream->getSlug() . '/{entry.id}'); break; default: // Determine the HREF based on the button type. $type = array_get($button, 'segment', array_get($button, 'button')); if ($type && !str_contains($type, '\\') && !class_exists($type)) { $button['attributes']['href'] = $section->getHref($type . '/{entry.id}'); } break; } } $builder->setButtons($buttons); }
/** * Return the URL for the file. * * @param array $attributes * @param null $secure * @return string */ public function url(array $attributes = [], $secure = null) { if ($secure === null) { $secure = $this->request->isSecure(); } return $this->url->to($this->object->publicPath(), $attributes, $secure); }
public function filter(Route $route, Request $request) { if ($this->auth->check()) { $config = $this->config->get('c::redirect-login'); $url = $config ? $this->url->to($config) : '/'; return $this->redirect->to($url); } }
/** * 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); }
/** * Guess the HREF for the views. * * @param TableBuilder $builder */ public function guess(TableBuilder $builder) { $views = $builder->getViews(); foreach ($views as &$view) { // Only automate it if not set. if (!isset($view['attributes']['href'])) { $view['attributes']['href'] = $this->url->to($this->request->path() . '?' . array_get($view, 'prefix') . 'view=' . $view['slug']); } } $builder->setViews($views); }
function it_creates_image_links(UrlGenerator $url) { $url->to('/', null)->shouldBeCalled()->willReturn('localhost'); $this->beConstructedWith($url); $html = '<a href="localhost"><img src="http://placehold.it/100x100.png" /></a>'; $this->linkImage('/', '<img src="http://placehold.it/100x100.png" />')->shouldReturn($html); }
public function url($path = null, $parameters = [], $secure = null) { if (!$path) { return $this->url; } return $this->url->to($path, $parameters, $secure); }
/** * @param $request * @param \Closure $next * @return \Illuminate\Http\RedirectResponse */ public function handle($request, Closure $next) { if ($this->auth->check()) { return new RedirectResponse(UrlGenerator::to('admin')); } return $next($request); }
/** * Generate a absolute URL to the given path. * * @param mixed $path or SiteTreeNodeInterface Instance * @param mixed $extra * @param bool $secure * @return string */ public function to($path, $extra = array(), $secure = null) { // Page object passed if (is_object($path) && $path instanceof SiteTreeNodeInterface) { if (starts_with($path->getPath(), 'http:')) { $path = $path->getPath(); } else { $path = $this->getPathFinder()->toPage($path); } } elseif (is_string($path) && $this->pageTypes->has($path)) { $path = $this->getPathFinder()->toPageType($path); } elseif (is_string($path) && $this->currentCmsPathProvider->getCurrentCmsPath()->isCmsPath()) { if ($extra && !isset($extra[0])) { $extra = array_values($extra); $extraPath = implode('/', $extra); $path = trim($path, '/') . '/' . trim($extraPath, '/'); $extra = []; } if ($path == '/' && $this->getTreeScope()) { $path = trim($this->getTreeScope()->getPathPrefix() . $path, '/'); } } elseif ($path == '/' && ($treeScope = $this->getTreeScope())) { $path = trim($treeScope->getPathPrefix() . $path, '/'); } return parent::to($path, $extra, $secure); }
/** * Get the action for a "url" option. * * @param array|string $options * @return string */ protected function getUrlAction($options) { if (is_array($options)) { return $this->url->to($options[0], array_slice($options, 1)); } return $this->url->to($options); }
/** * Guess the sections HREF attribute. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $sections = $builder->getSections(); foreach ($sections as $index => &$section) { // If HREF is set then skip it. if (isset($section['attributes']['href'])) { continue; } $module = $this->modules->active(); $href = $this->url->to('admin/' . $module->getSlug()); if ($index !== 0 && $module->getSlug() !== $section['slug']) { $href .= '/' . $section['slug']; } $section['attributes']['href'] = $href; } $builder->setSections($sections); }
/** * Generate a HTML link. * * @param string $url * @param string $title * @param array $attributes * @param bool $secure * @return string */ public function link($url, $title = null, $attributes = array(), $secure = null) { $url = $this->url->to($url, array(), $secure); if (is_null($title) || $title === false) { $title = $url; } return '<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $this->entities($title) . '</a>'; }
/** * Generate an HTML image element. * * @param string $url * @param string $alt * @param array $attributes * @return string */ public function image($url, $alt = null, $attributes = array()) { if (is_null($alt)) { $alt = $url; } $attributes['alt'] = $alt; return '<img src="' . $this->url->to($url) . '"' . $this->attributes($attributes) . '>'; }
/** * Generate a absolute URL to the given path. * * @param string $path * @param mixed $parameters * @param bool $secure * @return string */ public function to($path, $parameters = array(), $secure = null) { // If the given path is an object, we build a string path based on resource // controllers conventions if (is_object($path)) { $path = str_plural(snake_case(get_class($path))) . '/' . $path->getKey(); } return parent::to($path, $parameters, $secure); }
/** * Return a named route if it exists. * * @param string $url * @param array $parameters * * @return string */ protected function parseUrl($url, $parameters) { // If provided $url is a route name... if ($this->route->has($url)) { $url = $this->url->route($url, $parameters); } else { $url = $this->url->to($url, $parameters); } return $url; }
/** * Get the action for a "url" option. * * @param array|string $options * @return string */ protected function getUrl($options) { foreach ($options as $key => $value) { ${$key} = $value; } $secure = (isset($options['secure']) and $options['secure'] === true) ? true : false; if (is_array($url)) { if (self::isAbs($url[0])) { return $url[0]; } return $this->url->to($prefix . '/' . $url[0], array_slice($url, 1), $secure); } if (self::isAbs($url)) { return $url; } return $this->url->to($prefix . '/' . $url, array(), $secure); }
/** * Generate an absolute URL to the given path. * * @param string $path * @param mixed $extra * @param bool|null $secure * @return string */ public function to($path, $extra = [], $secure = null) { if ($this->isValidUrl($path)) { return $path; } if (!strpos($path, '/rtlweb/rtler/assets/css/rtl.css')) { $backendUri = Config::get('cms.backendUri', 'backend'); $requestUrl = Request::url(); if (File::exists(base_path(dirname($path)) . '.rtl.' . File::extension($path))) { $path = dirname($path) . '.rtl.' . File::extension($path); } else { if (File::extension($path) == 'css' && (strpos($requestUrl, $backendUri) || strpos($path, 'plugins/') || strpos($path, 'modules/'))) { $path = CssFlipper::flipCss($path); } } } return parent::to($path, $extra, $secure); }
/** * Create a new internal request from an HTTP verb and URI. * * @param string $verb * @param string $uri * @param string|array $parameters * * @return \Dingo\Api\Http\InternalRequest */ protected function createRequest($verb, $uri, $parameters) { if (!isset($this->version)) { $this->version = $this->properties->getVersion(); } $api = $this->router->getApiGroups()->getByDomainOrVersion($this->domain, $this->version); if (($prefix = $api->option('prefix')) && !starts_with($uri, $prefix)) { $uri = sprintf('%s/%s', $prefix, $uri); } $parameters = array_merge($this->parameters, (array) $parameters); $request = InternalRequest::create($this->url->to($uri), $verb, $parameters, $this->cookies, $this->uploads, [], $this->content); if ($domain = $api->option('domain')) { $request->headers->set('host', $domain); } foreach ($this->headers as $header => $value) { $request->headers->set($header, $value); } $request->headers->set('accept', $this->buildAcceptHeader()); return $request; }
/** * Get the fallback callback redirect URL if none provided. * * @param string $callback_url * * @return string */ private function getCallbackUrl($callback_url) { $callback_url = $callback_url ?: $this->config_handler->get('laravel-facebook-sdk.default_redirect_uri'); return $this->url->to($callback_url); }
/** * Create a new redirect response to the given path. * * @param string $path * @param int $status * @param array $headers * @param bool $secure * @return \Illuminate\Http\RedirectResponse */ public function to($path, $status = 302, $headers = [], $secure = null) { $path = $this->generator->to($path, [], $secure); return $this->createRedirect($path, $status, $headers); }
/** * Generate a link that will automatically login a user and then redirect * them to a hard-coded path as generated by the URL * generator. * * @param \Illuminate\Auth\UserInterface $user * @param string $path * @param mixed $extra * @param bool $secure * @return string */ public function to(UserInterface $user, $path, $extra = array(), $secure = null) { $path = $this->generator->to($path, $extra, $secure); return $this->getAutologinLink($user, $path); }
public function asset($path, $secure = null) { return parent::to($this->rewrite_url($path), [], false); }
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); }
protected function getHomeUrl() { $path = $this->config->get('c::redirect-login', '/'); return $this->url->to($path); }
/** * Return true if current page is an admin home (main) page. */ public function isAdminHome() : bool { return $this->url->current() == $this->url->to($this->config->get('helpers.paths.admin')); }
/** * Creates a Link to the first page of a Resource Collection. * * Makes sense to have this ability when we would like to embed a link to a sub Resource Collection which should * be paginated due to the fact that it maybe contains tons of data, so this way we don't expose all the Collection, * sparing some server side resources. * * @param $rel * @return array */ public function createLinkToFirstPage($rel) { $url = $this->url->to($this->request->url() . '/' . strtolower($rel) . $this->queryStringOps->setQueryStringParam($this->config->get('restext::page_param'), 1)); return ['rel' => $rel, 'href' => $url]; }
/** * Generate an absolute URL to the given path. * * @param string $path * @param mixed $extra * @param bool|null $secure * @return string * @static */ public static function to($path, $extra = array(), $secure = null) { return \Illuminate\Routing\UrlGenerator::to($path, $extra, $secure); }
/** * Returns the URL for the relative URI. * * @param string $uri * @return string */ public function getUrl($uri) { return $this->urlGenerator->to($this->removeWindowsSeparator($uri)); }