PHPackages                             ayom413/sitemap-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. ayom413/sitemap-generator

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

ayom413/sitemap-generator
=========================

SitemapGenerator is a library which allows you to generate .xml, .json and ,csv files from data array

026PHP

Since Aug 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Ayom413/SitemapGenerator)[ Packagist](https://packagist.org/packages/ayom413/sitemap-generator)[ RSS](/packages/ayom413-sitemap-generator/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

SitemapGenerator
================

[](#sitemapgenerator)

SitemapGenerator is a library which allows you to generate .xml, .json and ,csv files from data array.

Installation
============

[](#installation)

You can dowload the library directly from Github, or via using composer. Composer command for downloading: composer require ayom413/sitemap-generator:dev-main. After that include the SitemapGenerator class in your PHP file:

require\_once './SitemapGenerator/SitemapGenerator.php';

Usage
=====

[](#usage)

Fisrt you need to create the data array for pages data, the file type you want to generate and the file path. After that you need to create the new instance of SitemapGenerator class.

```
$page = [
    [
        'loc' => 'https://site.ru/news',
        'lastmod' => '2020-12-14',
        'priority' => '1',
        'changefreq' => 'hourly',
    ],
    ];
$fileType = "json"; // or "csv", or "xml"
$filePath = "./sitemap_location";
$generator = new SitemapGenerator($page, $fileType, $filePath);
```

And finally call the generate() method to create a sitemap

```
$generator->generation();
print_r($generator);
```

Class structure
===============

[](#class-structure)

The library consists of several classes and interfaces: SitemapGenerator class is the main class responsible for generating sitemaps.

`Generator` is an abstract class that defines the generate method for sitemap generators.

`DataGenerator`,`CsvGenerator`, `JsonGenerator`, and `XmlGenerator` classes implement the main sitemap generation.

`ValidateData` class contains methods that validate the input data, file type, and file path.

`InvalidData`, `InvalidDataType`, and `InvalidFilePath` classes are exceptions thrown by the library in case of invalid input or incorrect usage.

Example
=======

[](#example)

```
