ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Slim\Http\Environment Class Reference

Environment. More...

+ Inheritance diagram for Slim\Http\Environment:
+ Collaboration diagram for Slim\Http\Environment:

Static Public Member Functions

static mock (array $userData=[])
 Create mock environment. More...
 

Additional Inherited Members

- Public Member Functions inherited from Slim\Collection
 __construct (array $items=[])
 Create new collection. More...
 
 set ($key, $value)
 Set collection item. More...
 
 get ($key, $default=null)
 Get collection item for key. More...
 
 replace (array $items)
 Add item to collection, replacing existing items with the same data key. More...
 
 all ()
 Get all items in collection. More...
 
 keys ()
 Get collection keys. More...
 
 has ($key)
 Does this collection have a given key? More...
 
 remove ($key)
 Remove item from collection. More...
 
 clear ()
 Remove all items from collection. More...
 
 offsetExists ($key)
 Does this collection have a given key? More...
 
 offsetGet ($key)
 Get collection item for key. More...
 
 offsetSet ($key, $value)
 Set collection item. More...
 
 offsetUnset ($key)
 Remove item from collection. More...
 
 count ()
 Get number of items in collection. More...
 
 getIterator ()
 Get collection iterator. More...
 
- Protected Attributes inherited from Slim\Collection
 $data = []
 

Detailed Description

Environment.

This class decouples the Slim application from the global PHP environment. This is particularly useful for unit testing, but it also lets us create custom sub-requests.

Definition at line 21 of file Environment.php.

Member Function Documentation

◆ mock()

static Slim\Http\Environment::mock ( array  $userData = [])
static

Create mock environment.

Parameters
array$userDataArray of custom environment keys and values
Returns
self

Implements Slim\Interfaces\Http\EnvironmentInterface.

Definition at line 30 of file Environment.php.

References Slim\Collection\$data.

31  {
32  //Validates if default protocol is HTTPS to set default port 443
33  if ((isset($userData['HTTPS']) && $userData['HTTPS'] !== 'off') ||
34  ((isset($userData['REQUEST_SCHEME']) && $userData['REQUEST_SCHEME'] === 'https'))) {
35  $defscheme = 'https';
36  $defport = 443;
37  } else {
38  $defscheme = 'http';
39  $defport = 80;
40  }
41 
42  $data = array_merge([
43  'SERVER_PROTOCOL' => 'HTTP/1.1',
44  'REQUEST_METHOD' => 'GET',
45  'REQUEST_SCHEME' => $defscheme,
46  'SCRIPT_NAME' => '',
47  'REQUEST_URI' => '',
48  'QUERY_STRING' => '',
49  'SERVER_NAME' => 'localhost',
50  'SERVER_PORT' => $defport,
51  'HTTP_HOST' => 'localhost',
52  'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
53  'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
54  'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
55  'HTTP_USER_AGENT' => 'Slim Framework',
56  'REMOTE_ADDR' => '127.0.0.1',
57  'REQUEST_TIME' => time(),
58  'REQUEST_TIME_FLOAT' => microtime(true),
59  ], $userData);
60 
61  return new static($data);
62  }

The documentation for this class was generated from the following file: