PHPackages                             ridiculouscircumstances/sm-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ridiculouscircumstances/sm-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ridiculouscircumstances/sm-generator
====================================

A simple library for site-map generation.

1.0.2(3y ago)06MITPHP

Since Nov 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/RidiculousCircumstances/Sm-generator)[ Packagist](https://packagist.org/packages/ridiculouscircumstances/sm-generator)[ RSS](/packages/ridiculouscircumstances-sm-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

SITEMAP GENERATOR
=================

[](#sitemap-generator)

A simple library for fast sitemap generation in your projects.

---

Quickstart
----------

[](#quickstart)

To start using Sitemap generator, simply install and import it:

```
composer require ridiculouscircumstances/sm-generator

```

And then:

```
use Rc/SmGeneration/Sitemap;

```

First of all, create and add your array-like data into generator, then choose the type of output file and get an array of paths to saved files:

```
use Rc/SmGeneration/Sitemap;
///

$paths = Sitemap::create()->add([
    'loc' => 'ftp://site.ru',
    'lastmod' => '2020-11-12',
    'changefreq' => 'daily',
    'priority' => '1',
],
[
    'loc' => 'http://site.ru',
    'lastmod' => '2020-11-12',
    'changefreq' => 'monthly',
    'priority' => '0.4',
])
->writeToJson('sitemap')
->writeToXml('sitemap)
->writeToCsv('sitemap')
->getPaths();

```

That's all.

> Notice: default path to saved files determines by current directory of your project. In case you want to specify your path, pass it into second argument of "writeTo" method.

As you may have noticed, there is support for a chain-style, each method returns instance of Sitemap class. By default, the input data represents as an array of an associative arrays with the following keys:

- 'loc' - url address of resource,
- 'lastmod' - date of last resource modification,
- 'changefreq' - obviously, frequency of resource updating,
- 'priority' - value of page priority for search engines as they evaluate pages within a single site.

Thus, generator takes the above arguments and performs a data validation: each argument must match a specific format rule. The rules are defined via attributes which are attached to the data transfer object, and at which point you can flexibly customize your own rules and your own data patterns. Let's take a little look at the processes under the hood.

---

### Validation

[](#validation)

A data object looks like this:

```
class PageData
{
    public function __construct(
        #[Url]
