| 1 | <?php |
||
| 8 | class Sitemap |
||
| 9 | { |
||
| 10 | /** @var array */ |
||
| 11 | protected $tags = []; |
||
| 12 | |||
| 13 | /** @var string */ |
||
| 14 | protected $sitemapXsl; |
||
| 15 | |||
| 16 | public static function create(): self |
||
| 20 | |||
| 21 | public function __construct(string $sitemapXsl) |
||
| 22 | { |
||
| 23 | $this->sitemapXsl = $sitemapXsl; |
||
| 24 | return $this; |
||
|
|
|||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string|\Spatie\Sitemap\Tags\Tag $tag |
||
| 29 | * |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function add($tag): self |
||
| 33 | { |
||
| 34 | if (is_string($tag)) { |
||
| 35 | $tag = Url::create($tag); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (! in_array($tag, $this->tags)) { |
||
| 39 | $this->tags[] = $tag; |
||
| 40 | } |
||
| 41 | |||
| 42 | return $this; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getTags(): array |
||
| 46 | { |
||
| 47 | return $this->tags; |
||
| 48 | } |
||
| 49 | |||
| 50 | public function getUrl(string $url): ?Url |
||
| 51 | { |
||
| 52 | return collect($this->tags)->first(function (Tag $tag) use ($url) { |
||
| 53 | return $tag->getType() === 'url' && $tag->url === $url; |
||
| 54 | }); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function hasUrl(string $url): bool |
||
| 58 | { |
||
| 59 | return (bool) $this->getUrl($url); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function render(): string |
||
| 63 | { |
||
| 64 | sort($this->tags); |
||
| 65 | |||
| 66 | $tags = $this->tags; |
||
| 67 | $sitemapXsl = $this->sitemapXsl; |
||
| 68 | |||
| 69 | return view('laravel-sitemap::sitemap') |
||
| 70 | ->with(compact('tags', 'sitemapXsl')) |
||
| 71 | ->render(); |
||
| 72 | } |
||
| 73 | |||
| 74 | public function writeToFile(string $path): self |
||
| 80 | } |
||
| 81 |