/** * Parse host information from keyed local host name * * @param Request $request * * @return void */ protected static function getHostFromUrl(Url $url) { if (count($url->getHost()) > 2) { return preg_replace('/\\-/', '.', $url->getHost()[0]); } return null; }
public function testGetterAccess() { $this->assertInstanceof('League\Url\Components\Scheme', $this->url->getScheme()); $this->assertInstanceof('League\Url\Components\User', $this->url->getUser()); $this->assertInstanceof('League\Url\Components\Pass', $this->url->getPass()); $this->assertInstanceof('League\Url\Components\Host', $this->url->getHost()); $this->assertInstanceof('League\Url\Components\Port', $this->url->getPort()); $this->assertInstanceof('League\Url\Components\Path', $this->url->getPath()); $this->assertInstanceof('League\Url\Components\Query', $this->url->getQuery()); $this->assertInstanceof('League\Url\Components\Fragment', $this->url->getFragment()); }
/** * Get the location of a redirect or false if none * * @param Url $url * * @return Url|false */ protected function getRedirectLocation(Url $url) { /** @var ResponseInterface $response */ $response = Guzzle::get((string) $url, ['allow_redirects' => false, 'verify' => env('REDIRECTS_VERIFY_SSL', true)]); if (!env('ALLOW_INSANE_STATUS_CODES', false) && ($response->getStatusCode() > 399 || $response->getStatusCode() < 300)) { return false; } $rawLocation = $response->getHeader('location'); if (!$rawLocation) { return false; } $rawLocation = $rawLocation[0]; $newUrl = $this->getUrlObject($rawLocation); if (!$newUrl->getHost()->get()) { $newUrl->setHost($url->getHost()->get()); if ('/' !== $rawLocation[0]) { $newUrl->setPath(rtrim($url->getPath()->get(), '/') . '/' . ltrim($newUrl->getPath()->get(), '/')); } } return $newUrl; }
/** * Format a URL authority according to the Formatter properties * * @param Url $url * * @return string */ protected function formatAuthority(Url $url) { if ('' == $url->getHost()) { return ''; } return '//' . $url->userInfo->getUriComponent() . $this->formatHost($url->host) . $url->port->getUriComponent(); }