Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
ca3bb2cb0a | |
|
|
c5f49214b5 |
|
|
@ -7,7 +7,7 @@ use Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HeaderCollection provides case-insensitive access to lists of header values.
|
* HeaderCollection provides case-insensitive access to lists of header values.
|
||||||
**
|
*
|
||||||
* HeaderCollection preserves the cases of keys as they are set, but treats key
|
* HeaderCollection preserves the cases of keys as they are set, but treats key
|
||||||
* access case insensitively.
|
* access case insensitively.
|
||||||
*
|
*
|
||||||
|
|
@ -51,7 +51,7 @@ class HeaderCollection implements ArrayAccess, Iterator
|
||||||
* @param string $offset
|
* @param string $offset
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function offsetExists($offset)
|
public function offsetExists($offset): bool
|
||||||
{
|
{
|
||||||
return isset($this->values[strtolower($offset)]);
|
return isset($this->values[strtolower($offset)]);
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ class HeaderCollection implements ArrayAccess, Iterator
|
||||||
* @param mixed $offset
|
* @param mixed $offset
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function offsetGet($offset)
|
public function offsetGet($offset): array
|
||||||
{
|
{
|
||||||
return $this->values[strtolower($offset)];
|
return $this->values[strtolower($offset)];
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ class HeaderCollection implements ArrayAccess, Iterator
|
||||||
* @param string $offset
|
* @param string $offset
|
||||||
* @param string $value
|
* @param string $value
|
||||||
*/
|
*/
|
||||||
public function offsetSet($offset, $value)
|
public function offsetSet($offset, $value): void
|
||||||
{
|
{
|
||||||
$normalized = strtolower($offset);
|
$normalized = strtolower($offset);
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ class HeaderCollection implements ArrayAccess, Iterator
|
||||||
/**
|
/**
|
||||||
* @param string $offset
|
* @param string $offset
|
||||||
*/
|
*/
|
||||||
public function offsetUnset($offset)
|
public function offsetUnset($offset): void
|
||||||
{
|
{
|
||||||
$normalized = strtolower($offset);
|
$normalized = strtolower($offset);
|
||||||
unset($this->fields[$normalized]);
|
unset($this->fields[$normalized]);
|
||||||
|
|
@ -107,27 +107,30 @@ class HeaderCollection implements ArrayAccess, Iterator
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// Iterator
|
// Iterator
|
||||||
|
|
||||||
public function current()
|
/**
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function current(): array
|
||||||
{
|
{
|
||||||
return $this->values[$this->keys[$this->position]];
|
return $this->values[$this->keys[$this->position]];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function next()
|
public function next(): void
|
||||||
{
|
{
|
||||||
++$this->position;
|
++$this->position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function key()
|
public function key(): string
|
||||||
{
|
{
|
||||||
return $this->fields[$this->keys[$this->position]];
|
return $this->fields[$this->keys[$this->position]];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function valid()
|
public function valid(): bool
|
||||||
{
|
{
|
||||||
return isset($this->keys[$this->position]);
|
return isset($this->keys[$this->position]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rewind()
|
public function rewind(): void
|
||||||
{
|
{
|
||||||
$this->position = 0;
|
$this->position = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ class Request extends Message implements RequestInterface
|
||||||
$request = clone $this;
|
$request = clone $this;
|
||||||
|
|
||||||
$newHost = $uri->getHost();
|
$newHost = $uri->getHost();
|
||||||
$oldHost = isset($request->headers['Host']) ? $request->headers['Host'] : '';
|
$oldHost = $request->headers['Host'] ?? '';
|
||||||
|
|
||||||
if ($preserveHost === false) {
|
if ($preserveHost === false) {
|
||||||
// Update Host
|
// Update Host
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace WellRESTed\Message;
|
||||||
|
|
||||||
|
use Psr\Http\Message\RequestFactoryInterface;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
use Psr\Http\Message\UriInterface;
|
||||||
|
|
||||||
|
class RequestFactory implements RequestFactoryInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Create a new request.
|
||||||
|
*
|
||||||
|
* @param string $method The HTTP method associated with the request.
|
||||||
|
* @param UriInterface|string $uri The URI associated with the request. If
|
||||||
|
* the value is a string, the factory MUST create a UriInterface
|
||||||
|
* instance based on it.
|
||||||
|
*
|
||||||
|
* @return RequestInterface
|
||||||
|
*/
|
||||||
|
public function createRequest(string $method, $uri): RequestInterface
|
||||||
|
{
|
||||||
|
return new Request($method, $uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -117,21 +117,21 @@ class UploadedFile implements UploadedFileInterface
|
||||||
*
|
*
|
||||||
* @see http://php.net/is_uploaded_file
|
* @see http://php.net/is_uploaded_file
|
||||||
* @see http://php.net/move_uploaded_file
|
* @see http://php.net/move_uploaded_file
|
||||||
* @param string $path Path to which to move the uploaded file.
|
* @param string $targetPath Path to which to move the uploaded file.
|
||||||
* @return void
|
* @return void
|
||||||
* @throws InvalidArgumentException if the $path specified is invalid.
|
* @throws InvalidArgumentException if the $path specified is invalid.
|
||||||
* @throws RuntimeException on any error during the move operation, or on
|
* @throws RuntimeException on any error during the move operation, or on
|
||||||
* the second or subsequent call to the method.
|
* the second or subsequent call to the method.
|
||||||
*/
|
*/
|
||||||
public function moveTo($path)
|
public function moveTo($targetPath)
|
||||||
{
|
{
|
||||||
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
if ($this->tmpName === null || !file_exists($this->tmpName)) {
|
||||||
throw new RuntimeException("File {$this->tmpName} does not exist.");
|
throw new RuntimeException("File {$this->tmpName} does not exist.");
|
||||||
}
|
}
|
||||||
if (php_sapi_name() === 'cli') {
|
if (php_sapi_name() === 'cli') {
|
||||||
rename($this->tmpName, $path);
|
rename($this->tmpName, $targetPath);
|
||||||
} else {
|
} else {
|
||||||
move_uploaded_file($this->tmpName, $path);
|
move_uploaded_file($this->tmpName, $targetPath);
|
||||||
}
|
}
|
||||||
$this->moved = true;
|
$this->moved = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -292,7 +292,7 @@ class Uri implements UriInterface
|
||||||
*/
|
*/
|
||||||
public function withScheme($scheme)
|
public function withScheme($scheme)
|
||||||
{
|
{
|
||||||
$scheme = $scheme ? strtolower($scheme) : '';
|
$scheme = strtolower($scheme ?? '');
|
||||||
if (!in_array($scheme, ['', 'http', 'https'])) {
|
if (!in_array($scheme, ['', 'http', 'https'])) {
|
||||||
throw new InvalidArgumentException('Scheme must be http, https, or empty.');
|
throw new InvalidArgumentException('Scheme must be http, https, or empty.');
|
||||||
}
|
}
|
||||||
|
|
@ -446,7 +446,7 @@ class Uri implements UriInterface
|
||||||
public function withFragment($fragment)
|
public function withFragment($fragment)
|
||||||
{
|
{
|
||||||
$uri = clone $this;
|
$uri = clone $this;
|
||||||
$uri->fragment = $fragment;
|
$uri->fragment = $fragment ?? '';
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -520,7 +520,7 @@ class Uri implements UriInterface
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function percentEncode($subject)
|
private function percentEncode(string $subject)
|
||||||
{
|
{
|
||||||
$reserved = ':/?#[]@!$&\'()*+,;=';
|
$reserved = ':/?#[]@!$&\'()*+,;=';
|
||||||
$reserved = preg_quote($reserved);
|
$reserved = preg_quote($reserved);
|
||||||
|
|
|
||||||
|
|
@ -278,7 +278,7 @@ class Router implements MiddlewareInterface
|
||||||
usort($matches, $compareByLength);
|
usort($matches, $compareByLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
$bestMatch = $matches[0];
|
$bestMatch = array_values($matches)[0];
|
||||||
return $this->prefixRoutes[$bestMatch];
|
return $this->prefixRoutes[$bestMatch];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue