- 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.
37 lines
960 B
PHP
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',
|
|
]
|
|
);
|
|
});
|