| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Sitemap\Integrations; |
| 6 |
|
| 7 |
use Yatra\Sitemap\SitemapRenderer; |
| 8 |
use Yatra\Sitemap\SitemapRouter; |
| 9 |
use Yatra\Sitemap\SitemapService; |
| 10 |
|
| 11 |
/** |
| 12 |
* Shared base for SEO plugins whose sitemap index is a filterable XML string |
| 13 |
* (Yoast, Rank Math). We append a single <sitemap> node pointing at Yatra's |
| 14 |
* own consolidated /yatra-sitemap.xml, so the plugin's index links to our one |
| 15 |
* file without us re-implementing its rendering. |
| 16 |
*/ |
| 17 |
abstract class AbstractIndexIntegration |
| 18 |
{ |
| 19 |
protected SitemapService $service; |
| 20 |
protected SitemapRouter $router; |
| 21 |
protected SitemapRenderer $renderer; |
| 22 |
|
| 23 |
public function __construct(SitemapService $service, SitemapRouter $router, SitemapRenderer $renderer) |
| 24 |
{ |
| 25 |
$this->service = $service; |
| 26 |
$this->router = $router; |
| 27 |
$this->renderer = $renderer; |
| 28 |
} |
| 29 |
|
| 30 |
abstract public function register(): void; |
| 31 |
|
| 32 |
/** |
| 33 |
* @param mixed $output Existing index XML (string). |
| 34 |
*/ |
| 35 |
public function append($output): string |
| 36 |
{ |
| 37 |
$pointer = $this->renderer->indexEntries([ |
| 38 |
['loc' => $this->router->sitemapUrl(), 'lastmod' => $this->service->getLatestLastmod()], |
| 39 |
]); |
| 40 |
|
| 41 |
return (string) $output . $pointer; |
| 42 |
} |
| 43 |
} |
| 44 |
|