当前位置: 首页>>代码示例>>PHP>>正文


PHP Http\Headers类代码示例

本文整理汇总了PHP中Slim\Http\Headers的典型用法代码示例。如果您正苦于以下问题:PHP Headers类的具体用法?PHP Headers怎么用?PHP Headers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Headers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testWritePlain

 public function testWritePlain()
 {
     $this->_jsonTestOutputWriter->expects($this->exactly(1))->method('_jsonEncode')->with($this->equalTo(array('mockKey' => 'mockValue')))->will($this->returnValue('{"mockKey": "mockValue"}'));
     $this->_mockHeaders->expects($this->exactly(1))->method('set')->with($this->equalTo('Content-Type'), $this->equalTo('application/json; charset=UTF-8'));
     $this->_mockResponse->expects($this->exactly(1))->method('setStatus')->with($this->equalTo(200));
     $this->_mockResponse->expects($this->exactly(1))->method('setBody')->with($this->equalTo('{"mockKey": "mockValue"}'));
     $this->_jsonTestOutputWriter->writePlain(array('mockKey' => 'mockValue'));
 }
开发者ID:bigpoint,项目名称:slim-bootstrap,代码行数:8,代码来源:JsonTest.php

示例2: testWriteArray

 /**
  * @param $data
  *
  * @dataProvider normalizeAllDataProvider
  */
 public function testWriteArray($data)
 {
     $localCsvTestOutputWriter = $this->getMock('\\SlimBootstrap\\ResponseOutputWriter\\Csv', array('_csvEncode'), array($this->_mockRequest, $this->_mockResponse, $this->_mockHeaders, 'mockShortName'));
     $this->_mockHeaders->expects($this->once())->method('set')->with($this->identicalTo("Content-Type"), $this->identicalTo("text/csv; charset=UTF-8"));
     $this->_mockResponse->expects($this->once())->method('setStatus')->with($this->equalTo(200));
     $localCsvTestOutputWriter->expects($this->once())->method('_csvEncode');
     $this->_mockResponse->expects($this->once())->method('setBody');
     $localCsvTestOutputWriter->write($data, 200);
 }
开发者ID:bigpoint,项目名称:slim-bootstrap,代码行数:14,代码来源:CsvTest.php

示例3: setUp

 /**
  * Run before each test.
  */
 public function setUp()
 {
     $uri = Uri::createFromString('https://example.com:443/foo/bar');
     $headers = new Headers();
     $headers->set('REMOTE_ADDR', '127.0.0.1');
     $cookies = [];
     $env = Environment::mock();
     $serverParams = $env->all();
     $body = new Body(fopen('php://temp', 'r+'));
     $this->request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new Response();
 }
开发者ID:davidepastore,项目名称:slim-restrict-route,代码行数:15,代码来源:RestrictRouteTest.php

示例4: setUpXmlPost

 /**
  * Setup for the XML POST requests.
  *
  * @param string $xml The XML to use to mock the body of the request.
  */
 public function setUpXmlPost($xml)
 {
     $uri = Uri::createFromString('https://example.com:443/foo');
     $headers = new Headers();
     $headers->set('Content-Type', 'application/xml;charset=utf8');
     $cookies = [];
     $env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'POST']);
     $serverParams = $env->all();
     $body = new RequestBody();
     $body->write($xml);
     $this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new Response();
 }
开发者ID:DavidePastore,项目名称:Slim-Validation,代码行数:18,代码来源:ValidationTest.php

示例5: 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

示例6: 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

示例7: __construct

 /**
  * Constructor (private access)
  *
  * @param  array|null $settings If present, these are used instead of global server variables
  */
 private function __construct($settings = null)
 {
     if ($settings) {
         $this->properties = $settings;
     } else {
         $env = array();
         //The HTTP request method
         $env['REQUEST_METHOD'] = $_SERVER['REQUEST_METHOD'];
         //The IP
         $env['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
         // Server params
         $scriptName = $_SERVER['SCRIPT_NAME'];
         // <-- "/foo/index.php"
         $requestUri = $_SERVER['REQUEST_URI'];
         // <-- "/foo/bar?test=abc" or "/foo/index.php/bar?test=abc"
         $queryString = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
         // <-- "test=abc" or ""
         // Physical path
         if (strpos($requestUri, $scriptName) !== false) {
             $physicalPath = $scriptName;
             // <-- Without rewriting
         } else {
             $physicalPath = str_replace('\\', '', dirname($scriptName));
             // <-- With rewriting
         }
         $env['SCRIPT_NAME'] = rtrim($physicalPath, '/');
         // <-- Remove trailing slashes
         $env['PATH_INFO'] = !empty($requestUri) && !empty($physicalPath) && strpos($requestUri, $physicalPath) === 0 ? substr_replace($requestUri, '', 0, strlen($physicalPath)) : $requestUri;
         // <-- Remove physical path
         $env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']);
         // <-- Remove query string
         $env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/');
         // <-- Ensure leading slash
         // Query string (without leading "?")
         $env['QUERY_STRING'] = $queryString;
         //Name of server host that is running the script
         $env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
         //Number of server port that is running the script
         $env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
         //HTTP request headers (retains HTTP_ prefix to match $_SERVER)
         $headers = \Slim\Http\Headers::extract($_SERVER);
         foreach ($headers as $key => $value) {
             $env[$key] = $value;
         }
         //Is the application running under HTTPS or HTTP protocol?
         $env['slim.url_scheme'] = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
         //Input stream (readable one time only; not available for multipart/form-data requests)
         $rawInput = @file_get_contents('php://input');
         if (!$rawInput) {
             $rawInput = '';
         }
         $env['slim.input'] = $rawInput;
         //Error stream
         $env['slim.errors'] = @fopen('php://stderr', 'w');
         //             print_r($env); die;
         $this->properties = $env;
     }
 }
开发者ID:konstantin-pr,项目名称:Ses,代码行数:63,代码来源:Environment.php

示例8: 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

示例9: createFromReactRequest

 /**
  * Creates a new request object from the data of a reactPHP request object
  *
  * @param \React\Http\Request $request ReactPHP native request object
  *
  * @return \Slim\Http\Request
  */
 public static function createFromReactRequest(\React\Http\Request $request)
 {
     $slimHeads = new Headers();
     foreach ($request->getHeaders() as $reactHeadKey => $reactHead) {
         $slimHeads->add($reactHeadKey, $reactHead);
         if ($reactHeadKey === 'Host') {
             $host = explode(':', $reactHead);
             if (count($host) === 1) {
                 $host[1] = '80';
             }
         }
     }
     $slimUri = new Uri('http', $host[0], (int) $host[1], $request->getPath(), $request->getQuery());
     $cookies = [];
     $serverParams = $_SERVER;
     $serverParams['SERVER_PROTOCOL'] = 'HTTP/' . $request->getHttpVersion();
     $slimBody = new RequestBody();
     return new self($request->getMethod(), $slimUri, $slimHeads, $cookies, $serverParams, $slimBody);
 }
开发者ID:mbarquin,项目名称:reactphp-slim,代码行数:26,代码来源:Request.php

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


注:本文中的Slim\Http\Headers类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。