本文整理汇总了PHP中Symfony\Component\BrowserKit\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 = strtoupper($request->getMethod());
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;
}
示例2: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();
$_REQUEST = $request->getParameters();
$_POST = $_GET = array();
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $request->getParameters();
} else {
$_POST = $request->getParameters();
}
$uri = $request->getUri();
$pathString = parse_url($uri, PHP_URL_PATH);
$queryString = parse_url($uri, PHP_URL_QUERY);
$_SERVER['REQUEST_URI'] = $queryString === null ? $pathString : $pathString . '?' . $queryString;
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
parse_str($queryString, $params);
foreach ($params as $k => $v) {
$_GET[$k] = $v;
}
$app = $this->startApp();
$app->getResponse()->on(YiiResponse::EVENT_AFTER_PREPARE, array($this, 'processResponse'));
$this->headers = array();
$this->statusCode = null;
ob_start();
$app->handleRequest($app->getRequest())->send();
$content = ob_get_clean();
// catch "location" header and display it in debug, otherwise it would be handled
// by symfony browser-kit and not displayed.
if (isset($this->headers['location'])) {
Debug::debug("[Headers] " . json_encode($this->headers));
}
return new Response($content, $this->statusCode, $this->headers);
}
示例3: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$this->_headers = array();
$_COOKIE = array_merge($_COOKIE, $request->getCookies());
$_SERVER = array_merge($_SERVER, $request->getServer());
$_FILES = $this->remapFiles($request->getFiles());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
// Parse url parts
$uriPath = trim(parse_url($request->getUri(), PHP_URL_PATH), '/');
$uriQuery = ltrim(parse_url($request->getUri(), PHP_URL_QUERY), '?');
$scriptName = trim(parse_url($this->url, PHP_URL_PATH), '/');
if (!empty($uriQuery)) {
$uriPath .= "?{$uriQuery}";
parse_str($uriQuery, $params);
foreach ($params as $k => $v) {
$_GET[$k] = $v;
}
}
// Add script name to request if none
if (strpos($uriPath, $scriptName) === false) {
$uriPath = "/{$scriptName}/{$uriPath}";
}
// Add forward slash if not exists
if (strpos($uriPath, '/') !== 0) {
$uriPath = "/{$uriPath}";
}
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uriPath;
/**
* Hack to be sure that CHttpRequest will resolve route correctly
*/
$_SERVER['SCRIPT_NAME'] = "/{$scriptName}";
$_SERVER['SCRIPT_FILENAME'] = $this->appPath;
ob_start();
Yii::setApplication(null);
Yii::createApplication($this->appSettings['class'], $this->appSettings['config']);
// disabling logging. Logs slow down test execution
if (Yii::app()->hasComponent('log')) {
foreach (Yii::app()->getComponent('log')->routes as $route) {
$route->enabled = false;
}
}
Yii::app()->onEndRequest->add(array($this, 'setHeaders'));
Yii::app()->run();
$content = ob_get_clean();
$headers = $this->getHeaders();
$statusCode = 200;
foreach ($headers as $header => $val) {
if ($header == 'Location') {
$statusCode = 302;
}
}
$response = new Response($content, $statusCode, $this->getHeaders());
return $response;
}
示例4: doRequest
/**
* @param Request $request
*
* @return Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();
$_SERVER['REQUEST_METHOD'] = $method = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
if ($method === 'HEAD' || $method === 'GET') {
$_GET = $request->getParameters();
$_POST = [];
} else {
$_GET = [];
$_POST = $request->getParameters();
}
$container = call_user_func($this->containerAccessor);
$httpRequest = $container->getByType(IRequest::class);
$httpResponse = $container->getByType(IResponse::class);
if (!$httpRequest instanceof HttpRequest || !$httpResponse instanceof HttpResponse) {
throw new Exception('Arachne\\Codeception\\DI\\HttpExtension is not used or conflicts with another extension.');
}
$httpRequest->reset();
$httpResponse->reset();
try {
ob_start();
$container->getByType(Application::class)->run();
$content = ob_get_clean();
} catch (Exception $e) {
ob_end_clean();
throw $e;
}
$code = $httpResponse->getCode();
$headers = $httpResponse->getHeaders();
return new Response($content, $code, $headers);
}
示例5: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $this->remapFiles($request->getFiles());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
$_POST = $_GET = [];
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
$uri = $request->getUri();
$pathString = parse_url($uri, PHP_URL_PATH);
$queryString = parse_url($uri, PHP_URL_QUERY);
$_SERVER['REQUEST_URI'] = $queryString === null ? $pathString : $pathString . '?' . $queryString;
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
parse_str($queryString, $params);
foreach ($params as $k => $v) {
$_GET[$k] = $v;
}
$app = $this->startApp();
$app->getResponse()->on(YiiResponse::EVENT_AFTER_PREPARE, [$this, 'processResponse']);
// disabling logging. Logs are slowing test execution down
foreach ($app->log->targets as $target) {
$target->enabled = false;
}
$this->headers = array();
$this->statusCode = null;
ob_start();
$yiiRequest = $app->getRequest();
$yiiRequest->setRawBody($request->getContent());
try {
$app->handleRequest($yiiRequest)->send();
} catch (\Exception $e) {
if ($e instanceof HttpException) {
// we shouldn't discard existing output as PHPUnit preform output level verification since PHPUnit 4.2.
$app->errorHandler->discardExistingOutput = false;
$app->errorHandler->handleException($e);
} elseif ($e instanceof ExitException) {
// nothing to do
} else {
// for exceptions not related to Http, we pass them to Codeception
throw $e;
}
}
$content = ob_get_clean();
// catch "location" header and display it in debug, otherwise it would be handled
// by symfony browser-kit and not displayed.
if (isset($this->headers['location'])) {
Debug::debug("[Headers] " . json_encode($this->headers));
}
return new Response($content, $this->statusCode, $this->headers);
}
示例6: filterRequest
protected function filterRequest(Request $request)
{
$server = $request->getServer();
$uri = Url::factory($request->getUri());
$server['HTTP_HOST'] = $uri->getHost();
$port = $uri->getPort();
if ($port !== null && $port !== 443 && $port != 80) {
$server['HTTP_HOST'] .= ':' . $port;
}
return new Request($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getFiles(), $request->getCookies(), $server, $request->getContent());
}
示例7: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$application = $this->getApplication();
$di = $application->getDI();
DI::reset();
DI::setDefault($di);
$_SERVER = array();
foreach ($request->getServer() as $key => $value) {
$_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
}
if (!$application instanceof \Phalcon\MVC\Application && !$application instanceof \Phalcon\MVC\Micro) {
throw new \Exception('Unsupported application class');
}
$_COOKIE = $request->getCookies();
$_FILES = $this->remapFiles($request->getFiles());
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $_REQUEST;
} else {
$_POST = $_REQUEST;
}
$uri = str_replace('http://localhost', '', $request->getUri());
$_SERVER['REQUEST_URI'] = $uri;
$_GET['_url'] = strtok($uri, '?');
$_SERVER['QUERY_STRING'] = http_build_query($_GET);
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$di['request'] = Stub::construct($di->get('request'), [], array('getRawBody' => $request->getContent()));
$response = $application->handle();
$headers = $response->getHeaders();
$status = (int) $headers->get('Status');
$headersProperty = new \ReflectionProperty($headers, '_headers');
$headersProperty->setAccessible(true);
$headers = $headersProperty->getValue($headers);
if (!is_array($headers)) {
$headers = array();
}
$cookiesProperty = new \ReflectionProperty($di['cookies'], '_cookies');
$cookiesProperty->setAccessible(true);
$cookies = $cookiesProperty->getValue($di['cookies']);
if (is_array($cookies)) {
$restoredProperty = new \ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
$restoredProperty->setAccessible(true);
$valueProperty = new \ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
$valueProperty->setAccessible(true);
foreach ($cookies as $name => $cookie) {
if (!$restoredProperty->getValue($cookie)) {
$clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
$headers['Set-Cookie'][] = (string) $clientCookie;
}
}
}
return new Response($response->getContent(), $status ? $status : 200, $headers);
}
示例8: extractHeaders
private function extractHeaders(BrowserKitRequest $request)
{
$headers = [];
$server = $request->getServer();
$contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true);
foreach ($server as $header => $val) {
$header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header)))));
if (strpos($header, 'Http-') === 0) {
$headers[substr($header, 5)] = $val;
} elseif (isset($contentHeaders[$header])) {
$headers[$header] = $val;
}
}
return $headers;
}
示例9: filterRequest
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @param DomRequest $request A DomRequest instance
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) {
$httpRequest->files->set($key, $value);
}
return $httpRequest;
}
示例10: doRequest
/**
*
* @param \Symfony\Component\BrowserKit\Request $request
* @return \Symfony\Component\BrowserKit\Response
*/
public function doRequest($request)
{
$_COOKIE = $request->getCookies();
$_SERVER = $request->getServer();
$_FILES = $request->getFiles();
$_REQUEST = $request->getParameters();
if (strtoupper($request->getMethod()) == 'GET') {
$_GET = $request->getParameters();
} else {
$_POST = $request->getParameters();
}
$uri = str_replace('http://localhost', '', $request->getUri());
$scriptName = str_replace('http://localhost', '', $this->url);
$queryString = parse_url($uri, PHP_URL_QUERY);
parse_str($queryString, $params);
if (strpos($uri, $scriptName) === false) {
$uri = $scriptName . $queryString;
}
foreach ($params as $k => $v) {
$_GET[$k] = $v;
}
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_SERVER['REQUEST_URI'] = $uri;
$_SERVER['SCRIPT_NAME'] = $scriptName;
$_SERVER['SCRIPT_FILENAME'] = $this->entryScript;
$_SERVER['PHP_SELF'] = $this->entryScript;
$config = (require $this->entryScript);
/** @var \yii\web\Application $app */
$app = Yii::createObject($config);
$client = $this;
$app->getResponse()->on(YiiResponse::EVENT_AFTER_PREPARE, function ($event) use($client) {
/** @var \yii\web\Response $sender */
$sender = $event->sender;
$this->headers = $sender->getHeaders()->toArray();
$sender->getHeaders()->removeAll();
$this->statusCode = $sender->getStatusCode();
$_POST = array();
$sender->setStatusCode(null);
});
$this->headers = array();
$this->statusCode = null;
ob_start();
$app->handleRequest($app->getRequest())->send();
$content = ob_get_clean();
return new Response($content, $this->statusCode === null ? 200 : $this->statusCode, $this->headers);
}
示例11: filterRequest
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @param Request $request A Request instance
*
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request)
{
$uri = $request->getUri();
if (preg_match('#^https?\\://([^/]+)/(.*)$#', $uri, $matches)) {
$uri = '/' . $matches[2];
}
return Request::create($uri, $request->getMethod(), $request->getParameters(), $request->getFiles(), $request->getCookies(), $request->getServer());
}
示例12: doRequest
/**
* @param Request $request
*
* @return Response
*/
protected function doRequest($request)
{
$headers = array();
foreach ($request->getServer() as $key => $val) {
$key = strtolower(str_replace('_', '-', $key));
$contentHeaders = array('content-length' => true, 'content-md5' => true, 'content-type' => true);
if (0 === strpos($key, 'http-')) {
$headers[substr($key, 5)] = $val;
} elseif (isset($contentHeaders[$key])) {
$headers[$key] = $val;
}
}
$cookies = CookieJar::fromArray($this->getCookieJar()->allRawValues($request->getUri()), parse_url($request->getUri(), PHP_URL_HOST));
$requestOptions = array('cookies' => $cookies, 'allow_redirects' => false, 'auth' => $this->auth);
if (!in_array($request->getMethod(), array('GET', 'HEAD'))) {
if (null !== ($content = $request->getContent())) {
$requestOptions['body'] = $content;
} else {
if ($files = $request->getFiles()) {
$requestOptions['multipart'] = [];
$this->addPostFields($request->getParameters(), $requestOptions['multipart']);
$this->addPostFiles($files, $requestOptions['multipart']);
} else {
$requestOptions['form_params'] = $request->getParameters();
}
}
}
if (!empty($headers)) {
$requestOptions['headers'] = $headers;
}
$method = $request->getMethod();
$uri = $request->getUri();
foreach ($this->headers as $name => $value) {
$requestOptions['headers'][$name] = $value;
}
// Let BrowserKit handle redirects
try {
$response = $this->getClient()->request($method, $uri, $requestOptions);
} catch (RequestException $e) {
$response = $e->getResponse();
if (null === $response) {
throw $e;
}
}
return $this->createResponse($response);
}
示例13: filterRequest
/**
* Converts the BrowserKit request to a HttpKernel request.
*
* @param DomRequest $request A Request instance
*
* @return Request A Request instance
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
/** this happens so we can send oauth2 tokens in the header */
if (isset($this->server['HTTP_AUTHORIZATION'])) {
$httpRequest->headers->add(array('HTTP_AUTHORIZATION' => $this->server['HTTP_AUTHORIZATION']));
}
$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
return $httpRequest;
}
示例14: createClient
protected function createClient(Request $request)
{
$client = $this->createZendClient();
$client->setUri($request->getUri());
$client->setConfig(array_merge(array('maxredirects' => 0, 'timeout' => 30, 'useragent' => $this->server['HTTP_USER_AGENT'], 'adapter' => 'Zend\\Http\\Client\\Adapter\\Socket'), $this->zendConfig));
$client->setMethod(strtoupper($request->getMethod()));
if ('POST' == $request->getMethod()) {
$client->setParameterPost($request->getParameters());
}
$client->setHeaders($this->headers);
if ($this->auth !== null) {
$client->setAuth($this->auth['user'], $this->auth['password'], $this->auth['type']);
}
foreach ($this->getCookieJar()->allValues($request->getUri()) as $name => $value) {
$client->addCookie($name, $value);
}
foreach ($request->getFiles() as $name => $info) {
if (isset($info['tmp_name']) && '' !== $info['tmp_name']) {
$filename = $info['name'];
if (false === ($data = @file_get_contents($info['tmp_name']))) {
throw new \RuntimeException("Unable to read file '{$filename}' for upload");
}
$client->setFileUpload($filename, $name, $data);
}
}
return $client;
}
示例15: extractHeaders
private function extractHeaders(BrowserKitRequest $request)
{
$headers = [];
$server = $request->getServer();
$uri = new Uri($request->getUri());
$server['HTTP_HOST'] = $uri->getHost();
$port = $uri->getPort();
if ($port !== null && $port !== 443 && $port != 80) {
$server['HTTP_HOST'] .= ':' . $port;
}
$contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true);
foreach ($server as $header => $val) {
$header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header)))));
if (strpos($header, 'Http-') === 0) {
$headers[substr($header, 5)] = $val;
} elseif (isset($contentHeaders[$header])) {
$headers[$header] = $val;
}
}
return $headers;
}