Exemplo n.º 1
0
 /**
  * @param UriInterface $uri
  * @param array        $params
  * @param string       $method
  *
  * @return string
  */
 public function getSignature(UriInterface $uri, array $params, $method = 'POST')
 {
     parse_str($uri->getQuery(), $queryStringData);
     foreach (array_merge($queryStringData, $params) as $key => $value) {
         $signatureData[rawurlencode($key)] = rawurlencode($value);
     }
     ksort($signatureData);
     // determine base uri
     $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
     if ('/' === $uri->getPath()) {
         $baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
     } else {
         $baseUri .= $uri->getPath();
     }
     $baseString = strtoupper($method) . '&';
     $baseString .= rawurlencode($baseUri) . '&';
     $baseString .= rawurlencode($this->buildSignatureDataString($signatureData));
     return base64_encode($this->hash($baseString));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  *
  * In addition to the original method, allows array parameters for filters.
  */
 public function getSignature(UriInterface $uri, array $params, $method = 'POST')
 {
     $queryStringData = !$uri->getQuery() ? [] : array_reduce(explode('&', $uri->getQuery()), function ($carry, $item) {
         list($key, $value) = explode('=', $item, 2);
         $carry[rawurldecode($key)] = rawurldecode($value);
         return $carry;
     }, []);
     foreach (array_merge($queryStringData, $params) as $key => $value) {
         $signatureData[rawurlencode($key)] = rawurlencode($value);
     }
     ksort($signatureData);
     // determine base uri
     $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
     if ('/' == $uri->getPath()) {
         $baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
     } else {
         $baseUri .= $uri->getPath();
     }
     $baseString = strtoupper($method) . '&';
     $baseString .= rawurlencode($baseUri) . '&';
     $baseString .= rawurlencode($this->buildSignatureDataString($signatureData));
     return base64_encode($this->hash($baseString));
 }