/** * 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 = $this->uri->getBasePath(); $path .= $this->uri->getPath(); $query = $this->uri->getQuery(); if ($query) { $path .= '?' . $query; } $this->requestTarget = $path; return $this->requestTarget; }
/** * 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; }
public function basePath() { return $this->uri->getBasePath(); }
/** * @param UriInterface $uri * * @return string */ private function extractPath(UriInterface $uri) { // Slim3 compatibility if ($uri instanceof Uri) { $basePath = $uri->getBasePath(); if (!empty($basePath)) { return $basePath; } } return $uri->getPath(); }