本文整理汇总了PHP中Symfony\Component\BrowserKit\Request::getCookies方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getCookies方法的具体用法?PHP Request::getCookies怎么用?PHP Request::getCookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\BrowserKit\Request
的用法示例。
在下文中一共展示了Request::getCookies方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例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 \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);
}
示例5: 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;
}
示例6: 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->getApplication();
$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());
$yiiRequest->setBodyParams($_POST);
$yiiRequest->setQueryParams($_GET);
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
$this->resetApplication();
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));
}
$this->resetApplication();
return new Response($content, $this->statusCode, $this->headers);
}
示例7: 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;
}
示例8: filterRequest
/**
* Filters the BrowserKit request to the cake one.
*
* @param \Symfony\Component\BrowserKit\Request $request BrowserKit request.
* @return \Cake\Network\Request Cake request.
*/
protected function filterRequest(\Symfony\Component\BrowserKit\Request $request)
{
$url = preg_replace('/^https?:\\/\\/[a-z0-9\\-\\.]+/', '', $request->getUri());
$_ENV = $environment = ['REQUEST_METHOD' => $request->getMethod()] + $request->getServer();
$props = ['url' => $url, 'post' => (array) $request->getParameters(), 'files' => (array) $request->getFiles(), 'cookies' => (array) $request->getCookies(), 'session' => $this->getSession(), 'environment' => $environment];
$this->cake['request'] = new Request($props);
// set params
Router::setRequestInfo($this->cake['request']);
$this->cake['request']->params = Router::parse($url);
return $this->cake['request'];
}
示例9: 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());
}
示例10: doRequest
/**
* Makes a request.
*
* @param \Symfony\Component\BrowserKit\Request $request
*
* @return \Symfony\Component\BrowserKit\Response
* @throws \RuntimeException
*/
public function doRequest($request)
{
$application = $this->getApplication();
$di = $application->getDI();
Di::reset();
Di::setDefault($di);
$_SERVER = [];
foreach ($request->getServer() as $key => $value) {
$_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
}
if (!$application instanceof Application && !$application instanceof MicroApplication) {
throw new RuntimeException('Unsupported application class.');
}
$_COOKIE = $request->getCookies();
$_FILES = $this->remapFiles($request->getFiles());
$_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
$_REQUEST = $this->remapRequestParameters($request->getParameters());
if ($_SERVER['REQUEST_METHOD'] == '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'), [], ['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 = [];
}
$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);
}
示例11: createClient
protected function createClient(Request $request)
{
// create new request without content body
$client = parent::createClient(new Request($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getFiles(), $request->getCookies(), $request->getServer()));
// add server variables
$headers = $this->headers;
foreach ($request->getServer() as $key => $val) {
$key = ucfirst(strtolower(str_replace(array('_', 'HTTP-'), array('-', ''), $key)));
if (!isset($headers[$key])) {
$headers[$key] = $val;
}
}
$client->setHeaders($headers);
return $client;
}
示例12: 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);
}
示例13: doRequestInProcess
/**
* @param Request $request
* @return Response
*/
public function doRequestInProcess($request)
{
if ($this->mockedResponse) {
$response = $this->mockedResponse;
$this->mockedResponse = null;
return $response;
}
$requestCookie = $request->getCookies();
$requestServer = $request->getServer();
$requestFiles = $this->remapFiles($request->getFiles());
$parseResult = parse_url($request->getUri());
$uri = $parseResult["path"];
if (array_key_exists("query", $parseResult)) {
$uri .= "?" . $parseResult["query"];
}
$requestRequestArray = $this->remapRequestParameters($request->getParameters());
$requestServer['REQUEST_METHOD'] = strtoupper($request->getMethod());
$requestServer['REQUEST_URI'] = $uri;
$requestServer['HTTP_HOST'] = $this->domain;
$requestServer['SERVER_PROTOCOL'] = 'HTTP/1.1';
$this->index = $this->uriToIndexMapper->getIndexForUri($uri);
$phpSelf = str_replace($this->rootFolder, '', $this->index);
$requestServer['PHP_SELF'] = $phpSelf;
$env = ['headers' => $this->headers, 'cookie' => $requestCookie, 'server' => $requestServer, 'files' => $requestFiles, 'request' => $requestRequestArray];
if (strtoupper($request->getMethod()) == 'GET') {
$env['get'] = $env['request'];
} else {
$env['post'] = $env['request'];
}
$requestScript = dirname(dirname(__DIR__)) . '/scripts/request.php';
$command = PHP_BINARY . ' ' . escapeshellarg($requestScript) . ' ' . escapeshellarg($this->index) . ' ' . escapeshellarg(base64_encode(serialize($env)));
$process = new Process($command);
$process->run();
$rawProcessOutput = $process->getOutput();
$unserializedResponse = unserialize(base64_decode($rawProcessOutput));
$_SERVER = empty($unserializedResponse['server']) ? [] : $unserializedResponse['server'];
$_FILES = empty($unserializedResponse['files']) ? [] : $unserializedResponse['files'];
$_REQUEST = empty($unserializedResponse['request']) ? [] : $unserializedResponse['request'];
$_GET = empty($unserializedResponse['get']) ? [] : $unserializedResponse['get'];
$_POST = empty($unserializedResponse['post']) ? [] : $unserializedResponse['post'];
$content = $unserializedResponse['content'];
$headers = $this->replaceSiteUrlDeep($unserializedResponse['headers'], $this->url);
$response = new Response($content, $unserializedResponse['status'], $headers);
return $response;
}
示例14: 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;
}
示例15: 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;
}