1 : <?php
2 :
3 : /**
4 : * XSLT Benchmarking
5 : * @link https://github.com/masicek/XSLT-Benchmarking
6 : * @author Viktor Mašíček <viktor@masicek.net>
7 : * @license "New" BSD License
8 : */
9 :
10 : namespace XSLTBenchmarking\TestsGenerator;
11 :
12 : require_once __DIR__ . '/IXmlGeneratorDriver.php';
13 :
14 : /**
15 : * Driver for generating XML files by \SimpleXMLElement.
16 : * Generate only list of elements by settings.
17 : *
18 : * @author Viktor Mašíček <viktor@masicek.net>
19 : */
20 : class EasyXmlGeneratorDriver implements IXmlGeneratorDriver
21 : {
22 :
23 :
24 : /**
25 : * Object configuration
26 : *
27 : * @param string $tmpDirectory The path of the temporary directory
28 : */
29 : public function __construct($tmpDirectory)
30 : {
31 0 : }
32 :
33 :
34 : /**
35 : * Generate xml file
36 : *
37 : * @param string $outputPath The path of the output xml file
38 : * @param array $settings The list of settings specific by selected xml generator
39 : *
40 : * @return void
41 : */
42 : public function generate($outputPath, $templateDir, array $settings)
43 : {
44 1 : $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>');
45 :
46 1 : foreach ($settings as $elementName => $count)
47 : {
48 1 : for ($elementIdx = 1; $elementIdx <= $count; $elementIdx++)
49 : {
50 1 : $xml->addChild($elementName, 'Easy element ' . $elementIdx);
51 1 : }
52 1 : }
53 :
54 : // make indent and new lines
55 1 : $dom = dom_import_simplexml($xml)->ownerDocument;
56 1 : $dom->formatOutput = TRUE;
57 1 : $dom->save($outputPath);
58 1 : }
59 :
60 :
61 : }
|