Skip to content

Commit

Permalink
allow omitting of leading xml tag (#48)
Browse files Browse the repository at this point in the history
* feat(writer): allow omitting of leading xml tag

In some use-cases it is useful to group multiple svg into one larger
svg. However, in this we need to omit the <?xml tag from the child svg.

* fix: expose $standalone flag in toXMLString

Since most external applications will not instantiate SVGWriter directly,
the flag should be exposed to common methods that could use it.
  • Loading branch information
micgro42 authored and meyfa committed Mar 7, 2018
1 parent e309858 commit fe8c9d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/SVGImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public function __toString()
* same XML string generated by this method, since the output is optimized
* and formatted according to specific rules.
*
* @param bool $standalone optional, false omits the leading <?xml tag
*
* @return string This image's document tree as an XML string.
*/
public function toXMLString()
public function toXMLString($standalone = true)
{
$writer = new SVGWriter();
$writer = new SVGWriter($standalone);
$writer->writeNode($this->document);

return $writer->getString();
Expand Down
8 changes: 5 additions & 3 deletions src/Writing/SVGWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
class SVGWriter
{
/** @var string $outString The XML output string being written */
private $outString;
private $outString = '';

public function __construct()
public function __construct($isStandalone = true)
{
$this->outString = '<?xml version="1.0" encoding="utf-8"?>';
if ($isStandalone) {
$this->outString = '<?xml version="1.0" encoding="utf-8"?>';
}
defined('ENT_XML1') ? ENT_XML1 : define('ENT_XML1', 16);
}

Expand Down

0 comments on commit fe8c9d9

Please sign in to comment.