本文整理汇总了PHP中Zend\Uri\Http::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::getQuery方法的具体用法?PHP Http::getQuery怎么用?PHP Http::getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Http
的用法示例。
在下文中一共展示了Http::getQuery方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAssembling
/**
* @param Query $route
* @param string $path
* @param integer $offset
* @param array $params
* @param boolean $skipAssembling
*/
public function testAssembling(Query $route, $path, $offset, array $params = null, $skipAssembling = false)
{
if ($params === null || $skipAssembling) {
// Data which will not match are not tested for assembling.
return;
}
$uri = new Http();
$result = $route->assemble($params, array('uri' => $uri));
if ($offset !== null) {
$this->assertEquals($offset, strpos($path, $uri->getQuery(), $offset));
} else {
$this->assertEquals($path, $uri->getQuery());
}
}
示例2: doRequest
/**
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function doRequest($request)
{
$zendRequest = $this->application->getRequest();
$zendResponse = $this->application->getResponse();
$zendResponse->setStatusCode(200);
$uri = new HttpUri($request->getUri());
$queryString = $uri->getQuery();
$method = strtoupper($request->getMethod());
$zendRequest->setCookies(new Parameters($request->getCookies()));
if ($queryString) {
parse_str($queryString, $query);
$zendRequest->setQuery(new Parameters($query));
}
if ($request->getContent() !== null) {
$zendRequest->setContent($request->getContent());
} elseif ($method != HttpRequest::METHOD_GET) {
$post = $request->getParameters();
$zendRequest->setPost(new Parameters($post));
}
$zendRequest->setMethod($method);
$zendRequest->setUri($uri);
$zendRequest->setRequestUri(str_replace('http://localhost', '', $request->getUri()));
$zendRequest->setHeaders($this->extractHeaders($request));
$this->application->run();
$this->zendRequest = $zendRequest;
$exception = $this->application->getMvcEvent()->getParam('exception');
if ($exception instanceof \Exception) {
throw $exception;
}
$response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
return $response;
}
示例3: doRequest
/**
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function doRequest($request)
{
$zendRequest = $this->application->getRequest();
$zendResponse = $this->application->getResponse();
$uri = new HttpUri($request->getUri());
$queryString = $uri->getQuery();
$method = $request->getMethod();
if ($queryString) {
parse_str($queryString, $query);
}
if ($method == HttpRequest::METHOD_POST) {
$post = $request->getParameters();
$zendRequest->setPost(new Parameters($post));
} elseif ($method == HttpRequest::METHOD_GET) {
$query = $request->getParameters();
$zendRequest->setQuery(new Parameters($query));
} elseif ($method == HttpRequest::METHOD_PUT) {
$zendRequest->setContent($request->getContent());
}
$zendRequest->setMethod($method);
$zendRequest->setUri($uri);
$this->application->run();
$this->zendRequest = $zendRequest;
$exception = $this->application->getMvcEvent()->getParam('exception');
if ($exception instanceof \Exception) {
throw $exception;
}
$response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
return $response;
}
示例4: write
/**
* Send request to the remote server with streaming support.
*
* @param string $method
* @param \Zend\Uri\Http $uri
* @param string $http_ver
* @param array $headers
* @param string $body
* @return string Request as string
*/
public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
{
// Make sure we're properly connected
if (!$this->socket) {
throw new Adapter\Exception('Trying to write but we are not connected');
}
$host = $uri->getHost();
$host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
throw new Adapter\Exception('Trying to write but we are connected to the wrong host');
}
// Save request method for later
$this->method = $method;
// Build request headers
$path = $uri->getPath();
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "{$method} {$path} HTTP/{$http_ver}\r\n";
foreach ($headers as $k => $v) {
if (is_string($k)) {
$v = ucfirst($k) . ": {$v}";
}
$request .= "{$v}\r\n";
}
// Send the headers over
$request .= "\r\n";
if (!@fwrite($this->socket, $request)) {
throw new Adapter\Exception('Error writing request to server');
}
//read from $body, write to socket
$chunk = $body->read(self::CHUNK_SIZE);
while ($chunk !== FALSE) {
if (!@fwrite($this->socket, $chunk)) {
throw new Adapter\Exception('Error writing request to server');
}
$chunk = $body->read(self::CHUNK_SIZE);
}
$body->closeFileHandle();
return 'Large upload, request is not cached.';
}
示例5: doRequest
/**
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function doRequest($request)
{
$this->createApplication();
$zendRequest = $this->application->getRequest();
$uri = new HttpUri($request->getUri());
$queryString = $uri->getQuery();
$method = strtoupper($request->getMethod());
$zendRequest->setCookies(new Parameters($request->getCookies()));
$query = [];
$post = [];
$content = $request->getContent();
if ($queryString) {
parse_str($queryString, $query);
}
if ($method !== HttpRequest::METHOD_GET) {
$post = $request->getParameters();
}
$zendRequest->setQuery(new Parameters($query));
$zendRequest->setPost(new Parameters($post));
$zendRequest->setFiles(new Parameters($request->getFiles()));
$zendRequest->setContent($content);
$zendRequest->setMethod($method);
$zendRequest->setUri($uri);
$requestUri = $uri->getPath();
if (!empty($queryString)) {
$requestUri .= '?' . $queryString;
}
$zendRequest->setRequestUri($requestUri);
$zendRequest->setHeaders($this->extractHeaders($request));
$this->application->run();
// get the response *after* the application has run, because other ZF
// libraries like API Agility may *replace* the application's response
//
$zendResponse = $this->application->getResponse();
$this->zendRequest = $zendRequest;
$exception = $this->application->getMvcEvent()->getParam('exception');
if ($exception instanceof \Exception) {
throw $exception;
}
$response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
return $response;
}
示例6: doRequest
/**
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function doRequest($request)
{
$zendRequest = $this->application->getRequest();
$zendResponse = $this->application->getResponse();
$zendHeaders = $zendRequest->getHeaders();
if (!$zendHeaders->has('Content-Type')) {
$server = $request->getServer();
if (isset($server['CONTENT_TYPE'])) {
$zendHeaders->addHeaderLine('Content-Type', $server['CONTENT_TYPE']);
}
}
$zendResponse->setStatusCode(200);
$uri = new HttpUri($request->getUri());
$queryString = $uri->getQuery();
$method = strtoupper($request->getMethod());
$zendRequest->setCookies(new Parameters($request->getCookies()));
if ($queryString) {
parse_str($queryString, $query);
$zendRequest->setQuery(new Parameters($query));
}
if ($method == HttpRequest::METHOD_POST) {
$post = $request->getParameters();
$zendRequest->setPost(new Parameters($post));
} elseif ($method == HttpRequest::METHOD_PUT) {
$zendRequest->setContent($request->getContent());
}
$zendRequest->setMethod($method);
$zendRequest->setUri($uri);
$this->application->run();
$this->zendRequest = $zendRequest;
$exception = $this->application->getMvcEvent()->getParam('exception');
if ($exception instanceof \Exception) {
throw $exception;
}
$response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
return $response;
}
示例7: url
/**
* Set the request URL
*
* @param string $url
* @param string|null $method
* @param array|null $params
* @return AbstractControllerTestCase
*/
public function url($url, $method = HttpRequest::METHOD_GET, $params = [])
{
$request = $this->getRequest();
if ($this->useConsoleRequest) {
preg_match_all('/(--\\S+[= ]"[^\\s"]*\\s*[^\\s"]*")|(--\\S+=\\S+|--\\S+\\s\\S+|\\S+)/', $url, $matches);
$params = str_replace([' "', '"'], ['=', ''], $matches[0]);
$request->params()->exchangeArray($params);
return $this;
}
$query = $request->getQuery()->toArray();
$post = $request->getPost()->toArray();
$uri = new HttpUri($url);
$queryString = $uri->getQuery();
if ($queryString) {
parse_str($queryString, $query);
}
if ($method == HttpRequest::METHOD_POST) {
if (count($params) != 0) {
$post = $params;
}
} elseif ($method == HttpRequest::METHOD_GET) {
$query = array_merge($query, $params);
} elseif ($method == HttpRequest::METHOD_PUT || $method == HttpRequest::METHOD_PATCH) {
if (count($params) != 0) {
$content = http_build_query($params);
$request->setContent($content);
}
} elseif ($params) {
trigger_error('Additional params is only supported by GET, POST, PUT and PATCH HTTP method', E_USER_NOTICE);
}
$request->setMethod($method);
$request->setQuery(new Parameters($query));
$request->setPost(new Parameters($post));
$request->setUri($uri);
$request->setRequestUri($uri->getPath());
return $this;
}
示例8: url
/**
* Set the request URL
*
* @param string $url
* @param string|null $method
* @param array|null $params
* @return AbstractControllerTestCase
*/
public function url($url, $method = HttpRequest::METHOD_GET, $params = array())
{
$request = $this->getRequest();
if ($this->useConsoleRequest) {
preg_match_all('/(--\\S+[= ]"\\S*\\s*\\S*")|(--\\S+=\\S+|--\\S+\\s\\S+|\\S+)/', $url, $matches);
$params = str_replace(array(' "', '"'), array('=', ''), $matches[0]);
$request->params()->exchangeArray($params);
return $this;
}
$query = $request->getQuery()->toArray();
$post = $request->getPost()->toArray();
$uri = new HttpUri($url);
$queryString = $uri->getQuery();
if ($queryString) {
parse_str($queryString, $query);
}
if ($method == HttpRequest::METHOD_POST) {
if (count($params) != 0) {
$post = $params;
}
} elseif ($method == HttpRequest::METHOD_GET) {
$query = array_merge($query, $params);
} elseif ($method == HttpRequest::METHOD_PUT) {
if (count($params) != 0) {
array_walk($params, function (&$item, $key) {
$item = $key . '=' . $item;
});
$content = implode('&', $params);
$request->setContent($content);
}
} elseif ($params) {
trigger_error('Additional params is only supported by GET, POST and PUT HTTP method', E_USER_NOTICE);
}
$request->setMethod($method);
$request->setQuery(new Parameters($query));
$request->setPost(new Parameters($post));
$request->setUri($uri);
$request->setRequestUri($uri->getPath());
return $this;
}
示例9: url
/**
* Set the request URL
*
* @param string $url
* @return AbstractControllerTestCase
*/
public function url($url, $method = HttpRequest::METHOD_GET, $params = array())
{
$request = $this->getRequest();
if ($this->useConsoleRequest) {
$params = preg_split('#\\s+#', $url);
$request->params()->exchangeArray($params);
return $this;
}
$query = $request->getQuery()->toArray();
$post = $request->getPost()->toArray();
$uri = new HttpUri($url);
$queryString = $uri->getQuery();
if ($queryString) {
parse_str($queryString, $query);
}
if ($method == HttpRequest::METHOD_POST) {
$post = $params;
}
if ($method == HttpRequest::METHOD_GET) {
$query = array_merge($query, $params);
}
$request->setMethod($method);
$request->setQuery(new Parameters($query));
$request->setPost(new Parameters($post));
$request->setUri($uri);
return $this;
}