2017 © Pedro Peláez
 

library sitemap-generator

Library for create and write sitemap.xml for you site

image

mima/sitemap-generator

Library for create and write sitemap.xml for you site

  • Tuesday, September 27, 2016
  • by MimaTomis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 67 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

Sitemap generator

Build Status, (*1)

Library for generate sitemap.xml. Easy to use and very extensible. It allows you to create custom data sources., (*2)

Installation

Install with composer from command line:, (*3)

composer require mima/sitemap-generator

Or add dependency to require section in your composer.json:, (*4)

{
    "require": {
        "mima/sitemap-generator": "~1.0"
    }
}

Usage

To start, you must to create data extractor. For this, define subclass of SitemapRenderer\Extractor\DataExtractorInterface., (*5)

As sample, we create following data extractor:, (*6)

namespace MyNamespace\SitemapGenerator\Extractor;

use SitemapGenerator\Extractor\DataExtractorInterface;
use SitemapGenerator\Entity\SitemapItem;

class FromArrayDataExtractor implements DataExtractorInterface
{
    /**
     * This method return \Generator, which at each iteration returns instance of SitemapItem
     *
     * @return |Generator
     */
    public function extractData()
    {
        // load data and each them
        foreach ($this->loadData() as $data) {
            // create instance of SitemapItem based on loaded data
            $item = new SitemapItem('/page-'.$data['id'], new \DateTime($data['created_at']));

            // return this instance
            yield $item;
        }
    }

    /**
     * Load data from array, as samle.
     * It can be a database query, or query to external API.
     *
     * @return array
     */
    protected function loadData()
    {
        return [
            [
                'id' => 1,
                'created_at' => '2016-09-12 00:00:00'
            ],
            [
                'id' => 2,
                'created_at' => '2016-09-12 03:40:00'
            ]
        ];
    }
}

Now we can generate a sitemap.xml:, (*7)

use SitemapGenerator\Factory\SimpleGeneratorFactory;
use MyNamespace\SitemapGenerator\Extractor\FromArrayDataExtractor;

/**
 * This is a directory, where the sitemap will be saved.
 * It must exist in the file system and be available for recording.
 */
$directoryToSaveSitemap = './web';

// Create instance of extractor, which we defined earlier
$extractor = new FromArrayDataExtractor();

// Create instance of factory for simple sitemap generator
$simpleGeneratorFactory = new SimpleGeneratorFactory();

// Create generator by factory
$generator = $simpleGeneratorFactory->createGenerator($directoryToSaveSitemap);

/**
 * Generate sitemap by data, which return extractor.
 * This method return path to generated file.
 */
$filePath = $generator->generate($extractor);

The Versions

27/09 2016

dev-develop

dev-develop

Library for create and write sitemap.xml for you site

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

27/09 2016

dev-master

9999999-dev

Library for create and write sitemap.xml for you site

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

27/09 2016

v1.0.2

1.0.2.0

Library for create and write sitemap.xml for you site

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

27/09 2016

v1.0.1

1.0.1.0

Library for create and write sitemap.xml for you site

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev

27/09 2016

v1.0

1.0.0.0

Library for create and write sitemap.xml for you site

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Dmitriy Konev