コード例 #1
0
 public function aggregate($key, $value, QueryString $query)
 {
     if ($query->isUrlEncoding()) {
         return array($query->encodeValue($key) => implode(',', array_map(array($query, 'encodeValue'), $value)));
     } else {
         return array($key => implode(',', $value));
     }
 }
コード例 #2
0
 public function aggregate($key, $value, QueryString $query)
 {
     $key = "{$key}[]";
     if ($query->isUrlEncoding()) {
         return array($query->encodeValue($key) => array_map(array($query, 'encodeValue'), $value));
     } else {
         return array($key => $value);
     }
 }
コード例 #3
0
 public function testEncodes()
 {
     $query = new QueryString();
     $query->useUrlEncoding(false);
     $a = new Ag();
     $key = 'test 123';
     $value = array('foo 123', 'baz', 'bar');
     $result = $a->aggregate($key, $value, $query);
     $this->assertEquals(array('test 123' => 'foo 123,baz,bar'), $result);
 }
コード例 #4
0
 public function testEncodes()
 {
     $query = new QueryString();
     $query->useUrlEncoding(false);
     $a = new Ag();
     $key = 'facet 1';
     $value = array('size a', 'width b');
     $result = $a->aggregate($key, $value, $query);
     $this->assertEquals(array('facet 1' => array('size a', 'width b')), $result);
 }
コード例 #5
0
 public function testEncodes()
 {
     $query = new QueryString();
     $query->useUrlEncoding(false);
     $a = new Ag();
     $key = 't';
     $value = array('v1' => 'a', 'v2' => 'b', 'v3' => array('v4' => 'c', 'v5' => 'd'));
     $result = $a->aggregate($key, $value, $query);
     $this->assertEquals(array('t[v1]' => 'a', 't[v2]' => 'b', 't[v3][v4]' => 'c', 't[v3][v5]' => 'd'), $result);
 }
コード例 #6
0
ファイル: OAuth.php プロジェクト: cnam/yandex_metrica
 /**
  * Запрос На авторизацию
  *
  * @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();
 }
コード例 #7
0
ファイル: SolrRequest.php プロジェクト: cpliakas/psolr
 /**
  * {@inheritDoc}
  *
  * Converts booleans to strings.
  */
 public function set($key, $value)
 {
     if (is_bool($value)) {
         $value = $value ? 'true' : 'false';
     }
     return parent::set($key, $value);
 }
コード例 #8
0
 /**
  * {@inheritDoc}
  */
 public function aggregate($key, $value, QueryString $query)
 {
     $ret = [];
     foreach ($value as $k => $v) {
         if (is_int($k)) {
             return [$query->encodeValue("{$key}[]") => $value];
         }
         $k = "{$key}[{$k}]";
         if (is_array($v)) {
             $ret = array_merge($ret, self::aggregate($k, $v, $query));
         } else {
             $ret[$query->encodeValue($k)] = $query->encodeValue($v);
         }
     }
     return $ret;
 }
コード例 #9
0
 /**
  * @covers \Guzzle\Http\QueryString::__toString
  * @covers \Guzzle\Http\QueryString::encodeData
  * @covers \Guzzle\Http\QueryString::aggregateUsingPhp
  */
 public function testAllowsNestedQueryData()
 {
     $this->q->replace(array('test' => 'value', 't' => array('v1' => 'a', 'v2' => 'b', 'v3' => array('v4' => 'c', 'v5' => 'd'))));
     $this->q->setEncodeFields(false);
     $this->q->setEncodeValues(false);
     $this->assertEquals('?test=value&t[v1]=a&t[v2]=b&t[v3][v4]=c&t[v3][v5]=d', $this->q->__toString());
 }
コード例 #10
0
 /**
  * {@inheritdoc}
  */
 public function __construct(array $data = null)
 {
     parent::__construct($data);
     $this->setFieldSeparator(';')->setPrefix('')->setValueSeparator('=')->setEncodeFields(false)->setEncodeValues(false)->setAggregateFunction(function ($key, $value, $encodeFields = false, $encodeValues = false) {
         $value = array_unique($value);
         return array($encodeFields ? rawurlencode($key) : $key => $encodeValues ? array_map('rawurlencode', $value) : $value);
     });
 }
コード例 #11
0
ファイル: Url.php プロジェクト: unkerror/Budabot
 /**
  * Factory method to create a new URL from a URL string
  *
  * @param string $url Full URL used to create a Url object
  *
  * @return Url
  */
 public static function factory($url)
 {
     $parts = ParserRegistry::getInstance()->getParser('url')->parseUrl($url);
     // Convert the query string into a QueryString object
     if ($parts['query']) {
         $parts['query'] = QueryString::fromString($parts['query']);
     }
     return new self($parts['scheme'], $parts['host'], $parts['user'], $parts['pass'], $parts['port'], $parts['path'], $parts['query'], $parts['fragment']);
 }
