Skip to content
Permalink
Browse files

Add the ability to add comments to the output.

  • Loading branch information...
Mathew Davies
Mathew Davies committed Jun 24, 2018
1 parent e0a6e68 commit ed59d385747ace39bd42808538dc77b4868eb3a6
Showing with 43 additions and 1 deletion.
  1. +22 −0 README.md
  2. +5 −0 src/Drivers/XmlWriterDriver.php
  3. +16 −1 tests/Drivers/XmlWriterDriverTest.php
@@ -113,3 +113,25 @@ Which will add before the document starts.
```


**Comments**

Comments are useful for information such as when the file was created.

```php
<?php declare(strict_types=1);
use Thepixeldeveloper\Sitemap\Drivers\XmlWriterDriver;
$date = date('Y-m-d H:i:s');
$driver = new XmlWriterDriver();
$driver->addComment('This XML file was written on ' . $date . '. Bye!');
```

Which will render out.

``` xml
<?xml version="1.0" encoding="UTF-8"?>
<!--This XML file was written on 2018-06-24 15:57:23. Bye!-->
```

@@ -77,6 +77,11 @@ public function addProcessingInstructions(string $target, string $content)
$this->writer->writePI($target, $content);
}
public function addComment(string $comment)
{
$this->writer->writeComment($comment);
}
private function writeElement(string $name, $content)
{
if (!$content) {
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace Tests\Thepixeldeveloper\Sitemap\Drivers;
@@ -29,6 +29,21 @@ public function testProcessingInstructions()
$this->assertSame($expected, $driver->output());
}
public function testComments()
{
$date = date('Y-m-d H:i:s');
$driver = new XmlWriterDriver();
$driver->addComment('This XML file was written on ' . $date . '. Bye!');
$expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<!--This XML file was written on $date. Bye!-->
XML;
$this->assertSame($expected, $driver->output());
}
public function testSitemapIndex()
{
$sitemapIndex = new SitemapIndex();

0 comments on commit ed59d38

Please sign in to comment.
You can’t perform that action at this time.