kuzmichus/sitemap-xml

Generated Sitemap XML file

dev-master / 0.1.x-dev 2015-07-20 07:38 UTC

This package is not auto-updated.

Last update: 2020-08-07 19:49:38 UTC


README

Code Climate Build Status

SitemapXml

Generation Sitemap XML file

Install the latest version with

$ composer require kuzmichus/sitemap-xml

Usage

<?php

use SitemapXml\Generator;

require __DIR__ . '/../vendor/autoload.php';


\SitemapXml\Helper\Formatter::enable();
\SitemapXml\Validators\Availability::setStrictness(\SitemapXml\Validators\Availability::STRICT_SOFT);

$io = new \Symfony\Component\Console\Output\ConsoleOutput();

$generator = new \SitemapXml\XmlGoogleGenerator();
$generator
    ->setIo($io)
    ->setLocalPath(__DIR__ . '/public/')
    ->setPublicIndexPath('http://example.com/')
    ->setDefaultChangefreq(Generator::DAILY)
    ->setDefaultPriority('0.8')
    ->start();

    try {

        $generator->add('http://example.com/');
        $generator->add('http://example.com/page1/');
        $generator->add('http://example.com/page2/');
        $generator->add('http://example.com/page3/');

    } catch (\SitemapXml\Exception\ResourceNotFound $e) {
        echo $e->getMessage() . PHP_EOL;
    }

$generator->finish();