/** * Get the scheme for a raw URL. * * @param bool|null $secure * @return string */ protected function getScheme($secure) { if (is_null($secure)) { return $this->forceSchema ?: $this->request->getScheme() . '://'; } return $secure ? 'https://' : 'http://'; }
/** * Handle an incoming request, check to see if we have a redirect in place for the requested URL * and then redirect if we do have a match * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // Get the full URL that has been requested, minus the protocol $full_url = str_replace($request->getScheme() . "://", "", $request->url()); // Check for any results matching the full domain request $results = Redirect::where("type", "domain")->where("from", $full_url)->where("status", "active"); if ($results->exists()) { // Get the first result back $redirect = $results->first(); // Grab the URL before we increment $url = $redirect->to; // Increment the hit count $redirect->increment('hits'); // Redirect off to where we're going return RedirectFacade::to($url); } // Check for any results matching the path only $results = Redirect::where("type", "path")->where("from", "/" . $request->path())->where("status", "active"); // If a redirect exists for this, process it and redirect if ($results->exists()) { // Get the first result back $redirect = $results->first(); // Grab the URL before we increment $url = $redirect->to; // Increment the hit count $redirect->increment('hits'); // Redirect off to where we're going return RedirectFacade::to($url, 301); } // By default, continue afterwards and bail out return $next($request); }
/** * Returns an URL adapted to locale * * @param string $locale * @return string */ private function localizedURL($locale) { // Default language doesn't get a special subdomain $locale = $locale !== $this->defaultLocale ? strtolower($locale) . '.' : ''; // URL elements $uri = $this->request->getRequestUri(); $scheme = $this->request->getScheme(); // Get host $array = explode('.', $this->request->getHttpHost()); $host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1]; // Create URL from template $url = str_replace(['[scheme]', '[locale]', '[host]', '[uri]'], [$scheme, $locale, $host, $uri], $this->config['locale_url']); return url($url); }
/** * Returns an URL adapted to $locale * * @throws SupportedLocalesNotDefined * @throws UnsupportedLocaleException * * @param string|boolean $locale Locale to adapt, false to remove locale * @param string|false $url URL to adapt in the current language. If not passed, the current url would be * taken. * @param array $attributes Attributes to add to the route, if empty, the system would try to extract * them from the url. * * * @return string|false URL translated, False if url does not exist */ public function getLocalizedURL($locale = null, $url = null, $attributes = []) { // Use default if not set if ($locale === null) { $locale = $this->getCurrentLocale(); } // Get request Uri if (empty($url)) { $url = $this->request->getRequestUri(); } else { $parts = parse_url($url); $url = $parts['path'] . (isset($parts['query']) ? '?' . $parts['query'] : ''); } $scheme = $this->request->getScheme(); $locale = $locale && $locale !== $this->getDefaultLocale() ? "{$locale}." : ''; // Get host $array = explode('.', $this->request->getHttpHost()); $host = (array_key_exists(count($array) - 2, $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1]; return app('url')->to("{$scheme}://{$locale}{$host}{$url}", $attributes); }
/** * Gets the request's scheme. * * @return string * @static */ public static function getScheme() { //Method inherited from \Symfony\Component\HttpFoundation\Request return \Illuminate\Http\Request::getScheme(); }
/** * @param $data * @return array */ protected function setRequestData(array $data) { $data['original_headers'] = $this->httpRequest->headers->all(); $data['request'] = ['host' => $this->httpRequest->getHost(), 'method' => $this->httpRequest->method(), 'scheme' => $this->httpRequest->getScheme()]; return $data; }
/** * @param \Illuminate\Http\Request $request * @return string */ public function getRequestContext(Request $request) { return implode('.', [$request->getScheme(), strtolower($request->getMethod()), $this->guessRequestType($request), '_' . $this->quotePath($request->getPathInfo())]); }