本文整理汇总了PHP中Symfony\Component\BrowserKit\Request::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getContent方法的具体用法?PHP Request::getContent怎么用?PHP Request::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\BrowserKit\Request
的用法示例。
在下文中一共展示了Request::getContent方法的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
* @throws \Exception
*/
public function doRequest($request)
{
$inputStream = fopen('php://memory', 'r+');
$content = $request->getContent();
if ($content !== null) {
fwrite($inputStream, $content);
rewind($inputStream);
}
$queryParams = [];
$postParams = [];
$queryString = parse_url($request->getUri(), PHP_URL_QUERY);
if ($queryString != '') {
parse_str($queryString, $queryParams);
}
if ($request->getMethod() !== 'GET') {
$postParams = $request->getParameters();
}
$serverParams = $request->getServer();
if (!isset($serverParams['SCRIPT_NAME'])) {
//required by WhoopsErrorHandler
$serverParams['SCRIPT_NAME'] = 'Codeception';
}
$zendRequest = new ServerRequest($serverParams, $this->convertFiles($request->getFiles()), $request->getUri(), $request->getMethod(), $inputStream, $this->extractHeaders($request));
$zendRequest = $zendRequest->withCookieParams($request->getCookies())->withQueryParams($queryParams)->withParsedBody($postParams);
$cwd = getcwd();
chdir(codecept_root_dir());
$this->application->run($zendRequest);
chdir($cwd);
$this->request = $zendRequest;
$response = $this->responseCollector->getResponse();
$this->responseCollector->clearResponse();
return new Response($response->getBody(), $response->getStatusCode(), $response->getHeaders());
}
示例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: 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;
}
示例5: 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;
}
示例6: 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);
}
示例7: 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);
}
示例8: 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());
}
示例9: 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 ($request->getContent() !== null) {
$client->setRawBody($request->getContent());
}
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);
}
$this->addFileUploadsRecursively($client, $request->getFiles());
return $client;
}
示例10: 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);
}
示例11: 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;
}
示例12: 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;
}
示例13: filterRequest
/**
* Convert a BrowserKit request into a Illuminate request.
*
* @param Symfony\Component\BrowserKit\Request $request
* @return Illuminate\Http\Request
*/
protected function filterRequest(DomRequest $request)
{
$httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent());
$httpRequest->files->replace($this->filterFiles($httpRequest->files->all()));
return $httpRequest;
}
示例14: requestFromRequest
/**
* Makes a request from a Request object directly.
*
* @param Request $request A Request instance
* @param Boolean $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
*
* @return Crawler
*/
protected function requestFromRequest(Request $request, $changeHistory = true)
{
return $this->request($request->getMethod(), $request->getUri(), $request->getParameters(), array(), $request->getFiles(), $request->getServer(), $request->getContent(), $changeHistory);
}
示例15: extractFormData
protected function extractFormData(BrowserKitRequest $request)
{
if (!in_array(strtoupper($request->getMethod()), ['POST', 'PUT', 'PATCH'])) {
return null;
}
// guessing if it is a form data
$headers = $request->getServer();
if (isset($headers['HTTP_CONTENT_TYPE'])) {
// not a form
if ($headers['HTTP_CONTENT_TYPE'] !== 'application/x-www-form-urlencoded') {
return null;
}
}
if ($request->getContent() !== null) {
return null;
}
return $request->getParameters();
}