Skip to content

Commit

Permalink
formatting and cache path improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Nov 2, 2023
1 parent 6e528bd commit f400217
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/Commands/StaticBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function handle(): void
match ($driver = $this->config->get('static.driver', 'routes')) {
'crawler' => $this->cacheWithCrawler(),
'routes' => $this->cacheWithRoutes(),
default => throw new Exception("Static driver [{$driver}] is not supported"),
default => throw new Exception('Static driver '.$driver.' is not supported'),
};
}

Expand All @@ -63,26 +63,26 @@ public function cacheWithRoutes(): void
$response = Route::dispatchToRoute($request);

if (count($route->parameterNames()) !== 0) {
$id = $route->getName() ?? $route->uri();
$name = $route->getName() ?? $route->uri();

$this->components->warn("Skipping route [{$id}], can not build routes with parameters");
$this->components->warn('Skipping route: '.$name.', cannot cache routes with parameters');

continue;
}

if (! $response->isOk()) {
$this->components->error("✘ failed to cache page on route \"{$route->uri()}\"");
$this->components->error('Failed to cache route '.$route->uri());

$failed++;

continue;
}

$this->components->info("✔ page on route \"{$route->uri()}\" has been cached");
$this->components->info('Route '.$route->uri().' has been cached');
}

if ($failed > 0) {
$this->components->warn("FAILED TO CACHE {$failed} PAGES");
$this->components->warn('Failed to cache '.$failed.' routes');
}
}

Expand All @@ -106,7 +106,6 @@ public function cacheWithCrawler(): void
'User-Agent' => 'LaravelStatic/1.0',
],
])
->acceptNofollowLinks()
->setCrawlObserver($observer)
->setCrawlProfile($profile)
->setConcurrency($this->config->get('static.build.concurrency'))
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/StaticClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ protected function purgeWithRoutes(array $names)
$route = $routes->getByName($name);

if (is_null($route)) {
$this->components->warn("Route [{$name}] not found");
$this->components->warn('Route '.$name.' not found');

continue;
}

if (count($route->parameterNames()) !== 0) {
$this->components->warn("Route [{$name}] expects parameters, use the -u option instead");
$this->components->warn('Route '.$name.' expects parameters, use the -u option instead');

continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Crawler/StaticCrawlObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function crawled(
ResponseInterface $response,
UriInterface $foundOnUrl = null
): void {
$this->components->info("{$url} has been crawled");
$this->components->info('Crawled and cached url: '.$url);
}

/**
Expand All @@ -44,14 +44,14 @@ public function crawlFailed(
RequestException $requestException,
UriInterface $foundOnUrl = null
): void {
$this->components->error("✘ failed to crawl path ({$url})");
$this->components->error('Failed to crawl url: '.$url);
}

/**
* Called when the crawl has ended.
*/
public function finishedCrawling(): void
{
$this->components->info('Static build completed');
$this->components->info('Static cache build completed');
}
}
2 changes: 2 additions & 0 deletions src/Middleware/StaticResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function createStaticFile(Request $request, $response): void
[$path, $file] = $this->generateFilepath($request, $response);

$filepath = $this->joinPaths([
$request->method(),
$request->getHost(),
$path,
$file,
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/StaticCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

$this->get($route);

$path = "{$route}?.html";
$path = "GET/localhost/{$route}?.html";

$disk->assertExists($path);

Expand Down Expand Up @@ -48,7 +48,7 @@

$this->get('/');

$actual = $disk->get('?.html');
$actual = $disk->get('GET/localhost/?.html');

expect($actual)
->toBeString()
Expand Down

0 comments on commit f400217

Please sign in to comment.