當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Headers::createFromEnvironment方法代碼示例

本文整理匯總了PHP中Slim\Http\Headers::createFromEnvironment方法的典型用法代碼示例。如果您正苦於以下問題:PHP Headers::createFromEnvironment方法的具體用法?PHP Headers::createFromEnvironment怎麽用?PHP Headers::createFromEnvironment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\Http\Headers的用法示例。


在下文中一共展示了Headers::createFromEnvironment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: dispatch

 protected function dispatch($path, $method = 'GET', $data = array(), $cookies = array())
 {
     $container = $this->app->getContainer();
     // seperate the path from the query string so we can set in the environment
     @(list($path, $queryString) = explode('?', $path));
     // Prepare a mock environment
     $env = Environment::mock(array('REQUEST_URI' => $path, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => is_null($queryString) ? '' : $queryString));
     // Prepare request and response objects
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // create request, and set params
     $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     if (!empty($data)) {
         $req = $req->withParsedBody($data);
     }
     $res = new $container['response']();
     // // Fix for body, but breaks POST params in tests - http://stackoverflow.com/questions/34823328/response-getbody-is-empty-when-testing-slim-3-routes-with-phpunit
     // $body = new RequestBody();
     // if (!empty($data))
     //    $body->write(json_encode($data));
     //
     // // create request, and set params
     // $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     // $res = new $container['response']();
     $this->headers = $headers;
     $this->request = $req;
     $this->response = call_user_func_array($this->app, array($req, $res));
 }
開發者ID:martynbiz,項目名稱:slim3-controller,代碼行數:31,代碼來源:TestCase.php

示例2: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     //Make method uppercase
     $method = strtoupper($method);
     $options = array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path);
     if ($method === 'GET') {
         $options['QUERY_STRING'] = http_build_query($data);
     } else {
         $params = json_encode($data);
     }
     // Prepare a mock environment
     $env = Environment::mock(array_merge($options, $optionalHeaders));
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $this->cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // Attach JSON request
     if (isset($params)) {
         $headers->set('Content-Type', 'application/json;charset=utf8');
         $body->write($params);
     }
     $this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     $response = new Response();
     // Invoke request
     $app = $this->app;
     $this->response = $app($this->request, $response);
     // Return the application output.
     return (string) $this->response->getBody();
 }
開發者ID:there4,項目名稱:slim-test-helpers,代碼行數:30,代碼來源:WebTestClient.php

示例3: testCreateFromEnvironmentIgnoresHeaders

 public function testCreateFromEnvironmentIgnoresHeaders()
 {
     $e = Environment::mock(['CONTENT_TYPE' => 'text/csv', 'HTTP_CONTENT_LENGTH' => 1230]);
     $h = Headers::createFromEnvironment($e);
     $prop = new ReflectionProperty($h, 'data');
     $prop->setAccessible(true);
     $this->assertNotContains('content-length', $prop->getValue($h));
 }
開發者ID:hidayat365,項目名稱:phpindonesia.or.id-membership2,代碼行數:8,代碼來源:HeadersTest.php

示例4: createRequest

 protected function createRequest($env)
 {
     $method = $env["REQUEST_METHOD"];
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = Cookies::parseHeader($headers->get("Cookie", []));
     $serverParams = $env->all();
     $body = new Body(fopen("php://input", "r"));
     return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 }
開發者ID:zither,項目名稱:memo,代碼行數:10,代碼來源:RouterTest.php

示例5: createRequest

 protected function createRequest()
 {
     $env = (new Environment())->mock(["PATH_INFO" => "/index/hello/", "SCRIPT_NAME" => "/index.php"]);
     $method = $env["REQUEST_METHOD"];
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = Cookies::parseHeader($headers->get("Cookie", []));
     $serverParams = $env->all();
     $body = new Body(fopen("php://input", "r"));
     return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 }
開發者ID:zither,項目名稱:memo,代碼行數:11,代碼來源:ControllerTest.php

示例6: requestFactory

 public function requestFactory($acceptType = 'application/json')
 {
     $env = Environment::mock(['HTTP_ACCEPT' => $acceptType]);
     $uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
     $headers = Headers::createFromEnvironment($env);
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request('GET', $uri, $headers, [], $serverParams, $body, $uploadedFiles);
     return $request;
 }
開發者ID:slimphp-api,項目名稱:slim-json,代碼行數:11,代碼來源:JsonTest.php

示例7: makeRequest

 /**
  * @param $method
  * @param string $url
  *
  * @return Request
  */
 public function makeRequest($method, $url = '/')
 {
     $env = Environment::mock();
     $uri = Uri::createFromString('http://example.com' . $url);
     $headers = Headers::createFromEnvironment($env);
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request($method, $uri, $headers, [], $serverParams, $body, $uploadedFiles);
     return $request;
 }
開發者ID:ChrisBrenton,項目名稱:recipes,代碼行數:17,代碼來源:RequestFactory.php

