Passed
Pull Request — master (#195)
by
unknown
19:02
created

DocumentTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 24 4
1
<?php
2
namespace EWW\Dpf\Services\Transformer;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
class DocumentTransformer
18
{
19
20
    public function transform($xslt, $xml, $params = [])
21
    {
22
        $xslDoc = new \DOMDocument();
23
        $xslDoc->load($xslt);
24
25
        $xmlDoc = new \DOMDocument();
26
        $xmlDoc->loadXML($xml);
27
28
        $processor = new \XSLTProcessor();
29
30
        foreach ($params as $key => $value) {
31
            $processor->setParameter('', $key, $value);
32
        }
33
34
        libxml_use_internal_errors(true);
35
        $result = $processor->importStyleSheet($xslDoc);
36
        if (!$result) {
37
            foreach (libxml_get_errors() as $error) {
38
                echo "Libxml error: {$error->message}\n";
39
            }
40
        }
41
        libxml_use_internal_errors(false);
42
43
        return $processor->transformToXml($xmlDoc);
44
    }
45
46
}