本文整理汇总了PHP中Zend\Http\Request::getUriString方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUriString方法的具体用法?PHP Request::getUriString怎么用?PHP Request::getUriString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Request
的用法示例。
在下文中一共展示了Request::getUriString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequestCanSetAndRetrieveUri
/**
* @dataProvider uriDataProvider
*/
public function testRequestCanSetAndRetrieveUri($uri)
{
$request = new Request();
$request->setUri($uri);
$this->assertEquals($uri, $request->getUri());
$this->assertInstanceOf('Zend\\Uri\\Uri', $request->getUri());
$this->assertEquals($uri, $request->getUri()->toString());
$this->assertEquals($uri, $request->getUriString());
}
示例2: fromZend
/**
* Convert a Zend\Http\Response in a PSR-7 response, using zend-diactoros
*
* @param ZendRequest $zendRequest
* @return ServerRequest
*/
public static function fromZend(ZendRequest $zendRequest)
{
$body = new Stream('php://memory', 'wb+');
$body->write($zendRequest->getContent());
$headers = empty($zendRequest->getHeaders()) ? [] : $zendRequest->getHeaders()->toArray();
$query = empty($zendRequest->getQuery()) ? [] : $zendRequest->getQuery()->toArray();
$post = empty($zendRequest->getPost()) ? [] : $zendRequest->getPost()->toArray();
$files = empty($zendRequest->getFiles()) ? [] : $zendRequest->getFiles()->toArray();
$request = new ServerRequest([], self::convertFilesToUploaded($files), $zendRequest->getUriString(), $zendRequest->getMethod(), $body, $headers);
$request = $request->withQueryParams($query);
return $request->withParsedBody($post);
}
示例3: execute
protected function execute($url, $method, array $query = null, array $rawdata = null, Headers $headers = null)
{
$request = new Request();
// Headers
$request->getHeaders()->addHeaders(array('Content-Type' => $this->getContentType()));
if ($headers) {
$request->getHeaders()->addHeaders($headers);
}
// Query
if ($query) {
$request->setQuery(new Parameters($query));
}
$request->setUri($url)->setMethod($method);
switch ($method) {
case self::HTTP_VERB_POST:
case self::HTTP_VERB_PUT:
case self::HTTP_VERB_PATCH:
if ($rawdata) {
$request->setPost(new Parameters($rawdata));
}
break;
}
$client = new HttpClient('', $this->_httpClientOptions);
$adapter = $client->getAdapter();
/* @var $adapter Curl */
$secure = $request->getUri()->getScheme() == 'https';
$adapter->connect($request->getUri()->getHost(), $request->getUri()->getPort(), $secure);
$ch = $adapter->getHandle();
// Set URL
curl_setopt($ch, CURLOPT_URL, $request->getUriString() . '?' . $request->getQuery()->toString());
// ensure correct curl call
$curlValue = true;
switch ($method) {
case 'GET':
$curlMethod = CURLOPT_HTTPGET;
break;
case 'POST':
$curlMethod = CURLOPT_POST;
break;
case 'PUT':
case 'PATCH':
case 'DELETE':
case 'OPTIONS':
case 'TRACE':
case 'HEAD':
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = $method;
break;
default:
// For now, through an exception for unsupported request methods
throw new Exception("Method '{$method}' currently not supported");
}
// mark as HTTP request and set HTTP method
curl_setopt($ch, CURL_HTTP_VERSION_1_1, true);
curl_setopt($ch, $curlMethod, $curlValue);
// ensure actual response is returned
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// set callback function
if ($this->getCallbackWriteFunction() instanceof \Closure) {
curl_setopt($ch, CURLOPT_WRITEFUNCTION, $this->getCallbackWriteFunction());
}
// ensure headers are also returned
curl_setopt($ch, CURLOPT_HEADER, false);
// set callback function
if ($this->getCallbackHeaderFunction() instanceof \Closure) {
curl_setopt($ch, CURLOPT_HEADERFUNCTION, $this->getCallbackHeaderFunction());
}
// Treating basic auth headers in a special way
if ($request->getHeaders() instanceof Headers) {
$headersArray = $request->getHeaders()->toArray();
if (array_key_exists('Authorization', $headersArray) && 'Basic' == substr($headersArray['Authorization'], 0, 5)) {
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, base64_decode(substr($headersArray['Authorization'], 6)));
unset($headersArray['Authorization']);
}
// set additional headers
if (!isset($headersArray['Accept'])) {
$headersArray['Accept'] = '';
}
$curlHeaders = array();
foreach ($headersArray as $key => $value) {
$curlHeaders[] = $key . ': ' . $value;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
}
// POST body
switch ($method) {
case 'POST':
case 'PUT':
case 'PATCH':
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getPost()->toArray());
break;
}
$this->_handlers[uniqid()] = $ch;
end($this->_handlers);
return key($this->_handlers);
}
示例4: getAction
/**
* Get REST action
*
* @author Stoyan Rangelov
* @param \Zend\Http\Request $request
* @return string
*/
public function getAction(\Zend\Http\Request $request)
{
if ($request->isGet()) {
$explodedURI = explode('/', $request->getUriString());
$lastElement = end($explodedURI);
if ($lastElement != 0) {
$action = 'get';
} else {
$action = 'getList';
}
} else {
if ($request->isPost()) {
$action = 'create';
} else {
if ($request->isPut()) {
$action = 'update';
} else {
if ($request->isDelete()) {
$action = 'delete';
}
}
}
}
return $action;
}