Skip to content

Commit

Permalink
Merge pull request #1 from inhere/inhere-patch-1
Browse files Browse the repository at this point in the history
Update some
  • Loading branch information
inhere authored May 27, 2018
2 parents d2a3819 + babb8af commit 5078ddd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 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);
}
}
6 changes: 3 additions & 3 deletions src/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ public static function ensureIsCollection($data): Collection
return new Collection($data);
}

if (\is_object($data) && \method_exists($data, 'get')) {
return $data;
}
// if (\is_object($data) && \method_exists($data, 'get')) {
// return $data;
// }

return new Collection((array)$data);
}
Expand Down

0 comments on commit 5078ddd

Please sign in to comment.