Skip to content

Commit

Permalink
update: upgrade php version require is 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 4, 2019
1 parent 9834fa5 commit 5baf6d5
Show file tree
Hide file tree
Showing 29 changed files with 341 additions and 312 deletions.
2 changes: 1 addition & 1 deletion src/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PhpComp\Http\Message;

use PhpComp\Http\Message\Component\TempStream;
use PhpComp\Http\Message\Stream\TempStream;

/**
* Body
Expand Down
17 changes: 12 additions & 5 deletions src/Component/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function replace(array $items): void

/**
* @param string $name
* @param null $default
* @param null $default
* @return mixed|null
*/
public function get(string $name, $default = null)
Expand All @@ -64,7 +64,7 @@ public function get(string $name, $default = null)

/**
* @param string $name
* @param mixed $value
* @param mixed $value
* @return mixed|null
*/
public function add($name, $value)
Expand All @@ -80,13 +80,12 @@ public function add($name, $value)

/**
* @param string $name
* @param mixed $value
* @param mixed $value
* @return mixed|null
*/
public function set($name, $value)
{
$this[$name] = $value;

return $this;
}

Expand All @@ -98,6 +97,14 @@ public function all(): array
return $this->getArrayCopy();
}

/**
* @return array
*/
public function toArray(): array
{
return $this->getArrayCopy();
}

/**
* @param string $key
* @return bool
Expand All @@ -111,8 +118,8 @@ public function remove($key)
{
if (isset($this[$key])) {
$val = $this[$key];
unset($this[$key]);

unset($this[$key]);
return $val;
}

Expand Down
28 changes: 14 additions & 14 deletions src/Component/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ class Environment extends Collection
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',
'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' => 'MY Framework',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_TIME' => \time(),
'REQUEST_TIME_FLOAT' => \microtime(true),
'HTTP_ACCEPT_CHARSET' => 'utf-8;q=0.7,*;q=0.3',
'HTTP_USER_AGENT' => 'MY Framework',
'REMOTE_ADDR' => '127.0.0.1',
'REQUEST_TIME' => \time(),
'REQUEST_TIME_FLOAT' => \microtime(true),
], $userData);

return new static($data);
Expand Down
18 changes: 9 additions & 9 deletions src/Cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Cookies extends Collection
* @var array
*/
protected $defaults = [
'value' => '',
'domain' => null,
'value' => '',
'domain' => null,
'hostOnly' => null,
'path' => null,
'expires' => null,
'secure' => false,
'path' => null,
'expires' => null,
'secure' => false,
'httpOnly' => false
];

Expand All @@ -49,7 +49,7 @@ public function setDefaults(array $settings): void

/**
* Set cookie
* @param string $name Cookie name
* @param string $name Cookie name
* @param string|array $value Cookie value, or cookie properties
* @return $this
*/
Expand All @@ -66,7 +66,7 @@ public function set($name, $value): self

/**
* @param string $name
* @param mixed $value
* @param mixed $value
* @return self
*/
public function add($name, $value): self
Expand Down Expand Up @@ -95,7 +95,7 @@ public function toHeaders(): array
/**
* Convert to `Set-Cookie` header
* @param string $name Cookie name
* @param array $properties Cookie properties
* @param array $properties Cookie properties
* @return string
*/
protected function toHeaderLine(string $name, array $properties): string
Expand Down Expand Up @@ -180,7 +180,7 @@ public static function parseFromRawHeader($cookieText): array
$cookie = \explode('=', $cookie, 2);

if (\count($cookie) === 2) {
$key = \urldecode($cookie[0]);
$key = \urldecode($cookie[0]);
$value = \urldecode($cookie[1]);

if (!isset($cookies[$key])) {
Expand Down
35 changes: 17 additions & 18 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ class Headers extends Collection
* @var array
*/
protected static $special = [
'CONTENT_TYPE' => 1,
'CONTENT_LENGTH' => 1,
'PHP_AUTH_USER' => 1,
'PHP_AUTH_PW' => 1,
'CONTENT_TYPE' => 1,
'CONTENT_LENGTH' => 1,
'PHP_AUTH_USER' => 1,
'PHP_AUTH_PW' => 1,
'PHP_AUTH_DIGEST' => 1,
'AUTH_TYPE' => 1,
'AUTH_TYPE' => 1,
];


/**
* Return array of HTTP header names and values.
* This method returns the _original_ header name
Expand All @@ -59,14 +58,14 @@ public function all(): array
* Set HTTP header value
* This method sets a header value. It replaces
* any values that may already exist for the header name.
* @param string $key The case-insensitive header name
* @param string $key The case-insensitive header name
* @param string|array $value The header value
* @return mixed
*/
public function set($key, $value)
{
return parent::set($this->normalizeKey($key), [
'value' => (array)$value,
'value' => (array)$value,
'originalKey' => $key
]);
}
Expand All @@ -75,9 +74,9 @@ public function set($key, $value)
* Get HTTP header value
*
* @param string $key The case-insensitive header name
* @param mixed $default The default value if key does not exist
* @param mixed $default The default value if key does not exist
*
* @return string[]|null
* @return string[]|mixed|null
*/
public function get(string $key, $default = null)
{
Expand All @@ -89,7 +88,7 @@ public function get(string $key, $default = null)
}

/**
* @param $name
* @param $name
* @param null $default
* @return null|string
*/
Expand All @@ -104,7 +103,7 @@ public function getLine($name, $default = null): ?string

/**
* @param string $key
* @param mixed $value
* @param mixed $value
* @return mixed|null
*/
public function add($key, $value)
Expand All @@ -114,7 +113,7 @@ public function add($key, $value)
}

return parent::add($this->normalizeKey($key), [
'value' => (array)$value,
'value' => (array)$value,
'originalKey' => $key
]);
}
Expand Down Expand Up @@ -165,7 +164,7 @@ public function getAcceptLanguages(): array
}

