/** * Map the redirect routes. * * @param UrlGenerator $url * @param Router $router * @param Request $request * @param RedirectRepositoryInterface $redirects * @internal param Filesystem $files * @internal param Application $application */ public function map(UrlGenerator $url, Router $router, Request $request, RedirectRepositoryInterface $redirects) { if ($request->segment(1) == 'admin') { return; } /* @var RedirectInterface $redirect */ foreach ($redirects->sorted() as $redirect) { if (!starts_with($parsed = $redirect->getFrom(), ['http://', 'https://', '//'])) { $parsed = $url->to($redirect->getFrom()); } $parsed = parse_url(preg_replace_callback("/\\{[a-z]+\\?\\}/", function ($matches) { return str_replace('?', '!', $matches[0]); }, $parsed)); if (isset($parsed['host']) && $parsed['host'] == $request->getHost()) { /** * Route a domain redirect in a domain group. */ $router->group(['domain' => $parsed['host']], function () use($parsed, $router, $redirect) { $path = ltrim(preg_replace_callback("/\\{[a-z]+\\!\\}/", function ($matches) { return str_replace('!', '?', $matches[0]); }, $parsed['path']), '/'); $router->any($path ?: '/', ['uses' => 'Anomaly\\RedirectsModule\\Http\\Controller\\RedirectsController@handle', 'redirect' => $redirect->getId()])->where(['any' => '(.*)', 'path' => '(.*)']); }); } else { /** * Route a standard redirect. */ $router->any($redirect->getFrom(), ['uses' => 'Anomaly\\RedirectsModule\\Http\\Controller\\RedirectsController@handle', 'redirect' => $redirect->getId()])->where(['any' => '(.*)', 'path' => '(.*)']); } } }
/** * {@inheritdoc} */ public function to($path, $extra = [], $secure = null) { $url = $this->url->to($path, $extra, $secure); $permission = $this->securityApi->permissions()->getForPath($url); $this->checkPermission($permission); return $url; }
/** * Guess the HREF for a button. * * @param ControlPanelBuilder $builder */ public function guess(ControlPanelBuilder $builder) { $buttons = $builder->getButtons(); $sections = $builder->getControlPanelSections(); $active = $sections->active(); $module = $this->modules->active(); foreach ($buttons as &$button) { // If we already have an HREF then skip it. if (isset($button['attributes']['href'])) { continue; } // Determine the HREF based on the button type. switch (array_get($button, 'button')) { case 'add': case 'new': case 'create': $button['attributes']['href'] = $active->getHref('create'); break; case 'export': if ($module) { $button['attributes']['href'] = $this->url->to('entry/handle/export/' . $module->getNamespace() . '/' . array_get($button, 'namespace') . '/' . array_get($button, 'stream')); } break; } $type = array_get($button, 'segment', array_get($button, 'button')); if (!isset($button['attributes']['href']) && $type) { $button['attributes']['href'] = $active->getHref($type); } } $builder->setButtons($buttons); }
/** * {@inheritdoc} */ public function url($path, $absolute = true) { if ($absolute === false) { return $path; } return $this->urlGenerator->to($path); }
/** * Create a new Redirect response. * * @param RedirectInterface $redirect * @return \Illuminate\Http\RedirectResponse */ public function create(RedirectInterface $redirect) { $parameters = array_merge(array_map(function () { return null; }, array_flip($this->route->parameterNames())), $this->route->parameters()); if (!starts_with($url = $redirect->getTo(), ['http://', 'https://', '//'])) { $url = $this->url->to($redirect->getTo(), [], $redirect->isSecure()); } return $this->redirector->to(rtrim($this->parser->parse($url, $parameters), '/'), $redirect->getStatus()); }
/** * Generate a absolute URL to the given path. * * @param string $path * @param mixed $extra * @param bool $secure * @return string */ public function url($path, $extra = [], $secure = null) { // Do not modify path if it starts with `http`. if (preg_match('/^http/', $path)) { return $this->url->to($path, $extra, $secure); } if ($this->isCurrentLocaleDefault()) { return $this->url->to($path, $extra, $secure); } $path = $this->config->get('app.locale') . '/' . $path; return $this->url->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); }
/** * Generate a HTML link. * * @param string $url * @param string $title * @param array $attributes * @param bool $secure * @param bool $escaped * * @return \Illuminate\Support\HtmlString */ public function link($url, $title = null, $attributes = [], $secure = null, $escaped = true) { $url = $this->url->to($url, [], $secure); if (is_null($title) || $title === false) { $title = $url; } return $this->toHtmlString('<a href="' . $url . '"' . $this->attributes($attributes) . '>' . ($escaped ? $this->entities($title) : $title) . '</a>'); }
/** * 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 = [], $secure = null) { $url = $this->url->to($url, [], $secure); if (is_null($title) || $title === false) { $title = $url; } return '<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $this->entities($title) . '</a>'; }
/** * Generate a page URL, based on the request's current URL. * * @param int $page * @param bool $full Return the full version of the URL in for the first page * Ex. /users/page/1 instead of /users * * @return string */ public function pageUrl($page, $full = false) { $currentPageUrl = $this->router->getCurrentRoute()->getUri(); $url = $this->addPageQuery(str_replace('{pageQuery?}', '', $currentPageUrl), $page, $full); foreach ($this->router->getCurrentRoute()->bindParameters(app('request')) as $parameterName => $parameterValue) { $url = str_replace(['{' . $parameterName . '}', '{' . $parameterName . '?}'], $parameterValue, $url); } return $this->urlGenerator->to($url); }
/** * Convert slugs to urls. * * @param array $nav * * @return array */ protected function process(array $nav) { // convert slugs to urls foreach ($nav as $key => $value) { // if the url is not set if (!isset($value['url'])) { // set the url based on the slug $nav[$key]['url'] = $this->url->to($value['slug']); } // remove any remaining slugs unset($nav[$key]['slug']); } // spit out the nav bar array at the end return $nav; }
/** * Get the previous page url * * @param bool $full Return the full version of the url in for the first page * Ex. /users/page/1 instead of /users * @return string|null */ public function previousPageUrl($full = false) { $previousPage = $this->previousPage(); if ($previousPage === null) { return null; } // This should call the current action with a different parameter // Afaik there's no cleaner way to do this $currentPageUrl = new String($this->router->getCurrentRoute()->getUri()); if ($previousPage === 1 && !$full) { $previousPageUrl = $currentPageUrl->replaceLast($this->pageName . '/{page}', ''); } else { $previousPageUrl = $currentPageUrl->replaceLast('{page}', $previousPage); } return $this->urlGenerator->to($previousPageUrl); }
/** * Generates the menu item URL, using any of the following options, in order: * * If you pass a 'full_url' key within the item configuration, in that case * it will return it as the URL with no additional action. * * If you pass a 'url' key then it will call the Url::to method to complete * the base URL, you can also specify a 'secure' key to indicate whether * this URL should be secure or not. Otherwise the defaultSecure option will * be used. * * If you pass a 'route' key then it will call the getRouteAndParameters to * return the route's name and its parameters, then it will call Url::route * * If you pass an 'action' key it'd be processed in a similar way as the * route key, but calling the Url::action method instead. * * If none of these options are found then this function will simple return * a placeholder (#). * * * @param $values * @return mixed */ protected function generateUrl($values) { if (isset($values['full_url'])) { return $values['full_url']; } if (isset($values['url'])) { $isSecure = isset($values['secure']) ? $values['secure'] : $this->defaultSecure; return $this->url->to($values['url'], $isSecure); } if (isset($values['route'])) { list($route, $params) = $this->getRouteAndParameters($values['route']); return $this->url->route($route, $params); } if (isset($values['action'])) { list($route, $params) = $this->getRouteAndParameters($values['action']); return $this->url->action($route, $params); } return '#'; }
function it_passes_prefixed_url_to_url_when_locale_is_not_default(Config $config, UrlGenerator $url) { $config->get('app.locale')->willReturn('en'); $url->to('en/home', [], null)->shouldBeCalled(); $this->url('home'); }
/** * Return a URL. * * @param null $path * @param array $parameters * @param null $secure * @return string */ public function url($path = null, $parameters = [], $secure = null) { return $this->url->to($path, $parameters, $secure); }
/** * Get the action for a "url" option. * * @param array|string $options * * @return string */ private function getUrlAction($options) { return is_array($options) ? $this->url->to($options[0], array_slice($options, 1)) : $this->url->to($options); }
/** * Returns the current Url * **/ public function currentUrl() { return $this->urlGenerator->to($this->request->getPathInfo()); }
/** * @return string */ public function getBaseUri() { return $this->urlGenerator->to('/'); }
/** * Generate url via illuminate * * @param $url * @param array $extra * @param null $secure * @return string */ private function resolveUrl($url, $extra = [], $secure = null) { return $this->generator->to($url, $extra, $secure); }
/** * 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); }