@@ -90,38 +90,70 @@ echo $sitemapIndex->toString();
9090
9191### Sitemap Factory
9292
93- ** Still under heavy development. DO NOT USE.**
93+ The Sitemap Factory create Sitemaps and Sitemap Indexes and writes them to the Filesystem.
94+ Is is can be used to generate full Sitemaps with more than ** 50,000** URLs.
95+
96+ If more than one sitemap is generated, it will create a Sitemap Index automatically.
97+
98+ #### Instantiating
99+
100+ The factory uses [ Flysystem] ( http://flysystem.thephpleague.com/ ) to write the sitemaps. This
101+ means you can write the sitemaps to Local Disk, S3, Dropbox, wherever you want.
94102
95103``` php
96104<?php
105+
97106use League\Flysystem\Filesystem;
98107use League\Flysystem\Adapter\Local as LocalAdapter;
99108
100- $adapter = new LocalAdapter(__DIR__);
109+ $adapter = new LocalAdapter(__DIR__.'/sitemaps' );
101110$filesystem = new Filesystem($adapter);
102111$sitemapFactory = new Tackk\Cartographer\SitemapFactory($filesystem);
103112
104- // $sitemap is a string (this will be saved to the Filesystem eventually)
105- $sitemap = $sitemapFactory->create(get_sitemap_links());
106-
107- /**
108- * Generates an iterator for the SitemapFactory to use to
109- * create the sitemap.
110- * @return Iterator
111- */
112- function get_sitemap_links()
113- {
114- $result = execute_unbuffered_query();
115-
116- while ($link = $result->fetch()) {
117- yield [
118- 'url' => $link->url,
119- 'lastmod' => $link->lastModified,
120- ];
121- }
122- }
123113```
124114
115+ #### Base URL
116+
117+ The Base URL is used when generating the Sitemap Indexes, and for the returned entry point URL.
118+
119+ You can set the Base URL:
120+
121+ ``` php
122+ $sitemapFactory->setBaseUrl('http://foo.com/sitemaps/');
123+ ```
124+
125+ You can get the current base URL using ` getBaseUrl() ` .
126+
127+ #### Creating a Sitemap
128+
129+ To create a sitemap you use the ` createSitemap ` method. This method requires an ` Iterator ` as
130+ its only parameter.
131+
132+ ``` php
133+ <?php
134+
135+ use League\Flysystem\Filesystem;
136+ use League\Flysystem\Adapter\Local as LocalAdapter;
137+
138+ $adapter = new LocalAdapter(__DIR__.'/sitemaps');
139+ $filesystem = new Filesystem($adapter);
140+ $sitemapFactory = new Tackk\Cartographer\SitemapFactory($filesystem);
141+
142+ // Create an Iterator of your URLs somehow.
143+ $urls = get_url_iterator();
144+
145+ // Returns the URL to the main Sitemap/Index file
146+ $mainSitemap = $sitemapFactory->createSitemap($urls);
147+
148+ ```
149+
150+ #### Return Value
151+
152+ The two creation methods (` createSitemap ` and ` createSitemapIndex ` ) will return the URL
153+ of the root sitemap file. If there is only 1 sitemap created, it will return just that URL.
154+ If multiple sitemaps are created, then a Sitemap Index is generated and the URL to that is returned.
155+
156+
125157## Running Tests
126158
127159* This assumes you have ran ` composer update ` .*
0 commit comments