Skip to content

Commit

Permalink
Create Environment.php
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere authored May 27, 2018
1 parent 8267873 commit babb8af
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Component/Environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Created by PhpStorm.
* User: Inhere
* Date: 2015/2/27
* Use : ...
* File: Environment.php
*/

namespace Inhere\Http\Component;

/**
* mock 环境信息
* Class Environment
* @package Inhere\Http\Component
*/
class Environment extends Collection
{
/**
* Create mock environment
* @param array $userData Array of custom environment keys and values
* @return self
*/
public static function mock(array $userData = []): self
{
$data = \array_merge([
'SERVER_PROTOCOL' => 'HTTP/1.1',
'REQUEST_METHOD' => 'GET',
'SCRIPT_NAME' => '',
'REQUEST_URI' => '',
'QUERY_STRING' => '',
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'HTTP_HOST' => 'localhost',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
'HTTP_ACCEPT_CHARSET' => 'utf-8;q=0.7,*;q=0.3',
'HTTP_USER_AGENT' => 'Slim Framework',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_TIME' => \time(),
'REQUEST_TIME_FLOAT' => \microtime(true),
], $userData);

return new static($data);
}
}

0 comments on commit babb8af

Please sign in to comment.