示例8: setRequest

 public function setRequest($method = 'GET', $uri = '/', $other = [])
 {
     // Prepare request and response objects
     $base = ['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => $uri, 'REQUEST_METHOD' => $method];
     $env = \Slim\Http\Environment::mock(array_merge($base, $other));
     $uri = \Slim\Http\Uri::createFromEnvironment($env);
     $headers = \Slim\Http\Headers::createFromEnvironment($env);
     $cookies = (array) new \Slim\Collection();
     $serverParams = (array) new \Slim\Collection($env->all());
     $body = new \Slim\Http\Body(fopen('php://temp', 'r+'));
     return new \Slim\Http\Request('GET', $uri, $headers, $cookies, $serverParams, $body);
 }
開發者ID:usf-it,項目名稱:slim-skeleton,代碼行數:12,代碼來源:HomeActionTest.php

示例9: requestFactory

 public function requestFactory($queryString = '')
 {
     $env = Environment::mock();
     $uri = Uri::createFromString('https://example.com:443/foo/bar' . $queryString);
     $headers = Headers::createFromEnvironment($env);
     $cookies = ['user' => 'john', 'id' => '123'];
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
     return $request;
 }
開發者ID:geggleto,項目名稱:sessionmiddleware,代碼行數:12,代碼來源:SessionMiddlewareTest.php

示例10: requestFactory

 public function requestFactory($uri = '/')
 {
     // Prepare request and response objects
     $env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET']);
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = [];
     $serverParams = $env->all();
     $body = new Body(fopen('php://temp', 'r+'));
     $req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     return $req;
 }
開發者ID:geggleto,項目名稱:Collective,代碼行數:12,代碼來源:CollectiveTest.php

示例11: makeRequest

 /**
  * @param string $method
  * @param string $uri
  * @return Request
  */
 public function makeRequest($method = 'GET', $uri = '')
 {
     $env = Environment::mock([]);
     $uri = Uri::createFromString($uri);
     $headers = Headers::createFromEnvironment($env);
     $cookies = [];
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
     $request = $request->withHeader("Content-Type", "application/x-www-form-urlencoded");
     return $request;
 }
開發者ID:geggleto,項目名稱:slimgateway,代碼行數:18,代碼來源:RequestFactory.php

示例12: request

 public function request($method, $path, $options = array())
 {
     $env = Environment::mock(array_merge(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => $path, 'REQUEST_METHOD' => $method], $options));
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = [];
     $serverParams = $env->all();
     $body = new RequestBody();
     $req = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     $res = new Response();
     $app = (require ROOT_DIR . '/bootstrap/bootstrap.php');
     $app($req, $res);
     return $app($req, $res);
 }
開發者ID:takkyuuplayer,項目名稱:hackyou,代碼行數:14,代碼來源:csrf01Test.php

示例13: setupRequest

 public function setupRequest($url, $method, $request, $files)
 {
     $env = Environment::mock(['REQUEST_URI' => $url, 'REQUEST_METHOD' => $method, 'HTTP_CONTENT_TYPE' => 'multipart/form-data; boundary=---foo']);
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $files = UploadedFile::createFromEnvironment(Environment::mock());
     $cookies = [];
     $serverParams = $env->all();
     $body = new RequestBody();
     $this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, $files);
     $this->response = new Response();
     $app = $this->app;
     return $app($this->request, $this->response);
 }
開發者ID:raistlfiren,項目名稱:slim-skeleton,代碼行數:14,代碼來源:AbstractTestFunctional.php

示例14: prepareRequest

 private function prepareRequest($method, $url, array $requestParameters)
 {
     $env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => $url, 'REQUEST_METHOD' => $method]);
     $parts = explode('?', $url);
     if (isset($parts[1])) {
         $env['QUERY_STRING'] = $parts[1];
     }
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = [];
     $serverParams = $env->all();
     $body = new RequestBody();
     $body->write(json_encode($requestParameters));
     $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     return $request->withHeader('Content-Type', 'application/json');
 }
開發者ID:lzakrzewski,項目名稱:slim-integration-testing-example,代碼行數:16,代碼來源:ApiTestCase.php

示例15: fromGlobals

 public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
 {
     $environment = new Environment($server);
     $method = $environment['REQUEST_METHOD'];
     $uri = Uri::createFromEnvironment($environment);
     $headers = Headers::createFromEnvironment($environment);
     $cookies = Cookies::parseHeader($headers->get('Cookie', []));
     $serverParams = $environment->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($environment);
     $request = new ServerRequest($method, $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
     if ($method === 'POST' && in_array($request->getMediaType(), ['application/x-www-form-urlencoded', 'multipart/form-data'])) {
         // parsed body must be $_POST
         $request = $request->withParsedBody($_POST);
     }
     return $request;
 }
開發者ID:mkorkmaz,項目名稱:selami,代碼行數:17,代碼來源:ServerRequestFactory.php


注:本文中的Slim\Http\Headers::createFromEnvironment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。