22
33[ ![ CI] ( https://github.com/RumenDamyanov/php-sitemap/actions/workflows/ci.yml/badge.svg )] ( https://github.com/RumenDamyanov/php-sitemap/actions )
44[ ![ codecov] ( https://codecov.io/gh/RumenDamyanov/php-sitemap/branch/master/graph/badge.svg )] ( https://codecov.io/gh/RumenDamyanov/php-sitemap )
5+ [ ![ PHP Version] ( https://img.shields.io/badge/PHP-8.2%2B-blue.svg )] ( https://php.net )
6+ [ ![ License] ( https://img.shields.io/badge/license-MIT-green.svg )] ( LICENSE.md )
57
68** php-sitemap** is a modern, framework-agnostic PHP package for generating sitemaps in XML, TXT, HTML, and Google News formats. It works seamlessly with Laravel, Symfony, or any PHP project. Features include high test coverage, robust CI, extensible adapters, and support for images, videos, translations, alternates, and Google News.
79
1315- ** Framework-agnostic** : Use in Laravel, Symfony, or any PHP project
1416- ** Multiple formats** : XML, TXT, HTML, Google News, mobile
1517- ** Rich content** : Supports images, videos, translations, alternates, Google News
16- - ** Modern PHP** : Type-safe, extensible, and robust
18+ - ** Modern PHP** : Type-safe, extensible, and robust (PHP 8.2+)
1719- ** High test coverage** : 100% code coverage, CI/CD ready
1820- ** Easy integration** : Simple API, drop-in for controllers/routes
1921- ** Extensible** : Adapters for Laravel, Symfony, and more
22+ - ** Quality tools** : PHPStan Level 6, PSR-12, comprehensive testing
23+
24+ ---
25+
26+ ## Quick Links
27+
28+ - 📖 [ Installation] ( #installation )
29+ - 🚀 [ Usage Examples] ( #usage )
30+ - 🧪 [ Testing & Development] ( #testing--development )
31+ - 🤝 [ Contributing] ( CONTRIBUTING.md )
32+ - 🔒 [ Security Policy] ( SECURITY.md )
33+ - 💝 [ Support & Funding] ( FUNDING.md )
34+ - 📄 [ License] ( #license )
2035
2136---
2237
@@ -44,7 +59,10 @@ public function sitemap(Sitemap $sitemap)
4459 ['url' => 'https://example.com/img/about.jpg', 'title' => 'About Us']
4560 ]);
4661 // Add more items as needed...
47- return response($sitemap->render('xml'), 200, ['Content-Type' => 'application/xml']);
62+
63+ // Render XML using a view template
64+ $items = $sitemap->getModel()->getItems();
65+ return response()->view('sitemap.xml', compact('items'), 200, ['Content-Type' => 'application/xml']);
4866}
4967```
5068
@@ -94,7 +112,10 @@ class SitemapController
94112 $sitemap->add('https://example.com/', (new \DateTime())->format(DATE_ATOM), '1.0', 'daily');
95113 $sitemap->add('https://example.com/contact', (new \DateTime())->format(DATE_ATOM), '0.5', 'monthly');
96114 // Add more items as needed...
97- return new Response($sitemap->render('xml'), 200, ['Content-Type' => 'application/xml']);
115+
116+ // Render XML
117+ $xml = $sitemap->renderXml();
118+ return new Response($xml, 200, ['Content-Type' => 'application/xml']);
98119 }
99120}
100121```
@@ -122,8 +143,10 @@ $sitemap->add('https://example.com/', date('c'), '1.0', 'daily');
122143$sitemap->add('https://example.com/products', date('c'), '0.9', 'weekly', [
123144 ['url' => 'https://example.com/img/product.jpg', 'title' => 'Product Image']
124145]);
146+
147+ // Output XML
125148header('Content-Type : application/xml');
126- echo $sitemap->render('xml' );
149+ echo $sitemap->renderXml( );
127150```
128151
129152---
@@ -149,11 +172,13 @@ $sitemap->add(
149172 alternates: [['media' => 'print', 'url' => 'https://example.com/news-print']]
150173);
151174
152- // Render as TXT
153- file_put_contents('sitemap.txt', $sitemap->render('txt'));
175+ // Generate XML using renderXml() method
176+ $xml = $sitemap->renderXml();
177+ file_put_contents('sitemap.xml', $xml);
154178
155- // Render as HTML
156- file_put_contents('sitemap.html', $sitemap->render('html'));
179+ // Or use view templates for more control (create your own views based on src/views/)
180+ $items = $sitemap->getModel()->getItems();
181+ // Pass $items to your view template
157182```
158183
159184---
@@ -207,12 +232,116 @@ $sitemap->addItem([
207232
208233---
209234
210- ## Testing
235+ ## Rendering Options
236+
237+ The package provides multiple ways to generate sitemap output:
238+
239+ ### 1. Built-in XML Renderer (Simple)
240+
241+ ``` php
242+ $sitemap = new Sitemap();
243+ $sitemap->add('https://example.com/', date('c'), '1.0', 'daily');
244+ $xml = $sitemap->renderXml(); // Returns XML string
245+ ```
246+
247+ ### 2. View Templates (Flexible)
248+
249+ For more control, use the included view templates or create your own:
250+
251+ ``` php
252+ $sitemap = new Sitemap();
253+ $sitemap->add('https://example.com/', date('c'), '1.0', 'daily');
254+
255+ // Get the data for your view
256+ $items = $sitemap->getModel()->getItems();
257+
258+ // Laravel: Use response()->view() or view()->render()
259+ return response()->view('sitemap.xml', compact('items'), 200, ['Content-Type' => 'application/xml']);
260+
261+ // Symfony: Use Twig templates
262+ return $this->render('sitemap.xml.twig', ['items' => $items], new Response('', 200, ['Content-Type' => 'application/xml']));
263+
264+ // Generic PHP: Include view templates
265+ ob_start();
266+ include 'vendor/rumenx/php-sitemap/src/views/xml.php';
267+ $xml = ob_get_clean();
268+ ```
269+
270+ ** Available view templates** in ` src/views/ ` :
271+
272+ - ` xml.php ` - Standard XML sitemap
273+ - ` xml-mobile.php ` - Mobile-specific sitemap
274+ - ` google-news.php ` - Google News sitemap
275+ - ` sitemapindex.php ` - Sitemap index
276+ - ` txt.php ` - Plain text format
277+ - ` html.php ` - HTML format
278+
279+ ## Testing & Development
280+
281+ ### Running Tests
211282
212283``` bash
213- ./vendor/bin/pest
284+ # Run all tests
285+ composer test
286+
287+ # Run tests with text coverage report
288+ composer coverage
289+
290+ # Generate full HTML coverage report
291+ composer coverage-html
292+ ```
293+
294+ ### Code Quality
295+
296+ ``` bash
297+ # Run static analysis (PHPStan Level 6)
298+ composer analyze
299+
300+ # Check coding standards (PSR-12)
301+ composer style
302+
303+ # Auto-fix coding standards
304+ composer style-fix
214305```
215306
307+ ### Manual Testing
308+
309+ ``` bash
310+ # Run specific test file
311+ ./vendor/bin/pest tests/Unit/SitemapTest.php
312+
313+ # Run tests in watch mode
314+ ./vendor/bin/pest --watch
315+ ```
316+
317+ ---
318+
319+ ## Contributing
320+
321+ We welcome contributions! Please see our [ Contributing Guide] ( CONTRIBUTING.md ) for details on:
322+
323+ - Development setup
324+ - Coding standards
325+ - Testing requirements
326+ - Pull request process
327+
328+ ---
329+
330+ ## Security
331+
332+ If you discover a security vulnerability, please review our [ Security Policy] ( SECURITY.md ) for responsible disclosure guidelines.
333+
334+ ---
335+
336+ ## Support
337+
338+ If you find this package helpful, consider:
339+
340+ - ⭐ Starring the repository
341+ - 💝 [ Supporting development] ( FUNDING.md )
342+ - 🐛 [ Reporting issues] ( https://github.com/RumenDamyanov/php-sitemap/issues )
343+ - 🤝 [ Contributing improvements] ( CONTRIBUTING.md )
344+
216345---
217346
218347## License
0 commit comments