diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 086d622..8a8a179 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testSections":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTemplate":4,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":4},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.057,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.029,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.02,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.025,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.021,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.083,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.065,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.056,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.074,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.057,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":0.124,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testSections":0.09,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTemplate":0.111}} \ No newline at end of file +{"version":1,"defects":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":4,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testSections":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTemplate":4,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":3,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":4,"Tests\\PhpDocxTemplateTest::testRenderXml":3},"times":{"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTable":0.057,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testXmlToString":0.029,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetDocx":0.02,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testGetXml":0.025,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testPatchXml":0.021,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRenderXml":0.083,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testRender":0.065,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testLineBreak":0.056,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testCyrillic":0.074,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testForLoop":0.057,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testImages":0.124,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testSections":0.09,"Doctrine\\Tests\\DBAL\\Query\\PhpDocxTemplateTest::testTemplate":0.111,"Tests\\PhpDocxTemplateTest::testRenderXml":0.045}} \ No newline at end of file diff --git a/src/PhpDocxTemplate.php b/src/PhpDocxTemplate.php index c87bb82..9bbde55 100644 --- a/src/PhpDocxTemplate.php +++ b/src/PhpDocxTemplate.php @@ -3,6 +3,7 @@ namespace PhpDocxTemplate; use DOMDocument; +use Twig\Extension\ExtensionInterface; use Twig\Loader\ArrayLoader; use Twig\Environment; use PhpDocxTemplate\Twig\Impl\{ @@ -33,6 +34,8 @@ class PhpDocxTemplate private $picToReplace; private $picMap; + private $twigExtensions = []; + /** * Construct an instance of PhpDocxTemplate * @@ -426,6 +429,16 @@ private function cleanTags(array $matches): string ); } + /** + * Добавить пользовательское расширение + * + * @param ExtensionInterface $ext + */ + public function addTwigExtensions(ExtensionInterface $ext): void + { + $this->twigExtensions[] = $ext; + } + /** * Render xml * @@ -442,6 +455,12 @@ private function renderXml(string $srcXml, array $context): string 'index' => $srcXml, ])); + /** + * Пользовательские расширения + */ + foreach ($this->twigExtensions as $ext) { + $template->addExtension($ext); + } $ext = new ImageExtension(); $ext->setRenderer( diff --git a/tests/PhpDocxTemplateTest.php b/tests/PhpDocxTemplateTest.php index 0cdd9fc..9b62ba6 100644 --- a/tests/PhpDocxTemplateTest.php +++ b/tests/PhpDocxTemplateTest.php @@ -1,14 +1,12 @@ assertEquals( $reporter->buildXml(["object" => "world"]), "\n" . @@ -205,7 +204,7 @@ public function testRenderXml(): void "" . "" . - "\n" + "" ); $reporter->close(); }