eee
This commit is contained in:
+33
-26
@@ -12,9 +12,9 @@ use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* 渲染 Blade 视图
|
||||
*
|
||||
*
|
||||
* @param string $path 视图路径(支持 . 分隔,如 'user.profile')
|
||||
* @param array $data 视图数据
|
||||
* @param array $data 视图数据
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -22,26 +22,33 @@ function View(string $path, array $data = []): ResponseInterface
|
||||
{
|
||||
$response = \response();
|
||||
$response->withAddedHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
|
||||
|
||||
try {
|
||||
// 获取视图路径和缓存路径
|
||||
$viewPath = APP_PATH . 'resources/view';
|
||||
$cachePath = storage(null, 'view/cache');
|
||||
|
||||
$viewPath = APP_PATH . 'resources/view';
|
||||
$cachePath = storage(null, 'view/cache');
|
||||
|
||||
// 创建或获取 BladeFactory 实例
|
||||
$factory = BladeHelper::getFactory();
|
||||
if ($factory->getViewPath() !== $viewPath) {
|
||||
$factory = new BladeFactory($viewPath, $cachePath);
|
||||
BladeHelper::setFactory($factory);
|
||||
}
|
||||
|
||||
|
||||
// 渲染视图
|
||||
$content = $factory->render($path, $data);
|
||||
} catch (\Exception $e) {
|
||||
$content = function_exists('throwable') ? throwable($e) : $e->getMessage();
|
||||
return $response->html($factory->render($path, $data));
|
||||
} catch (\Exception $throwable) {
|
||||
\Kiri::getLogger()->json_log($throwable);
|
||||
|
||||
ob_start();
|
||||
|
||||
extract(['errorData' => $throwable], EXTR_SKIP);
|
||||
include __DIR__.'/template/error.php';
|
||||
|
||||
$message = ob_get_clean();
|
||||
|
||||
return $response->html($message);
|
||||
}
|
||||
|
||||
return $response->html($content);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +111,7 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param array $content
|
||||
* @param int $statusCode
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -115,8 +122,8 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param int $statusCode
|
||||
* @param array $params
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -127,7 +134,7 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param array $content
|
||||
* @param int $statusCode
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -139,7 +146,7 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -151,7 +158,7 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
@@ -162,8 +169,8 @@ class Response implements ResponseInterface
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @param int $statusCode
|
||||
* @param mixed $data
|
||||
* @param int $statusCode
|
||||
* @param ContentType $type
|
||||
*
|
||||
* @return Response
|
||||
@@ -176,7 +183,7 @@ class Response implements ResponseInterface
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param mixed ...$params
|
||||
* @param mixed ...$params
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -342,7 +349,7 @@ class Response implements ResponseInterface
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new and/or updated header and value.
|
||||
*
|
||||
* @param string $name Case-insensitive header field name.
|
||||
* @param string $name Case-insensitive header field name.
|
||||
* @param string|string[] $value Header value(s).
|
||||
*
|
||||
* @return static
|
||||
@@ -376,7 +383,7 @@ class Response implements ResponseInterface
|
||||
* immutability of the message, and MUST return an instance that has the
|
||||
* new header and/or value.
|
||||
*
|
||||
* @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).
|
||||
*
|
||||
* @return static
|
||||
@@ -454,8 +461,8 @@ class Response implements ResponseInterface
|
||||
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param string $content
|
||||
* @param int $statusCode
|
||||
* @param ContentType $contentType
|
||||
*
|
||||
* @return ResponseInterface
|
||||
@@ -479,7 +486,7 @@ class Response implements ResponseInterface
|
||||
* @link http://tools.ietf.org/html/rfc7231#section-6
|
||||
* @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
|
||||
* provided status code; if none is provided, implementations MAY
|
||||
* use the defaults as suggested in the HTTP specification.
|
||||
|
||||
Reference in New Issue
Block a user