ldc-sitemap-generator/routes/web.php
Jérémy Munsch 58c9050ecc
feat(config): add SitemapStorage for managing sitemap files
- Introduced SitemapStorage class for reading, writing, and checking existence of sitemap files.
- Updated GenerateSitemapCommand to utilize SitemapStorage for file operations.
- Refactored tests to accommodate changes in sitemap file handling.
- Enhanced configuration to support output paths and storage disks.
2026-10-15 14:42:20 +02:00

37 lines
960 B
PHP

<?php
declare(strict_types=1);
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Route;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Uwil\SitemapGenerator\Config\SitemapConfig;
use Uwil\SitemapGenerator\Exceptions\SitemapException;
Route::get('sitemap.xml', function (): StreamedResponse {
$sitemapStorage = resolve(SitemapConfig::class)->sitemapStorage;
try {
$stream = $sitemapStorage->streamFromDisk();
} catch (SitemapException) {
abort(404);
exit;
}
return Response::stream(
static function () use ($stream): void {
$output = fopen('php://output', 'wb');
if (\is_resource($output)) {
stream_copy_to_stream($stream, $output);
fclose($output);
}
fclose($stream);
},
200,
[
'Content-Type' => 'application/xml; charset=utf-8',
]
);
});