public function testAllowsMultipleValuesPerKey() { $q = new QueryString(); $q->add('facet', 'size'); $q->add('facet', 'width'); $q->add('facet.field', 'foo'); // Use the duplicate aggregator $q->setAggregator(new DuplicateAggregator()); $this->assertEquals('facet=size&facet=width&facet.field=foo', $q->__toString()); }
/** * Запрос На авторизацию * * @param string $redirectUrl Урл для * @param string $state дополнительный get параметр который подставляется к урл * * @return string */ public function getLoginUrl($redirectUrl, $state = ' ') { $this->redirectUrl = $redirectUrl; $query = new QueryString(); $query->add('response_type', 'code'); $query->add('client_id', $this->clientId); $query->add('redirect_uri', $redirectUrl); $query->add('state', $state); //$url = new Url('https','o2.mail.ru',null,null,null,'login',$query); $url = new Url('https', 'oauth.yandex.ru', null, null, null, 'authorize', $query); return $url->__toString(); }
/** * Get a signed URL that is valid for a specific amount of time for a virtual * hosted bucket. * * @param string $bucket The bucket of the object. * @param string $key The key of the object. * @param int $duration The number of seconds the URL is valid. * @param bool $cnamed Whether or not the bucket should be referenced by a * CNAMEd URL. * @param bool $torrent Set to true to append ?torrent and retrieve the * torrent of the file. * * @return string Returns a signed URL. * * @throws LogicException when $torrent and $requesterPays is passed. * * @link http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTAuthentication.html */ public function getSignedUrl($bucket, $key, $duration, $cnamed = false, $torrent = false, $requesterPays = false) { if ($torrent && $requesterPays) { throw new \InvalidArgumentException('Cannot use ?requesterPays with ?torrent.'); } $expires = time() + ($duration ? $duration : 60); $plugin = $this->getEventManager()->getAttached('Guzzle\\Aws\\S3\\SignS3RequestPlugin'); $plugin = isset($plugin[0]) ? $plugin[0] : false; $isSigned = $plugin != false; $xAmzHeaders = $torrentStr = ''; $url = 'http://' . $bucket . ($cnamed ? '' : '.' . $this->getConfig()->get('region')); if ($key) { $url .= '/' . $key; } $qs = new QueryString(); if ($isSigned) { $qs->add('AWSAccessKeyId', $this->getAccessKeyId())->add('Expires', $expires); } if ($torrent) { $qs->add('torrent', false); $torrentStr = '?torrent'; } else { if ($requesterPays) { $qs->add('x-amz-request-payer', 'requester'); $xAmzHeaders .= 'x-amz-request-payer:requester' . "\n"; } } if ($isSigned) { $strToSign = sprintf("GET\n\n\n{$expires}\n{$xAmzHeaders}/%s/%s{$torrentStr}", QueryString::rawurlencode($bucket, array('/')), QueryString::rawurlencode($key, array('/'))); $qs->add('Signature', $plugin->getSignature()->signString($strToSign)); } return $url . $qs; }
/** * Same as QueryString::fromString, supports comma-separated values * * @param string $query * * @return \Guzzle\Http\QueryString */ public function parseQueryString($query) { $q = new QueryString(); if (0 !== strlen($query)) { if ($query[0] == '?') { $query = substr($query, 1); } foreach (explode('&', $query) as $kvp) { $parts = explode('=', $kvp, 2); $key = rawurldecode($parts[0]); if (array_key_exists(1, $parts)) { if (strpos($parts[1], ',') !== false) { $value = explode(',', $parts[1]); foreach ($value as &$item) { $item = str_replace('+', '%20', $item); $item = rawurldecode($item); } } else { $value = str_replace('+', '%20', $parts[1]); $value = rawurldecode($value); } $q->add($key, $value); } else { $q->add($key, ''); } } } return $q; }