$value = \str_replace(' ', '', $value);
$ls = \explode(',', $value);
$ls = \explode(',', $value);
}

return $ls;
Expand All @@ -186,7 +185,7 @@ public function getAcceptEncodes(): array
}

$value = \str_replace(' ', '', $value);
$ens = \explode(',', $value);
$ens = \explode(',', $value);
}

return $ens;
Expand All @@ -201,8 +200,8 @@ public function toHeaderLines(bool $join = false)
$output = [];

foreach ($this as $name => $info) {
$name = \ucwords($name, '-');
$value = \implode(',', $info['value']);
$name = \ucwords($name, '-');
$value = \implode(',', $info['value']);
$output[] = "$name: $value\r\n";
}

Expand All @@ -217,7 +216,7 @@ public function getLines(): array
$output = [];

foreach ($this as $name => $info) {
$name = \ucwords($name, '-');
$name = \ucwords($name, '-');
$output[$name] = \implode(',', $info['value']);
}

Expand Down
41 changes: 20 additions & 21 deletions src/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class HttpFactory
* @var array
*/
protected static $special = [
'CONTENT_TYPE' => 1,
'CONTENT_LENGTH' => 1,
'PHP_AUTH_USER' => 1,
'PHP_AUTH_PW' => 1,
'CONTENT_TYPE' => 1,
'CONTENT_LENGTH' => 1,
'PHP_AUTH_USER' => 1,
'PHP_AUTH_PW' => 1,
'PHP_AUTH_DIGEST' => 1,
'AUTH_TYPE' => 1,
'AUTH_TYPE' => 1,
];

/**
Expand All @@ -43,7 +43,7 @@ class HttpFactory

/**
* Create a new request.
* @param string $method
* @param string $method
* @param UriInterface|string $uri
* @return RequestInterface
* @throws \RuntimeException
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function createResponse(int $code = 200): ResponseInterface

/**
* Create a new server request.
* @param string $method
* @param string $method
* @param UriInterface|string $uri
* @return ServerRequestInterface
* @throws \RuntimeException
Expand Down Expand Up @@ -108,11 +108,11 @@ public static function createServerRequestFromArray($server, string $class = nul
$env = self::ensureIsCollection($server);
$uri = static::createUriFromArray($env);

$body = new RequestBody();
$method = $env->get('REQUEST_METHOD', 'GET');
$headers = static::createHeadersFromArray($env);
$cookies = Cookies::parseFromRawHeader($headers->get('Cookie', []));
$serverParams = $env->all();
$body = new RequestBody();
$method = $env->get('REQUEST_METHOD', 'GET');
$headers = static::createHeadersFromArray($env);
$cookies = Cookies::parseFromRawHeader($headers->get('Cookie', []));
$serverParams = $env->all();
$uploadedFiles = UploadedFile::createFromFILES();

$class = $class ?: ServerRequest::class;
Expand Down Expand Up @@ -191,10 +191,10 @@ public static function createStreamFromResource($resource): StreamInterface
* @see http://php.net/manual/features.file-upload.post-method.php
* @see http://php.net/manual/features.file-upload.errors.php
* @param string|resource $file
* @param integer $size in bytes
* @param integer $error PHP file upload error
* @param string $clientFilename
* @param string $clientMediaType
* @param integer $size in bytes
* @param integer $error PHP file upload error
* @param string $clientFilename
* @param string $clientMediaType
* @return UploadedFileInterface
* @throws \InvalidArgumentException If the file resource is not readable.
*/
Expand All @@ -204,8 +204,7 @@ public static function createUploadedFile(
int $error = \UPLOAD_ERR_OK,
string $clientFilename = null,
string $clientMediaType = null
): UploadedFileInterface
{
): UploadedFileInterface {
return new UploadedFile($file, $clientFilename, $clientMediaType, $size, $error);
}

Expand Down Expand Up @@ -235,7 +234,7 @@ public static function createUriFromArray($env): Uri

// Scheme
$isSecure = $env->get('HTTPS');
$scheme = (empty($isSecure) || $isSecure === 'off') ? 'http' : 'https';
$scheme = (empty($isSecure) || $isSecure === 'off') ? 'http' : 'https';

// Authority: Username and password
$username = $env->get('PHP_AUTH_USER', '');
Expand Down Expand Up @@ -298,8 +297,8 @@ public static function createUriFromArray($env): Uri
public static function createHeadersFromArray($env): Headers
{
$data = [];
$env = self::ensureIsCollection($env);
$env = self::determineAuthorization($env);
$env = self::ensureIsCollection($env);
$env = self::determineAuthorization($env);

foreach ($env as $key => $value) {
$key = \strtoupper($key);
Expand Down
6 changes: 3 additions & 3 deletions src/HttpUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class HttpUtil
/**
* Send the response the client
* @param ResponseInterface $response
* @param array $options
* @param array $options
* @throws \RuntimeException
*/
public static function respond(ResponseInterface $response, array $options = []): void
{
$options = \array_merge([
'chunkSize' => 4096,
'chunkSize' => 4096,
'addContentLengthHeader' => false,
], $options);

Expand Down Expand Up @@ -57,7 +57,7 @@ public static function respond(ResponseInterface $response, array $options = [])
$body->rewind();
}

$chunkSize = $options['chunkSize'];
$chunkSize = $options['chunkSize'];
$contentLength = $response->getHeaderLine('Content-Length');

if (!$contentLength) {
Expand Down
Loading

0 comments on commit 5baf6d5

Please sign in to comment.