Ejemplo n.º 1
0
 /**
  * Get the absolute URL for a given route name.
  * You must provide the current request Uri to retrieve the scheme and host.
  *
  * @param UriInterface $uri
  * @param string $route
  * @param array $params
  * @param array $query
  *
  * @return string
  */
 public function absoluteURIFor(UriInterface $uri, $route, array $params = [], array $query = [])
 {
     $path = $this->uriFor($route, $params);
     return (string) $uri->withUserInfo('')->withPath($path)->withQuery(http_build_query($query))->withFragment('');
 }
Ejemplo n.º 2
0
 /**
  * Obfuscates URI if there is an username and a password present
  *
  * @param UriInterface $uri
  *
  * @return UriInterface
  */
 private static function obfuscateUri($uri)
 {
     $userInfo = $uri->getUserInfo();
     if (false !== ($pos = strpos($userInfo, ':'))) {
         return $uri->withUserInfo(substr($userInfo, 0, $pos), '***');
     }
     return $uri;
 }
Ejemplo n.º 3
0
 private function buildRequest(Command $command, UriInterface $uri) : RequestInterface
 {
     $parameters = sprintf('-db=%s&%s', urlencode($this->database), $command);
     $body = new Stream('php://temp', 'wb+');
     $body->write($parameters);
     $body->rewind();
     $request = (new Request($uri->withUserInfo(''), 'POST'))->withAddedHeader('User-agent', 'SimpleFM')->withAddedHeader('Content-type', 'application/x-www-form-urlencoded')->withAddedHeader('Content-length', (string) strlen($parameters))->withBody($body);
     $credentials = urldecode($uri->getUserInfo());
     if ($command->hasIdentity()) {
         Assertion::notNull($this->identityHandler, 'An identity handler must be set to use identities on commands');
         $identity = $command->getIdentity();
         $credentials = sprintf('%s:%s', $identity->getUsername(), $this->identityHandler->decryptPassword($identity));
     }
     $this->logger->info(sprintf('%s?%s', (string) $uri->withUserInfo(''), $parameters));
     if ('' === $credentials) {
         return $request;
     }
     return $request->withAddedHeader('Authorization', sprintf('Basic %s', base64_encode($credentials)));
 }