/** * 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']); }
/** * 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']); }
/** * @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); }
/** * @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')); }
/** * @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')); }
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; 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']); }
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; }
/** * @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; }
public function testGuessesIfDuplicateAggregatorShouldBeUsedAndChecksForPhpStyle() { $query = QueryString::fromString('test[]=a&test[]=b'); $this->assertEquals('test%5B0%5D=a&test%5B1%5D=b', (string) $query); }
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(); }
/** * @covers Guzzle\Http\QueryString::fromString */ public function testFromStringDoesntStripTrailingEquals() { $query = QueryString::fromString('data=mF0b3IiLCJUZWFtIERldiJdfX0='); $this->assertEquals('mF0b3IiLCJUZWFtIERldiJdfX0=', $query->get('data')); }
/** * @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('?µ')); }
/** * @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')); }