/**
  * @param string $specification
  * @return string
  */
 private function createUrlFromUri($specification)
 {
     preg_match('%^(?P<path>[^?#]*)(?:(?:\\?(?P<query>[^#]*))?(?:\\#(?P<fragment>.*))?)$%', (string) $specification, $matches);
     $path = $matches['path'];
     $query = isset($matches['query']) ? $matches['query'] : '';
     $fragment = isset($matches['fragment']) ? $matches['fragment'] : '';
     $uri = $this->uri->withQuery('')->withFragment('');
     // Relative path
     if (!empty($path) && '/' !== $path[0]) {
         $path = rtrim($this->uri->getPath(), '/') . '/' . $path;
     }
     // Path present; set on URI
     if (!empty($path)) {
         $uri = $uri->withPath($path);
     }
     // Query present; set on URI
     if (!empty($query)) {
         $uri = $uri->withQuery($query);
     }
     // Fragment present; set on URI
     if (!empty($fragment)) {
         $uri = $uri->withFragment($fragment);
     }
     return (string) $uri;
 }
Ejemplo n.º 2
0
 /**
  * Retrieves the message's request target.
  *
  * Retrieves the message's request-target either as it will appear (for
  * clients), as it appeared at request (for servers), or as it was
  * specified for the instance (see withRequestTarget()).
  *
  * In most cases, this will be the origin-form of the composed URI,
  * unless a value was provided to the concrete implementation (see
  * withRequestTarget() below).
  *
  * If no URI is available, and no request-target has been specifically
  * provided, this method MUST return the string "/".
  *
  * @return string
  */
 public function getRequestTarget() : string
 {
     if ($this->target !== null) {
         return $this->target;
     }
     return $this->uri->getPath() === '' ? '/' : $this->uri->getPath();
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getRequestTarget()
 {
     if ($this->requestTarget) {
         return $this->requestTarget;
     }
     $target = $this->uri->getPath();
     $target = $target ? $target : '/';
     $query = $this->uri->getQuery();
     $target .= $query ? '?' . $query : '';
     return $target;
 }
Ejemplo n.º 4
0
 public function getRequestTarget()
 {
     if ($this->requestTarget !== null) {
         return $this->requestTarget;
     }
     $target = $this->uri->getPath();
     if ($target == null) {
         $target = '/';
     }
     if ($this->uri->getQuery()) {
         $target .= '?' . $this->uri->getQuery();
     }
     return $target;
 }
Ejemplo n.º 5
0
 /**
  * Retrieves the message's request target.
  *
  * Retrieves the message's request-target either as it will appear (for
  * clients), as it appeared at request (for servers), or as it was
  * specified for the instance (see withRequestTarget()).
  *
  * In most cases, this will be the origin-form of the composed URI,
  * unless a value was provided to the concrete implementation (see
  * withRequestTarget() below).
  *
  * If no URI is available, and no request-target has been specifically
  * provided, this method will return the string "/".
  *
  * @return string
  */
 public function getRequestTarget()
 {
     // Use the explicitly set request target first.
     if (isset($this->requestTarget)) {
         return $this->requestTarget;
     }
     // Build the origin form from the composed URI.
     $target = $this->uri->getPath();
     $query = $this->uri->getQuery();
     if ($query) {
         $target .= "?" . $query;
     }
     // Return "/" if the origin form is empty.
     return $target ?: "/";
 }
Ejemplo n.º 6
0
 /**
  * Gets the request target from current URI
  *
  * @return string
  */
 private function targetFromUri()
 {
     $target = $this->uri->getPath();
     $target .= '' === $this->uri->getQuery() ? '' : '?' . $this->uri->getQuery();
     $target = empty($target) ? '/' : $target;
     return $target;
 }
Ejemplo n.º 7
0
 /**
  * @param UriInterface $uri        Has to contain a host name and cans have a path.
  * @param array        $hostConfig Config for AddHostPlugin. @see AddHostPlugin::configureOptions
  */
 public function __construct(UriInterface $uri, array $hostConfig = [])
 {
     $this->addHostPlugin = new AddHostPlugin($uri, $hostConfig);
     if (rtrim($uri->getPath(), '/')) {
         $this->addPathPlugin = new AddPathPlugin($uri);
     }
 }
Ejemplo n.º 8
0
 /**
  * @return string
  */
 public function getRequestTarget()
 {
     if (isset($this->requestTarget) && $this->requestTarget !== '') {
         return $this->requestTarget;
     }
     if (!isset($this->uri)) {
         return '/';
     }
     $target = $this->uri->getPath();
     if ($this->uri->getQuery() !== '') {
         $target .= '?' . $this->uri->getQuery();
     }
     if ($target === '') {
         $target = '/';
     }
     return $target;
 }
Ejemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function getRequestTarget()
 {
     if ($this->requestTarget !== null) {
         return $this->requestTarget;
     }
     $this->requireUri();
     if ($this->uri === null) {
         return '/';
     }
     $target = $this->uri->getPath();
     $query = $this->uri->getQuery();
     if ($query !== '') {
         $target .= '?' . $query;
     }
     $this->requestTarget = $target;
     return $this->requestTarget;
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function getRequestTarget()
 {
     if ($this->requestTarget !== null) {
         return $this->requestTarget;
     }
     if (!$this->uri instanceof UriInterface) {
         return '/';
     }
     $this->requestTarget = $this->uri->getPath();
     if (!$this->requestTarget) {
         $this->requestTarget = '/';
     }
     if ($this->uri->getQuery()) {
         $this->requestTarget .= '?' . $this->uri->getQuery();
     }
     return $this->requestTarget;
 }
Ejemplo n.º 11
0
 private function createRtmpUrl(UriInterface $uri)
 {
     // Use a relative URL when creating Flash player URLs
     $result = ltrim($uri->getPath(), '/');
     if ($query = $uri->getQuery()) {
         $result .= '?' . $query;
     }
     return $result;
 }
Ejemplo n.º 12
0
 /**
  * Gets the path from a ``UriInterface`` instance after removing the version
  * prefix.
  *
  * @param UriInterface $uri
  *
  * @return string
  */
 public function getPath(UriInterface $uri)
 {
     $path = trim($uri->getPath(), '/');
     $parts = explode('/', $path);
     if ($parts[0] === 'v' . Client::API_VERSION) {
         unset($parts[0]);
     }
     return '/' . implode('/', $parts);
 }
Ejemplo n.º 13
0
 private function parseVirtualHosted(UriInterface $url, array $matches)
 {
     $result = self::$defaultResult;
     $result['path_style'] = false;
     // Remove trailing "." from the prefix to get the bucket
     $result['bucket'] = substr($matches[1], 0, -1);
     $path = $url->getPath();
     // Check if a key was present, and if so, removing the leading "/"
     $result['key'] = !$path || $path == '/' ? null : substr($path, 1);
     return $result;
 }
 /**
  * Perform URI check.
  * @param  null|integer|string $var1
  * @param  mixed               $var2
  * @param  mixed               $var3
  * @param  mixed               $var4
  * @return mixed
  */
 public function runUri($var1 = null, $var2 = null, $var3 = null, $var4 = null)
 {
     if (is_null($var1)) {
         return $this->uri->getPath();
     }
     if (is_numeric($var1) and is_null($var2)) {
         return $this->parts[$var1];
     }
     if (is_numeric($var1) and is_string($var2)) {
         return $this->checkUriSegmentMatch($var1, $var2, $var3, $var4);
     }
     if (is_string($var1)) {
         return $this->checkUriRegexMatch($var1, $var2, $var3);
     }
     throw new LogicException('Invalid use of the uri function.');
 }
Ejemplo n.º 15
0
 /**
  * Retrieves the message's request target.
  *
  * Retrieves the message's request-target either as it will appear (for
  * clients), as it appeared at request (for servers), or as it was
  * specified for the instance (see withRequestTarget()).
  *
  * In most cases, this will be the origin-form of the composed URI,
  * unless a value was provided to the concrete implementation (see
  * withRequestTarget() below).
  *
  * If no URI is available, and no request-target has been specifically
  * provided, this method MUST return the string "/".
  *
  * @return string
  */
 public function getRequestTarget()
 {
     if ($this->requestTarget) {
         return $this->requestTarget;
     }
     if ($this->uri === null) {
         return '/';
     }
     $path = '/' . ltrim($this->uri->getPath(), '/');
     $query = $this->uri->getQuery();
     if ($query) {
         $path .= '?' . $query;
     }
     $this->requestTarget = $path;
     return $this->requestTarget;
 }
Ejemplo n.º 16
0
 /**
  * Retrieves the message's request target.
  *
  * Retrieves the message's request-target either as it will appear (for
  * clients), as it appeared at request (for servers), or as it was
  * specified for the instance (see withRequestTarget()).
  *
  * In most cases, this will be the origin-form of the composed URI,
  * unless a value was provided to the concrete implementation (see
  * withRequestTarget() below).
  *
  * If no URI is available, and no request-target has been specifically
  * provided, this method MUST return the string "/".
  *
  * @return string
  */
 public function getRequestTarget()
 {
     if (null !== $this->requestTarget) {
         return $this->requestTarget;
     }
     if (!$this->uri) {
         return '/';
     }
     $target = $this->uri->getPath();
     if ($this->uri->getQuery()) {
         $target .= '?' . $this->uri->getQuery();
     }
     if (empty($target)) {
         $target = '/';
     }
     return $target;
 }
Ejemplo n.º 17
0
 /**
  * Retrieves the message's request target.
  *
  * Retrieves the message's request-target either as it will appear (for
  * clients), as it appeared at request (for servers), or as it was
  * specified for the instance (see withRequestTarget()).
  *
  * In most cases, this will be the origin-form of the composed URI,
  * unless a value was provided to the concrete implementation (see
  * withRequestTarget() below).
  *
  * If no URI is available, and no request-target has been specifically
  * provided, this method MUST return the string "/".
  *
  * @return string
  */
 public function getRequestTarget()
 {
     if ($this->requestTarget) {
         return $this->requestTarget;
     }
     if ($this->uri === null) {
         return '/';
     }
     $basePath = method_exists($this->uri, 'getBasePath') ? $this->uri->getBasePath() : '';
     $path = $this->uri->getPath();
     $path = $basePath . '/' . ltrim($path, '/');
     $query = $this->uri->getQuery();
     if ($query) {
         $path .= '?' . $query;
     }
     $this->requestTarget = $path;
     return $this->requestTarget;
 }
Ejemplo n.º 18
0
    /**
     * @param UriInterface $uri
     * @return UriInterface
     * @throws \ErrorException
     */
    protected function forward_aliases(UriInterface $uri)
    {
        // strip beginning /
        $path = substr($uri->getPath(), 1);
        $aliases = $this->db->conn()->prepare(<<<SQL
          SELECT `alias_go`, `alias_forward_to`
          FROM `{$this->db->getPrefix()}aliases`
          WHERE `alias_active` = 1 AND `alias_go` = ?
SQL
);
        $aliases->execute(array($path));
        $aliases = $aliases->fetchAll(\PDO::FETCH_ASSOC);
        foreach ($aliases as $alias) {
            if ($path == $alias['alias_go']) {
                $path = $alias['alias_forward_to'];
            }
        }
        return $uri->withPath('/' . $path);
    }
Ejemplo n.º 19
0
 /**
  * Get each invalidation request replicated over all HTTP caching servers
  *
  * @return RequestInterface[]
  */
 public function all()
 {
     $requests = [];
     foreach ($this->queue as $request) {
         $uri = $request->getUri();
         // If a base URI is configured, try to make partial invalidation
         // requests complete.
         if ($this->baseUri) {
             if ($uri->getHost()) {
                 // Absolute URI: does it already have a scheme?
                 if (!$uri->getScheme() && $this->baseUri->getScheme() !== '') {
                     $uri = $uri->withScheme($this->baseUri->getScheme());
                 }
             } else {
                 // Relative URI
                 if ($this->baseUri->getHost() !== '') {
                     $uri = $uri->withHost($this->baseUri->getHost());
                 }
                 if ($this->baseUri->getPort()) {
                     $uri = $uri->withPort($this->baseUri->getPort());
                 }
                 // Base path
                 if ($this->baseUri->getPath() !== '') {
                     $path = $this->baseUri->getPath() . '/' . ltrim($uri->getPath(), '/');
                     $uri = $uri->withPath($path);
                 }
             }
         }
         // Close connections to make sure invalidation (PURGE/BAN) requests
         // will not interfere with content (GET) requests.
         $request = $request->withUri($uri)->withHeader('Connection', 'Close');
         // Create a request to each caching proxy server
         foreach ($this->servers as $server) {
             $requests[] = $request->withUri($uri->withScheme($server->getScheme())->withHost($server->getHost())->withPort($server->getPort()), true);
         }
     }
     return $requests;
 }
Ejemplo n.º 20
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.
  *
  * @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)
 {
     $request = clone $this;
     $request->scheme($uri->getScheme());
     $userInfo = $uri->getUserInfo();
     $parts = explode(':', $userInfo);
     $request->username($parts[0] ?: null);
     $request->password(!empty($parts[1]) ? $parts[1] : null);
     $request->port($uri->getPort());
     if ($preserveHost) {
         $host = $request->headers['Host'];
         $request->host($uri->getHost());
         $request->headers['Host'] = $host;
     } else {
         $request->host($uri->getHost());
     }
     $request->path($uri->getPath());
     $request->query($uri->getQuery());
     $request->fragment($uri->getFragment());
     return $request;
 }
Ejemplo n.º 21
0
 /**
  * Provide private routes to be exposes by search engine
  *
  * @param  \Psr\Http\Message\UriInterface $uri
  * @param  \Slim\Http\Response            $res
  * @return \Slim\Http\Response
  */
 protected function filterPrivateRoutes(UriInterface $uri, Response $res)
 {
     $privates = $this->settings['privateRoutes'];
     $path = $uri->getPath();
     if (is_string($privates) && $privates !== '') {
         $privates = [$privates];
     }
     if (is_null($privates) || is_array($privates) && in_array($path, $privates)) {
         $res = $res->withHeader('X-Robots-Tag', 'noindex, nofollow, noarchive');
     }
     return $res;
 }
Ejemplo n.º 22
0
 private static function getRelativePath(UriInterface $base, UriInterface $target)
 {
     $sourceSegments = explode('/', $base->getPath());
     $targetSegments = explode('/', $target->getPath());
     array_pop($sourceSegments);
     $targetLastSegment = array_pop($targetSegments);
     foreach ($sourceSegments as $i => $segment) {
         if (isset($targetSegments[$i]) && $segment === $targetSegments[$i]) {
             unset($sourceSegments[$i], $targetSegments[$i]);
         } else {
             break;
         }
     }
     $targetSegments[] = $targetLastSegment;
     $relativePath = str_repeat('../', count($sourceSegments)) . implode('/', $targetSegments);
     // A reference to am empty last segment or an empty first sub-segment must be prefixed with "./".
     // This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used
     // as the first segment of a relative-path reference, as it would be mistaken for a scheme name.
     if ('' === $relativePath || false !== strpos(explode('/', $relativePath, 2)[0], ':')) {
         $relativePath = "./{$relativePath}";
     } elseif ('/' === $relativePath[0]) {
         if ($base->getAuthority() != '' && $base->getPath() === '') {
             // In this case an extra slash is added by resolve() automatically. So we must not add one here.
             $relativePath = ".{$relativePath}";
         } else {
             $relativePath = "./{$relativePath}";
         }
     }
     return $relativePath;
 }
Ejemplo n.º 23
0
 /**
  * returns the resolve URI
  *
  * @param LeagueUriInterface|UriInterface $relative the relative URI
  *
  * @return LeagueUriInterface|UriInterface
  */
 protected function resolveRelative($relative)
 {
     $path = $relative->getPath();
     if (!empty($path)) {
         return $this->resolveRelativePath($relative, $path, $relative->getQuery());
     }
     $query = $relative->getQuery();
     if (!empty($query)) {
         return $this->getBaseUri($relative)->withPath($this->uri->getPath())->withQuery($query);
     }
     return $this->getBaseUri($relative)->withPath($this->uri->getPath())->withQuery($this->uri->getQuery());
 }
Ejemplo n.º 24
0
 /**
  * Resolve a base URI with a relative URI and return a new URI.
  *
  * @param UriInterface             $base Base URI
  * @param null|string|UriInterface $rel  Relative URI
  *
  * @throws \InvalidArgumentException
  *
  * @return UriInterface
  */
 public static function resolve(UriInterface $base, $rel = null)
 {
     if ($rel === null || $rel === '') {
         return $base;
     }
     if (!$rel instanceof UriInterface) {
         $rel = new self($rel);
     }
     // Return the relative uri as-is if it has a scheme.
     if ($rel->getScheme()) {
         return $rel->withPath(static::removeDotSegments($rel->getPath()));
     }
     $relParts = ['scheme' => $rel->getScheme(), 'authority' => $rel->getAuthority(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
     $parts = ['scheme' => $base->getScheme(), 'authority' => $base->getAuthority(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
     if (!empty($relParts['path'])) {
         if (strpos($relParts['path'], '/') === 0) {
             $parts['path'] = self::removeDotSegments($relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         } else {
             $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
             $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         }
     } elseif (!empty($relParts['query'])) {
         $parts['query'] = $relParts['query'];
     } elseif ($relParts['fragment'] !== null) {
         $parts['fragment'] = $relParts['fragment'];
     }
     return new self(static::createUriString($parts['scheme'], $parts['authority'], $parts['path'], $parts['query'], $parts['fragment']));
 }
Ejemplo n.º 25
0
 /**
  * Whether the URI is a relative-path reference.
  *
  * A relative reference that does not begin with a slash character is termed a relative-path reference.
  *
  * @param UriInterface $uri
  *
  * @return bool
  * @link https://tools.ietf.org/html/rfc3986#section-4.2
  */
 public static function isRelativePathReference(UriInterface $uri)
 {
     return $uri->getScheme() === '' && $uri->getAuthority() === '' && (!isset($uri->getPath()[0]) || $uri->getPath()[0] !== '/');
 }
 protected function getFiltersData(UriInterface $searchUri, Request $request)
 {
     $filter = new ViewData();
     $filter->url = $searchUri->getPath();
     $filter->list = new ViewDataCollection();
     $filter->list->add($this->getCategoriesFacet($this->getCategory($request), new Uri($request->getRequestUri())));
     $facetConfigs = $this->config->get('sunrise.products.facets');
     $queryParams = \GuzzleHttp\Psr7\parse_query($searchUri->getQuery());
     foreach ($facetConfigs as $facetName => $facetConfig) {
         $filter->list->add($this->getFacet($facetName, $facetConfig, $searchUri, $queryParams));
     }
     return $filter;
 }
Ejemplo n.º 27
0
 /**
  * Take a request URI and update the CI URI object state to match
  *
  * @param UriInterface $uri
  */
 private function forgeUri(UriInterface $uri)
 {
     static::$ci->router->_set_request(explode('/', trim($uri->getPath(), '/')));
     return $this;
 }
Ejemplo n.º 28
0
 /**
  * Resolve a base URI with a relative URI and return a new URI.
  *
  * @param UriInterface $base Base URI
  * @param string       $rel  Relative URI
  *
  * @return UriInterface
  */
 public static function resolve(UriInterface $base, $rel)
 {
     if ($rel === null || $rel === '') {
         return $base;
     }
     if ($rel instanceof UriInterface) {
         $relParts = ['scheme' => $rel->getScheme(), 'host' => $rel->getHost(), 'port' => $rel->getPort(), 'path' => $rel->getPath(), 'query' => $rel->getQuery(), 'fragment' => $rel->getFragment()];
     } else {
         $relParts = parse_url($rel) + ['scheme' => '', 'host' => '', 'port' => '', 'path' => '', 'query' => '', 'fragment' => ''];
     }
     if (!empty($relParts['scheme']) && !empty($relParts['host'])) {
         return $rel instanceof UriInterface ? $rel : self::fromParts($relParts);
     }
     $parts = ['scheme' => $base->getScheme(), 'host' => $base->getHost(), 'port' => $base->getPort(), 'path' => $base->getPath(), 'query' => $base->getQuery(), 'fragment' => $base->getFragment()];
     if (!empty($relParts['host'])) {
         $parts['host'] = $relParts['host'];
         $parts['port'] = $relParts['port'];
         $parts['path'] = self::removeDotSegments($relParts['path']);
         $parts['query'] = $relParts['query'];
         $parts['fragment'] = $relParts['fragment'];
     } elseif (!empty($relParts['path'])) {
         if (substr($relParts['path'], 0, 1) == '/') {
             $parts['path'] = self::removeDotSegments($relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         } else {
             if (!empty($parts['host']) && empty($parts['path'])) {
                 $mergedPath = '/';
             } else {
                 $mergedPath = substr($parts['path'], 0, strrpos($parts['path'], '/') + 1);
             }
             $parts['path'] = self::removeDotSegments($mergedPath . $relParts['path']);
             $parts['query'] = $relParts['query'];
             $parts['fragment'] = $relParts['fragment'];
         }
     } elseif (!empty($relParts['query'])) {
         $parts['query'] = $relParts['query'];
     } elseif ($relParts['fragment'] != null) {
         $parts['fragment'] = $relParts['fragment'];
     }
     return static::fromParts($parts);
 }
Ejemplo n.º 29
0
 private static function decodeUnreservedCharacters(UriInterface $uri)
 {
     $regex = '/%(?:2D|2E|5F|7E|3[0-9]|[46][1-9A-F]|[57][0-9A])/i';
     $callback = function (array $match) {
         return rawurldecode($match[0]);
     };
     return $uri->withPath(preg_replace_callback($regex, $callback, $uri->getPath()))->withQuery(preg_replace_callback($regex, $callback, $uri->getQuery()));
 }
Ejemplo n.º 30
0
 /**
  * Indicates if the route matches with the URI.
  *
  * @param UriInterface $uri
  * @param array        $attributes
  *
  * @return bool
  */
 public final function matchesWithUri(UriInterface $uri, &$attributes = [])
 {
     $matched = ('' === ($scheme = $this->getScheme()) or $scheme === $uri->getScheme()) && ('' === ($host = $this->getHost()) or preg_match($this->compileHost(), $uri->getHost(), $attrs)) && preg_match($this->compilePath(), $uri->getPath(), $attrs);
     $attributes = array_filter($attrs, 'is_string');
     return $matched;
 }