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

[1.x] Fixes route:cache command #76

Merged
merged 3 commits into from
Aug 8, 2023
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
11 changes: 1 addition & 10 deletions src/FolioManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Folio;

use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Route;
Expand Down Expand Up @@ -34,13 +33,6 @@ class FolioManager
*/
protected ?MatchedView $lastMatchedView = null;

/**
* Create a new Folio manager instance.
*/
public function __construct(protected Application $app)
{
}

/**
* Register a route to handle page based routing at the given paths.
*
Expand Down Expand Up @@ -95,7 +87,6 @@ protected function handler(): Closure
)->all();

return (new RequestHandler(
$this,
$mountPaths,
$this->renderUsing,
fn (MatchedView $matchedView) => $this->lastMatchedView = $matchedView,
Expand Down Expand Up @@ -148,7 +139,7 @@ public function terminate(): void
{
if ($this->terminateUsing) {
try {
($this->terminateUsing)($this->app);
($this->terminateUsing)();
} finally {
$this->terminateUsing = null;
}
Expand Down
10 changes: 5 additions & 5 deletions src/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Pipeline;
Expand All @@ -20,7 +19,6 @@ class RequestHandler
* @param array<int, \Laravel\Folio\MountPath> $mountPaths
*/
public function __construct(
protected FolioManager $manager,
protected array $mountPaths,
protected ?Closure $renderUsing = null,
protected ?Closure $onViewMatch = null,
Expand Down Expand Up @@ -60,10 +58,12 @@ public function __invoke(Request $request): mixed
? ($this->renderUsing)($request, $matchedView)
: $this->toResponse($matchedView);

$this->manager->terminateUsing(
fn (Application $app) => $middleware->filter(fn ($middleware) => is_string($middleware) && class_exists($middleware) && method_exists($middleware, 'terminate'))
$app = app();

$app->make(FolioManager::class)->terminateUsing(
fn () => $middleware->filter(fn ($middleware) => is_string($middleware) && class_exists($middleware) && method_exists($middleware, 'terminate'))
->map(fn (string $middleware) => $app->make($middleware))
->each(fn (object $middleware) => $app->call([$middleware, 'terminate'], ['request' => $request, 'response' => $response]))
->each(fn (object $middleware) => $app->call([$middleware, 'terminate'], ['request' => $request, 'response' => $response])),
);

return $response;
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/Console/RouteCacheCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Laravel\Folio\Folio;

test('routes may be cached', function () {
Folio::route(__DIR__.'/../resources/views/pages');

$command = $this->artisan('route:cache');

$command->expectsOutputToContain('Routes cached successfully.');

$command->assertOk();
});