コード例 #12
0
ファイル: Url.php プロジェクト: omusico/isle-web-framework
 /**
  * Factory method to create a new URL from a URL string
  *
  * @param string $url Full URL used to create a Url object
  *
  * @return Url
  */
 public static function factory($url)
 {
     static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null, 'user' => null, 'pass' => null, 'fragment' => null);
     $parts = parse_url($url) + $defaults;
     // Convert the query string into a QueryString object
     if ($parts['query'] || 0 !== strlen($parts['query'])) {
         $parts['query'] = QueryString::fromString($parts['query']);
     }
     return new self($parts['scheme'], $parts['host'], $parts['user'], $parts['pass'], $parts['port'], $parts['path'], $parts['query'], $parts['fragment']);
 }
コード例 #13
0
 /**
  * @param InputInterface  $input  The input instance
  * @param OutputInterface $output The output instance
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $pages = 25;
     $page = 1;
     $output->writeln('<info>Beginning Google crawl</info>');
     $query = new QueryString(array('q' => 'site:drupalcode.org "composer.json" "drupal-module"'));
     $url = 'http://www.google.com/search?' . $query;
     // Load page 1
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $repos = array();
     // Crawl through search pages.
     do {
         $current = $client->getHistory()->current()->getUri();
         $output->writeln('<info>Crawling:</info> ' . $current);
         // Use a CSS filter to select only the result links:
         $links = $crawler->filter('li h3 a');
         // Search the links for the domain:
         foreach ($links as $index => $link) {
             $href = $link->getAttribute('href');
             $query = QueryString::fromString(parse_url($href, PHP_URL_QUERY));
             $url = $query->get('q');
             // Match pages with composer.json in root.
             if (preg_match('/^http:\\/\\/drupalcode.org.+\\.git\\/.+\\/composer.json$/i', $url)) {
                 // Strip to git url and rewrite to drupalcode.org then store unique matches.
                 $matches = array();
                 preg_match('/^http:\\/\\/drupalcode.org.+\\.git/i', $url, $matches);
                 $repo = str_replace('http://drupalcode.org/', 'http://git.drupal.org/', $matches[0]);
                 $repos[$repo] = null;
                 $output->writeln('<info>Found:</info> ' . $repo);
             }
         }
         // Turn the page.
         $page++;
         $node = $crawler->filter('table#nav')->selectLink($page);
         if ($node->count()) {
             $crawler = $client->click($node->link());
         } else {
             break;
         }
     } while ($page < $pages);
     $path = getcwd() . '/satis.json';
     $file = new JsonFile($path);
     $data = $file->read();
     foreach ($data['repositories'] as $file_repo) {
         $repos[$file_repo['url']] = null;
     }
     $repos = array_keys($repos);
     sort($repos);
     $data['repositories'] = array();
     foreach ($repos as $repo) {
         $data['repositories'][] = array('url' => $repo, 'type' => 'vcs');
     }
     $file->write((array) $data);
 }
コード例 #14
0
ファイル: CreatePostMock.php プロジェクト: rafrsr/generic-api
 /**
  * @inheritDoc
  */
 public function mock(RequestInterface $request)
 {
     $body = $request->getBody()->getContents();
     $bodyArray = QueryString::fromString($body);
     $post = new Post();
     $post->setId(101);
     $post->setTitle($bodyArray['title']);
     $post->setUserId($bodyArray['userId']);
     $post->setBody($bodyArray['body']);
     return new Response(200, [], SerializerBuilder::create()->build()->serialize($post, 'json'));
 }
コード例 #15
0
ファイル: UpdatePostMock.php プロジェクト: rafrsr/generic-api
 /**
  * @inheritDoc
  */
 public function mock(RequestInterface $request)
 {
     $json = file_get_contents(__DIR__ . '/../../Fixtures/post1.json');
     $post = SerializerBuilder::create()->build()->deserialize($json, 'Rafrsr\\SampleApi\\Model\\Post', 'json');
     $body = $request->getBody()->getContents();
     $bodyArray = QueryString::fromString($body);
     $post->setTitle($bodyArray['title']);
     $post->setUserId($bodyArray['userId']);
     $post->setBody($bodyArray['body']);
     return new Response(200, [], SerializerBuilder::create()->build()->serialize($post, 'json'));
 }
