Ejemplo n.º 1
0
 /**
  * Generate the base URI to be used
  *
  * @param LeagueUriInterface|UriInterface $relative
  *
  * @return LeagueUriInterface|UriInterface
  */
 protected function getBaseUri($relative)
 {
     $userinfo = explode(':', $this->uri->getUserInfo(), 2);
     $user = array_shift($userinfo);
     $pass = array_shift($userinfo);
     return $relative->withHost($this->uri->getHost())->withScheme($this->uri->getScheme())->withUserInfo($user, $pass)->withPort($this->uri->getPort());
 }
 /**
  * Create an UriInterface with the host information from `$server`. It uses `$server['HTTP_HOST']` or
  * `$server['SERVER_NAME']` for this information.
  *
  * @param UriInterface $uri
  * @param array        $server
  *
  * @return UriInterface
  */
 private function withHost(UriInterface $uri, array $server) : UriInterface
 {
     if (isset($server['HTTP_HOST'])) {
         $server['HTTP_HOST'] = preg_replace('/:[0-9]+$/', '', $server['HTTP_HOST']);
         return $uri->withHost($server['HTTP_HOST']);
     } elseif (isset($server['SERVER_NAME'])) {
         return $uri->withHost($server['SERVER_NAME']);
     }
     return $uri;
 }
Ejemplo n.º 3
0
 /**
  * Returns an instance with the provided URI.
  *
  * This method MUST update the Host header of the returned request by
  * default if the URI contains a host component. If the URI does not
  * contain a host component, any pre-existing Host header MUST be carried
  * over to the returned request.
  *
  * You can opt-in to preserving the original state of the Host header by
  * setting `$preserveHost` to `true`. When `$preserveHost` is set to
  * `true`, this method interacts with the Host header in the following ways:
  *
  * - If the the Host header is missing or empty, and the new URI contains
  *   a host component, this method MUST update the Host header in the returned
  *   request.
  * - If the Host header is missing or empty, and the new URI does not contain a
  *   host component, this method MUST NOT update the Host header in the returned
  *   request.
  * - If a Host header is present and non-empty, this method MUST NOT update
  *   the Host header in the returned request.
  *
  * This method MUST be implemented in such a way as to retain the
  * immutability of the message, and MUST return an instance that has the
  * new UriInterface instance.
  *
  * @link http://tools.ietf.org/html/rfc3986#section-4.3
  * @param UriInterface $uri New request URI to use.
  * @param bool $preserveHost Preserve the original state of the Host header.
  * @return self
  */
 public function withUri(UriInterface $uri, $preserveHost = false)
 {
     if (!$preserveHost) {
         $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
         $uri->withHost($host);
     }
     $this->_uri = $uri;
     return $this;
 }