예제 #1
0
 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());
 }
예제 #2
0
 /**
  * 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;
 }