コード例 #16
0
ファイル: Url.php プロジェクト: carlyns/RESUSblog
 /**
  * Factory method to create a new URL from a URL string
  *
  * @param string $url Full URL used to create a Url object
  *
  * @return Url
  * @throws InvalidArgumentException
  */
 public static function factory($url)
 {
     static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null, 'user' => null, 'pass' => null, 'fragment' => null);
     if (false === ($parts = parse_url($url))) {
         throw new InvalidArgumentException('Was unable to parse malformed url: ' . $url);
     }
     $parts += $defaults;
     // Convert the query string into a QueryString object
     if ($parts['query'] || 0 !== strlen($parts['query'])) {
         $parts['query'] = QueryString::fromString($parts['query']);
     }
     return new static($parts['scheme'], $parts['host'], $parts['user'], $parts['pass'], $parts['port'], $parts['path'], $parts['query'], $parts['fragment']);
 }
コード例 #17
0
 public function __construct(ConnectionInterface $conn, RequestInterface $req)
 {
     $body = (string) $req->getBody();
     if (!empty($body)) {
         $query = QueryString::fromString($body);
         $fields = $query->getAll();
         foreach ($fields as $field => $value) {
             $req->setPostField($field, $value);
         }
     }
     $this->conn = $conn;
     $this->session = $conn->Session;
     $this->req = $req;
 }
コード例 #18
0
ファイル: GetPostsMock.php プロジェクト: rafrsr/generic-api
 /**
  * @inheritDoc
  */
 public function mock(RequestInterface $request)
 {
     $json = file_get_contents(__DIR__ . '/../../Fixtures/posts.json');
     $userId = QueryString::fromString($request->getUri()->getQuery())->get('userId');
     $response = new Response(200, [], $json);
     //filter
     if ($userId) {
         /** @var Post[] $posts */
         $posts = (new JsonMessageParser('array<Rafrsr\\SampleApi\\Model\\Post>'))->parse($response);
         $filteredPosts = [];
         foreach ($posts as $post) {
             if ($post->getUserId() == $userId) {
                 $filteredPosts[] = $post;
             }
         }
         $response = new Response(200, [], SerializerBuilder::create()->build()->serialize($filteredPosts, 'json'));
     }
     return $response;
 }
コード例 #19
0
ファイル: CopyObject.php プロジェクト: pfeyssaguet/guzzle-aws
 /**
  * {@inheritdoc}
  */
 protected function build()
 {
     $this->request = $this->client->getS3Request(RequestInterface::PUT, $this->get('bucket'), $this->get('key'));
     $this->applyDefaults($this->request);
     // Set the PUT copy specific headers
     $this->request->setHeader('x-amz-copy-source', QueryString::rawurlencode($this->get('copy_source'), array('/')));
     if ($this->get('metadata_directive')) {
         $this->request->setHeader('x-amz-metadata-directive', strtoupper($this->get('metadata_directive')));
     }
     if ($this->get('copy_source_if_match')) {
         $this->getRequestHeaders()->set('x-amz-copy-source-if-match', $this->get('copy_source_if_match'));
     }
     if ($this->get('copy_source_if_none_match')) {
         $this->request->setHeader('x-amz-copy-source-if-none-match', $this->get('copy_source_if_none_match'));
     }
     if ($this->get('copy_source_if_unmodified_since')) {
         $this->request->setHeader('x-amz-copy-source-if-unmodified-since', $this->get('copy_source_if_unmodified_since'));
     }
     if ($this->get('copy_source_if_modified_since')) {
         $this->request->setHeader('x-amz-copy-source-if-modified-since', $this->get('copy_source_if_modified_since'));
     }
     $this->request->getCurlOptions()->set(CURLOPT_LOW_SPEED_TIME, null);
 }
コード例 #20
0
ファイル: CollectionTest.php プロジェクト: alvarobfdev/applog
 public function testUsesStaticWhenCreatingNew()
 {
     $qs = new QueryString(array('a' => 'b', 'c' => 'd'));
     $this->assertInstanceOf('Guzzle\\Http\\QueryString', $qs->map(function ($a, $b) {
     }));
     $this->assertInstanceOf('Guzzle\\Common\\Collection', $qs->map(function ($a, $b) {
     }, array(), false));
     $this->assertInstanceOf('Guzzle\\Http\\QueryString', $qs->filter(function ($a, $b) {
     }));
     $this->assertInstanceOf('Guzzle\\Common\\Collection', $qs->filter(function ($a, $b) {
     }, false));
 }
