Apperclass Sitemap Builder library help you to create a sitemap for your site.
The recommended way to install SitemapBuilder is through composer.
Just create a composer.json file for your project:
{
"require": {
"apperclass/sitemap-builder": "dev-master"
},
"repositories" : [
{ "type":"vcs", "url":"https://github.com/apperclass/sitemap-builder.git" }
]
}
And run:
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
Here is the minimal code required to get a working sitemap builder:
<?php
use Apperclass\SitemapBuilder\SitemapBuilder;
use Apperclass\SitemapBuilder\SitemapPopulatorInterface;
use Apperclass\SitemapBuilder\Model\SitemapInterface;
use Apperclass\SitemapBuilder\Encoder\SitemapXmlEncoder;
use Apperclass\SitemapBuilder\Writer\SitemapFileWriter;
class SitemapPopulator implements SitemapPopulatorInterface
{
public function populate(SitemapInterface $sitemap)
{
$sitemapUrl = new SitemapUrl();
$sitemapUrl->setLoc('http://www.apperclass.com');
$sitemap->addSitemapUrl($sitemapUrl);
}
}
$sitemapBuilder = new SitemapBuilder();
$sitemapBuilder->addSitemapPopulator(new SitemapPopulator());
$sitemapEncoder = new SitemapXmlEncoder();
$sitemapFileWriter = new SitemapFileWriter();
$sitemapFileWriter
->setPath(__DIR__ . '/sitemap.xml');
->write($sitemapEncoder->encode($sitemapBuilder->build()));