Overview

Namespaces

  • PHP
  • XSLTBenchmarking
    • Reports
    • RunnerConsole
    • TestsGenerator
    • TestsRunner

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

  • IParamsDriver
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  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.23 - PHP"
 18:  *
 19:  * @author Viktor Mašíček <viktor@masicek.net>
 20:  */
 21: class Libxslt1123phpProcessorDriver 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 TRUE;
 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.23)|(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_WIN:
 99:                 $prefix = '"[LIBS]\Php\5.3.6\php.exe" -n -d extension="[PROCESSORS]\libxslt\1.1.23\php_xsl.dll"';
100:                 break;
101: 
102:             case self::OS_LINUX:
103:                 $prefix = $this->getLinuxCommandPrefix();
104:                 break;
105: 
106:         }
107: 
108:         $phpScript =
109:             'function errorHandler($errno, $errstr)' .
110:             '{' .
111:             '   throw new \ErrorException(\'Transformation failed: \' . $errstr);' .
112:             '}' .
113:             'set_error_handler(\'errorHandler\');' .
114:             '$errorMessage = \'\';' .
115:             'try {' .
116:             '   libxml_use_internal_errors(TRUE);' .
117:             '   $processor = new \XSLTProcessor();' .
118:             '   $processor->importStylesheet(new \SimpleXMLElement(\'[XSLT]\', 0, TRUE));' .
119:             '   $outputXml = $processor->transformToXml(new \SimpleXMLElement(\'[INPUT]\', 0, TRUE));' .
120:             '   file_put_contents(\'[OUTPUT]\', $outputXml);' .
121:             '}' .
122:             'catch (\ErrorException $e)' .
123:             '{' .
124:             '   restore_error_handler();' .
125:             '   $errorMessage = $e->getMessage();' .
126:             '}' .
127:             'catch (\Exception $e)' .
128:             '{' .
129:             '   restore_error_handler();' .
130:             '   $error = libxml_get_last_error();' .
131:             '   $errorMessage = $error->message . \': line \' . $error->line . \', column \' . $error->column . \', file \' . $error->file;' .
132:             '}' .
133:             'restore_error_handler();' .
134:             'if ($errorMessage)' .
135:             '{' .
136:             '   file_put_contents(\'[ERROR]\', $errorMessage);' .
137:             '}'
138:         ;
139: 
140:         if (PHP_OS == self::OS_LINUX)
141:         {
142:             $phpScript = str_replace('\\', '\\\\', $phpScript);
143:             $phpScript = str_replace('$', '\\$', $phpScript);
144:         }
145: 
146:         $commandTemplate = $prefix . ' -r "' . $phpScript . '"';
147: 
148:         return $commandTemplate;
149:     }
150: 
151: 
152:     /**
153:      * Full name of processor (with version)
154:      *
155:      * @return string
156:      */
157:     public function getFullName()
158:     {
159:         return 'libxslt 1.1.23 - PHP';
160:     }
161: 
162: 
163:     /**
164:      * Return name of processor kernel.
165:      * Available kernels are const of this class with prefix "KERNEL_"
166:      *
167:      * Examples:
168:      * Saxon 6.5.5 -> Saxon
169:      * xsltproc -> libxslt
170:      *
171:      * @return string
172:      */
173:     public function getKernel()
174:     {
175:         return self::KERNEL_LIBXSLT;
176:     }
177: 
178: 
179:     /**
180:      * Return prefix of command for running PHP on Linux with extension XSL.
181:      * It expected, that XSL extnesion is available as buildin extension or included.
182:      *
183:      * @return string
184:      */
185:     private function getLinuxCommandPrefix()
186:     {
187:         if (!self::$linuxCommandPrefix)
188:         {
189:             exec('find /usr/lib/php5/ -type f | grep \'/xsl.so\'', $output);
190:             if (isset($output[0]) || $output[0])
191:             {
192:                 self::$linuxCommandPrefix = 'php -n -d extension="' . $output[0] . '"';
193:             }
194:             else
195:             {
196:                 self::$linuxCommandPrefix = 'php -n';
197:             }
198:         }
199:         return self::$linuxCommandPrefix;
200:     }
201: 
202: 
203: }
204: 
XSTL Benchmarking API documentation generated by ApiGen.
Generated using the TokenReflection library.