fdevs / sitemap
Library for the generate sitemap
0.1.1
2016-06-17 11:03 UTC
Requires
- php: >=5.4
Suggests
- fdevs/sitemap-bridge: use with symfony components
- fdevs/sitemap-bundle: use with symfony bundle
README
Sitemap
use rules Sitemaps XML format for the generate sitemap
If you use Symfony 2, you could use our sitemap bridge or sitemap bundle!
Installation
Sitemap uses Composer, please checkout the composer website for more information.
The simple following command will install sitemap
into your project. It also add a new
entry in your composer.json
and update the composer.lock
as well.
composer require fdevs/sitemap
Usage examples:
create your adapter
<?php namespace FDevs\App\Sitemap\Adapter; use FDevs\Sitemap\Adapter\AbstractAdapter; class StaticRouting extends AbstractAdapter { /** * @param string $name * @param array $params * @param mixed $item * * @return Url|null */ public function createUrl($name, array $params = [], $item) { } /** * @param array $params * * @return \Iterator */ public function getItemList(array $params = []) { } }
usage UrlSet
use FDevs\Sitemap\Factory\UrlSet; use FDevs\Sitemap\Util\Params; $urlset = new UrlSet(); // your params for the uri $params = [ ['_locale' => 'ru', '_format' => 'html'], ['_locale' => 'en', '_format' => 'html'], ['_locale' => 'ru', '_format' => 'rss'], ['_locale' => 'en', '_format' => 'rss'], ]; echo $urlset->xmlString($params); //<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>http://4devs.io/ru</loc><priority>0.7</priority></url></urlset> //or save sitemap $urlset->saveFile('/full/path/to/sitemap.xml',$params);
usage SiteMapIndex
use FDevs\Sitemap\Factory\SiteMapIndex; $index = new SiteMapIndex('http://domain.ltd','/full/path/to/web/dir'); // your params for the uri $params = [ ['_locale' => 'ru', '_format' => 'html'], ['_locale' => 'en', '_format' => 'html'], ]; echo $index->xmlString($params); //<?xml version="1.0" encoding="UTF-8"?><sitemapindex><sitemap><loc>http://domain.ltd/ru.html.sitemap.xml</loc></sitemap><sitemap><loc>http://domain.ltd/en.html.sitemap.xml</loc></sitemap></sitemapindex> //or save sitemap $index->saveFile('/full/path/to/sitemap.xml',$params);
usage Params helper
use FDevs\Sitemap\Util\Params; $params = Params::prepare(['_locale'=>['ru','en'],'_format'=>['html','rss']]) //output //$params = [ // ['_locale' => 'ru', '_format' => 'html'], // ['_locale' => 'en', '_format' => 'html'], // ['_locale' => 'ru', '_format' => 'rss'], // ['_locale' => 'en', '_format' => 'rss'], //];
usage sitemap manager
use FDevs\Sitemap\SitemapManager; use FDevs\Sitemap\Factory\SiteMapIndex; use FDevs\Sitemap\Factory\UrlSet; use FDevs\Sitemap\Util\Params; $index = new SiteMapIndex('http://domain.ltd','/full/path/to/web/dir'); $urlset = new UrlSet(); $params = Params::prepare(['_locale'=>['ru','en'],'_format'=>['html','xml']]) $manager = new SitemapManager(); $manager ->add($urlset) ->add($index); $manager->get('index')->xmlString($params); $manager->get('index')->saveFile('/full/path/to/sitemap.xml',$params); $manager->get('sitemap')->xmlString($params); $manager->get('sitemap')->saveFile('/full/path/to/sitemapindex.xml',$params);
Created by 4devs - Check out our blog for more insight into this and other open-source projects we release.