Overview
Namespaces
Classes
- AMemoryUsageDriver
- AProcessorDriver
- Controlor
- Libxslt1123phpProcessorDriver
- Libxslt1126phpProcessorDriver
- LinuxMemoryUsageDriver
- MemoryUsage
- MSXML30ProcessorDriver
- MSXML60ProcessorDriver
- Params
- Processor
- Runner
- Sablotron103cmdProcessorDriver
- Saxon655ProcessorDriver
- SaxonHE9402ProcessorDriver
- Test
- TestRunner
- WindowsMemoryUsageDriver
- Xalan271ProcessorDriver
- XmlParamsDriver
- Xsltproc1123ProcessorDriver
- Xsltproc1126ProcessorDriver
- XT20051206ProcessorDriver
Interfaces
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\TestsRunner;
11:
12: // @codeCoverageIgnoreStart
13: require_once __DIR__ . '/AProcessorDriver.php';
14: // @codeCoverageIgnoreEnd
15:
16: /**
17: * Driver for "libxslt 1.1.26 - PHP"
18: *
19: * @author Viktor Mašíček <viktor@masicek.net>
20: */
21: class Libxslt1126phpProcessorDriver extends AProcessorDriver
22: {
23:
24:
25: /**
26: * Prefix of command for running PHP on Linux with extension XSL.
27: *
28: * @var string
29: */
30: static private $linuxCommandPrefix = '';
31:
32:
33: /**
34: * Return flag, if the driver is available.
35: *
36: * @return bool
37: */
38: public function isAvailable()
39: {
40: switch (PHP_OS)
41: {
42: case self::OS_WIN:
43: return FALSE;
44: break;
45:
46: case self::OS_LINUX:
47: $available = FALSE;
48:
49: // php is needed
50: exec('php -v 2> /dev/null | grep \'PHP\' | wc -l', $output);
51: if ($output[0] != '0')
52: {
53: $available = TRUE;
54: }
55:
56: if ($available)
57: {
58: // xsl extension is needed
59: $output = NULL;
60: exec('php --ri xsl | grep -P \'(libxslt Version => 1.1.26)|(XSL => enabled)\' | wc -l', $output);
61: if ($output[0] == '2')
62: {
63: $available = TRUE;
64: }
65: else
66: {
67: $available = FALSE;
68: }
69: }
70:
71: return $available;
72:
73: break;
74:
75: default:
76: return FALSE;
77: break;
78: }
79: }
80:
81:
82: /**
83: * Return template of command
84: *
85: * Templates substitutions:
86: * [XSLT] = path of XSLT template for transformation
87: * [INPUT] = path of input XML file
88: * [OUTPUT] = path of generated output XML file
89: * [ERROR] = path of file for eventual generated error message
90: * [LIBS] = path of directory containing XSLT processors (libraries, command-line program etc.)
91: *
92: * @return string
93: */
94: public function getCommandTemplate()
95: {
96: switch (PHP_OS)
97: {
98: case self::OS_LINUX:
99: $prefix = $this->getLinuxCommandPrefix();
100: break;
101:
102: }
103:
104: $phpScript =
105: 'function errorHandler($errno, $errstr)' .
106: '{' .
107: ' throw new \ErrorException(\'Transformation failed: \' . $errstr);' .
108: '}' .
109: 'set_error_handler(\'errorHandler\');' .
110: '$errorMessage = \'\';' .
111: 'try {' .
112: ' libxml_use_internal_errors(TRUE);' .
113: ' $processor = new \XSLTProcessor();' .
114: ' $processor->importStylesheet(new \SimpleXMLElement(\'[XSLT]\', 0, TRUE));' .
115: ' $outputXml = $processor->transformToXml(new \SimpleXMLElement(\'[INPUT]\', 0, TRUE));' .
116: ' file_put_contents(\'[OUTPUT]\', $outputXml);' .
117: '}' .
118: 'catch (\ErrorException $e)' .
119: '{' .
120: ' restore_error_handler();' .
121: ' $errorMessage = $e->getMessage();' .
122: '}' .
123: 'catch (\Exception $e)' .
124: '{' .
125: ' restore_error_handler();' .
126: ' $error = libxml_get_last_error();' .
127: ' $errorMessage = $error->message . \': line \' . $error->line . \', column \' . $error->column . \', file \' . $error->file;' .
128: '}' .
129: 'restore_error_handler();' .
130: 'if ($errorMessage)' .
131: '{' .
132: ' file_put_contents(\'[ERROR]\', $errorMessage);' .
133: '}'
134: ;
135:
136: if (PHP_OS == self::OS_LINUX)
137: {
138: $phpScript = str_replace('\\', '\\\\', $phpScript);
139: $phpScript = str_replace('$', '\\$', $phpScript);
140: }
141:
142: $commandTemplate = $prefix . ' -r "' . $phpScript . '"';
143:
144: return $commandTemplate;
145: }
146:
147:
148: /**
149: * Full name of processor (with version)
150: *
151: * @return string
152: */
153: public function getFullName()
154: {
155: return 'libxslt 1.1.26 - PHP';
156: }
157:
158:
159: /**
160: * Return name of processor kernel.
161: * Available kernels are const of this class with prefix "KERNEL_"
162: *
163: * Examples:
164: * Saxon 6.5.5 -> Saxon
165: * xsltproc -> libxslt
166: *
167: * @return string
168: */
169: public function getKernel()
170: {
171: return self::KERNEL_LIBXSLT;
172: }
173:
174:
175: /**
176: * Return prefix of command for running PHP on Linux with extension XSL.
177: * It expected, that XSL extnesion is available as buildin extension or included.
178: *
179: * @return string
180: */
181: private function getLinuxCommandPrefix()
182: {
183: if (!self::$linuxCommandPrefix)
184: {
185: exec('find /usr/lib/php5/ -type f | grep \'/xsl.so\'', $output);
186: if (isset($output[0]) || $output[0])
187: {
188: self::$linuxCommandPrefix = 'php -n -d extension="' . $output[0] . '"';
189: }
190: else
191: {
192: self::$linuxCommandPrefix = 'php -n';
193: }
194: }
195: return self::$linuxCommandPrefix;
196: }
197:
198:
199: }
200: