The dumper is the class which takes care of the sitemap's persistance (in memory, in a file, etc.) and the formatter formats the sitemap.
Currently, the following dumpers are implemented:
- File: dumps the sitemap into a file
- GzFile: dumps the sitemap into a gz compressed file
- Memory: dumps the sitemap in memory
And the following formatters are implemented:
- Text: formats the sitemap as a simple text file that contains one URL per line
- Xml: formats a classic XML sitemap
- RichXml: formats a rich XML sitemap
- Spaceless: wraps another formatter and remove the \n and \t characters
The dumpers must implement the Dumper
interface and the formatters the
Formatter
interface.
Images and videos are two objects that are embeddable in sitemaps, and fortunately, this bundle supports both of them.
Just look the Image and Video class to know how to use them.
In order to be able to generate a sitemap index, the sitemap generator configuration must follow these rules:
- use a
\SitemapGenerator\Dumper\FileDumper
instance as dumper (like\SitemapGenerator\Dumper\File
or\SitemapGenerator\Dumper\GzFile
) - use a
\SitemapGenerator\Formatter\SitemapIndex
instance as formatter (likeSitemapGenerator\Formatter\Xml
orSitemapGenerator\Formatter\RichXml
- and have a
limit
parameter strictly greater to0
.
If all these rules are respected, the generator will build a sitemap index.
Here is how you prepare the generator for a sitemap index:
<?php
use SitemapGenerator\Dumper;
use SitemapGenerator\Formatter;
use SitemapGenerator\SitemapIndex;
$dumper = new Dumper\File('sitemap-index.xml');
$formatter = new Formatter\RichXml();
$sitemap = new SitemapIndex($dumper, $formatter, $base_host = 'http://www.website.com');