Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hendle render paths not found #326

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/System/Integrate/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ protected function handleJsonResponse(\Throwable $th): Response

protected function handleHttpException(HttpException $e): Response
{
$view = $this->registerViewPath();
$code = $view->viewExist((string) $e->getStatusCode())
$templator = $this->registerViewPath();
$code = $templator->viewExist((string) $e->getStatusCode())
? $e->getStatusCode()
: 500;

$this->app->set('view.instance', fn () => $templator);

$response = view((string) $code);
$response->setResponeCode($e->getStatusCode());
$response->setResponeCode($code);
$response->headers->add($e->getHeaders());

return $response;
Expand All @@ -131,12 +133,11 @@ protected function handleHttpException(HttpException $e): Response
*/
public function registerViewPath(): Templator
{
$view_path = $this->app->get('path.view');
$view_paths = array_map(fn ($path): string => $path . 'pages/', $this->app->get('paths.view'));
$view_paths[] = $this->app->get('path.view');
/** @var TemplatorFinder */
$finder = $this->app->make(TemplatorFinder::class);
$finder->setPaths([
$view_path . 'pages/', // find default first
]);
$finder->setPaths($view_paths);

/** @var Templator */
$view = $this->app->make('view.instance');
Expand Down
9 changes: 5 additions & 4 deletions tests/Integrate/Exceptions/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ public function itCanRenderJsonForDev()
public function itCanRenderHttpException()
{
$this->app->setViewPath('/assets/');
$this->app->setViewPaths([
'/assets/',
'/assets/pages/',
]);
$this->app->set(
TemplatorFinder::class,
fn () => new TemplatorFinder([
__DIR__ . '/assets',
__DIR__ . '/assets/pages',
], ['.php', '.template.php'])
fn () => new TemplatorFinder(view_paths(), ['.php', '.template.php'])
);

$this->app->set(
Expand Down
Loading