コード例 #21
0
ファイル: QueryString.php プロジェクト: cultuurnet/auth
 public function __construct(array $data = null)
 {
     parent::__construct($data);
     $this->aggregator = array(__CLASS__, 'aggregateUsingDuplicates');
 }
コード例 #22
0
ファイル: QueryStringTest.php プロジェクト: jsnshrmn/Suma
 /**
  * @covers Guzzle\Http\QueryString::fromString
  * @see https://github.com/guzzle/guzzle/issues/108
  */
 public function testFromStringDoesntMangleZeroes()
 {
     $query = QueryString::fromString('var=0');
     $this->assertSame('0', $query->get('var'));
 }
コード例 #23
0
ファイル: QueryStringTest.php プロジェクト: norv/guzzle
 /**
  * @covers Guzzle\Http\QueryString::fromString
  */
 public function testProperlyDealsWithDuplicateQueryStringValues()
 {
     $query = QueryString::fromString('foo=a&foo=b&?µ=c');
     $this->assertEquals(array('a', 'b'), $query->get('foo'));
     $this->assertEquals('c', $query->get('?µ'));
 }
コード例 #24
0
ファイル: Url.php プロジェクト: enoch85/owncloud-testserver
 private function addQuery(QueryString $new, $strictRfc386)
 {
     if (!$strictRfc386) {
         $new->merge($this->query);
     }
     $this->query = $new;
 }
コード例 #25
0
 public function testGuessesIfDuplicateAggregatorShouldBeUsedAndChecksForPhpStyle()
 {
     $query = QueryString::fromString('test[]=a&test[]=b');
     $this->assertEquals('test%5B0%5D=a&test%5B1%5D=b', (string) $query);
 }
コード例 #26
0
ファイル: S3Client.php プロジェクト: pfeyssaguet/guzzle-aws
 /**
  * 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;
 }
コード例 #27
0
 /**
  * @covers Guzzle\Http\QueryString::fromString
  */
 public function testFromStringDoesntStripTrailingEquals()
 {
     $query = QueryString::fromString('data=mF0b3IiLCJUZWFtIERldiJdfX0=');
     $this->assertEquals('mF0b3IiLCJUZWFtIERldiJdfX0=', $query->get('data'));
 }
コード例 #28
0
ファイル: CommandBuilder.php プロジェクト: dh-open/desk-php
 /**
  * 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;
 }
コード例 #29
0
 protected function onRequest(ConnectionInterface $from, RequestInterface $request)
 {
     $requestPath = $request->getPath();
     $body = (string) $request->getBody();
     if (!empty($body)) {
         $query = QueryString::fromString($body);
         $fields = $query->getAll();
         $request->addPostFields($fields);
     }
     // TODO: use only $req->acceptLanguage() in Managers
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = (string) $request->getHeaders()->get('accept-language');
     $routes = array('/' => 'executeUiBooter', '/api' => 'executeApiCall', '/api/group' => 'executeApiCallGroup', '/sbin/apicall.php' => 'executeApiCall', '/sbin/apicallgroup.php' => 'executeApiCallGroup', '/sbin/rawdatacall.php' => 'executeRawDataCall', '#^/([a-zA-Z0-9-_.]+)\\.html$#' => 'executeUiBooter', '#^/(bin|boot|etc|home|tmp|usr|var)/(.*)$#' => 'executeReadFile', '/webos.webapp' => 'executeReadManifest', '/hello' => 'executeSayHello');
     foreach ($routes as $path => $method) {
         $matched = false;
         if (substr($path, 0, 1) == '#') {
             // Regex
             if (preg_match($path, $requestPath, $matches)) {
                 $result = $this->{$method}($from, $request, $matches);
                 $matched = true;
             }
         } else {
             if ($path == $requestPath) {
                 $result = $this->{$method}($from, $request);
                 $matched = true;
             }
         }
         if ($matched) {
             if (empty($result)) {
                 $result = '';
             }
             if ($result instanceof ResponseContent) {
                 $result = $result->generate();
             }
             if ($result instanceof HTTPServerResponse) {
                 if ($result->headersSent()) {
                     // Implicit mode, content already sent
                     if ($result->getHeader('Connection') != 'keep-alive') {
                         $from->close();
                     }
                 } else {
                     $result->send();
                 }
                 return;
             }
             $response = null;
             if (is_string($result)) {
                 $response = new Response(200, array(), (string) $result);
             } else {
                 $response = $result;
             }
             $from->send((string) $response);
             $from->close();
             return;
         }
     }
     $resp = new Response(404, array('Content-Type' => 'text/plain'), '404 Not Found');
     $from->send((string) $resp);
     $from->close();
 }