ea
This commit is contained in:
@@ -18,7 +18,5 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Kiri\\Router\\": "./src"
|
"Kiri\\Router\\": "./src"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,33 @@ use Psr\Http\Message\ResponseInterface;
|
|||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @param array $data
|
||||||
|
*
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
function View(string $path, array $data = []): ResponseInterface
|
||||||
|
{
|
||||||
|
$response = \response();
|
||||||
|
$response->withAddedHeader('Content-Type', 'text/html; charset=utf-8');
|
||||||
|
try {
|
||||||
|
ob_start();
|
||||||
|
$__path = $path;
|
||||||
|
$__data = $data;
|
||||||
|
|
||||||
|
extract($__data, EXTR_SKIP);
|
||||||
|
|
||||||
|
require APP_PATH . 'resources/view/' . $path . '.php';
|
||||||
|
|
||||||
|
$content = ltrim(ob_get_clean());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$content = throwable($e);
|
||||||
|
} finally {
|
||||||
|
return $response->html($content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -57,6 +84,7 @@ class Response implements ResponseInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ContentType $contentType
|
* @param ContentType $contentType
|
||||||
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function withContentType(ContentType $contentType): ResponseInterface
|
public function withContentType(ContentType $contentType): ResponseInterface
|
||||||
@@ -68,6 +96,7 @@ class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $content
|
* @param array $content
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function json(array $content, int $statusCode = 200): ResponseInterface
|
public function json(array $content, int $statusCode = 200): ResponseInterface
|
||||||
@@ -79,6 +108,7 @@ class Response implements ResponseInterface
|
|||||||
* @param string $url
|
* @param string $url
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function redirectTo(string $url, array $params = [], int $statusCode = 302): ResponseInterface
|
public function redirectTo(string $url, array $params = [], int $statusCode = 302): ResponseInterface
|
||||||
@@ -89,6 +119,7 @@ class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @param array $content
|
* @param array $content
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function xml(array $content, int $statusCode = 200): ResponseInterface
|
public function xml(array $content, int $statusCode = 200): ResponseInterface
|
||||||
@@ -100,6 +131,7 @@ class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function html(string $content = '', int $statusCode = 200): ResponseInterface
|
public function html(string $content = '', int $statusCode = 200): ResponseInterface
|
||||||
@@ -111,6 +143,7 @@ class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @param string $content
|
* @param string $content
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function sendfile(string $content, int $statusCode = 200): ResponseInterface
|
public function sendfile(string $content, int $statusCode = 200): ResponseInterface
|
||||||
@@ -123,6 +156,7 @@ class Response implements ResponseInterface
|
|||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
* @param ContentType $type
|
* @param ContentType $type
|
||||||
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function write(mixed $data, int $statusCode = 200, ContentType $type = ContentType::HTML): ResponseInterface
|
public function write(mixed $data, int $statusCode = 200, ContentType $type = ContentType::HTML): ResponseInterface
|
||||||
@@ -134,6 +168,7 @@ class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param mixed ...$params
|
* @param mixed ...$params
|
||||||
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private function __call__(string $method, ...$params): mixed
|
private function __call__(string $method, ...$params): mixed
|
||||||
@@ -144,6 +179,7 @@ class Response implements ResponseInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $cookies
|
* @param array $cookies
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function withCookieParams(array $cookies): ResponseInterface
|
public function withCookieParams(array $cookies): ResponseInterface
|
||||||
@@ -185,6 +221,7 @@ class Response implements ResponseInterface
|
|||||||
* new protocol version.
|
* new protocol version.
|
||||||
*
|
*
|
||||||
* @param string $version HTTP protocol version
|
* @param string $version HTTP protocol version
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public function withProtocolVersion(string $version): ResponseInterface
|
public function withProtocolVersion(string $version): ResponseInterface
|
||||||
@@ -228,6 +265,7 @@ class Response implements ResponseInterface
|
|||||||
* Checks if a header exists by the given case-insensitive name.
|
* Checks if a header exists by the given case-insensitive name.
|
||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name.
|
* @param string $name Case-insensitive header field name.
|
||||||
|
*
|
||||||
* @return bool Returns true if any header names match the given header
|
* @return bool Returns true if any header names match the given header
|
||||||
* name using a case-insensitive string comparison. Returns false if
|
* name using a case-insensitive string comparison. Returns false if
|
||||||
* no matching header name is found in the message.
|
* no matching header name is found in the message.
|
||||||
@@ -248,6 +286,7 @@ class Response implements ResponseInterface
|
|||||||
* empty array.
|
* empty array.
|
||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name.
|
* @param string $name Case-insensitive header field name.
|
||||||
|
*
|
||||||
* @return string[] An array of string values as provided for the given
|
* @return string[] An array of string values as provided for the given
|
||||||
* header. If the header does not appear in the message, this method MUST
|
* header. If the header does not appear in the message, this method MUST
|
||||||
* return an empty array.
|
* return an empty array.
|
||||||
@@ -273,6 +312,7 @@ class Response implements ResponseInterface
|
|||||||
* an empty string.
|
* an empty string.
|
||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name.
|
* @param string $name Case-insensitive header field name.
|
||||||
|
*
|
||||||
* @return string A string of values as provided for the given header
|
* @return string A string of values as provided for the given header
|
||||||
* concatenated together using a comma. If the header does not appear in
|
* concatenated together using a comma. If the header does not appear in
|
||||||
* the message, this method MUST return an empty string.
|
* the message, this method MUST return an empty string.
|
||||||
@@ -295,6 +335,7 @@ class Response implements ResponseInterface
|
|||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name.
|
* @param string $name Case-insensitive header field name.
|
||||||
* @param string|string[] $value Header value(s).
|
* @param string|string[] $value Header value(s).
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -307,6 +348,7 @@ class Response implements ResponseInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function withHeaders(array $headers): ResponseInterface
|
public function withHeaders(array $headers): ResponseInterface
|
||||||
@@ -327,6 +369,7 @@ class Response implements ResponseInterface
|
|||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name to add.
|
* @param string $name Case-insensitive header field name to add.
|
||||||
* @param string|string[] $value Header value(s).
|
* @param string|string[] $value Header value(s).
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -346,6 +389,7 @@ class Response implements ResponseInterface
|
|||||||
* the named header.
|
* the named header.
|
||||||
*
|
*
|
||||||
* @param string $name Case-insensitive header field name to remove.
|
* @param string $name Case-insensitive header field name to remove.
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public function withoutHeader(string $name): ResponseInterface
|
public function withoutHeader(string $name): ResponseInterface
|
||||||
@@ -375,6 +419,7 @@ class Response implements ResponseInterface
|
|||||||
* new body stream.
|
* new body stream.
|
||||||
*
|
*
|
||||||
* @param StreamInterface $body Body.
|
* @param StreamInterface $body Body.
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
@@ -403,6 +448,7 @@ class Response implements ResponseInterface
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
* @param int $statusCode
|
* @param int $statusCode
|
||||||
* @param ContentType $contentType
|
* @param ContentType $contentType
|
||||||
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
*/
|
*/
|
||||||
public function raw(string $content, int $statusCode = 200, ContentType $contentType = ContentType::JSON): ResponseInterface
|
public function raw(string $content, int $statusCode = 200, ContentType $contentType = ContentType::JSON): ResponseInterface
|
||||||
@@ -423,10 +469,12 @@ class Response implements ResponseInterface
|
|||||||
*
|
*
|
||||||
* @link http://tools.ietf.org/html/rfc7231#section-6
|
* @link http://tools.ietf.org/html/rfc7231#section-6
|
||||||
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
|
* @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
|
||||||
|
*
|
||||||
* @param int $code The 3-digit integer result code to set.
|
* @param int $code The 3-digit integer result code to set.
|
||||||
* @param string $reasonPhrase The reason phrase to use with the
|
* @param string $reasonPhrase The reason phrase to use with the
|
||||||
* provided status code; if none is provided, implementations MAY
|
* provided status code; if none is provided, implementations MAY
|
||||||
* use the defaults as suggested in the HTTP specification.
|
* use the defaults as suggested in the HTTP specification.
|
||||||
|
*
|
||||||
* @return static
|
* @return static
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user