function testXmlReader() { $config = <<<XML <config> <file dir="test/test1">*.*</file> </config> XML; $class = new ReflectionClass('preprocessor'); $opt = $class->getProperty('store'); $opt->setAccessible(true); $this->createTestFiles(4, 'test/test1'); $preprocessor = preprocessor::instance(); $preprocessor->xml_read($config); $store = $opt->getValue($preprocessor); $this->assertEquals(count($store), 4); $config = <<<XML1 <config> <remove>test1\\*1.tmp</remove> </config> XML1; $preprocessor->xml_read($config); $store = $opt->getValue($preprocessor); $this->assertEquals(count($store), 3); $this->removeTestFiles('test/test1'); }
<?php /** * to call preprocesor - type php -f preprocessor.php file_name * * <%=point('hat','jscomment');%> */ include_once "../preprocessor.class.php"; include_once "../point.ext.php"; $paths = preprocessor::instance(); $par = array("/Dtarget=debug", "/Ddst=build", "config.xml"); for ($i = 1; $i < count($par); $i++) { if (preg_match('/^\\/D(\\w+)\\=(\\S+)$/', $par[$i], $m)) { $paths->export($m[1], $m[2]); } else { if (is_file($par[$i])) { $arg1 = pathinfo($par[$i]); if ($arg1['extension'] == 'xml') { $paths->xml_read($par[$i]); } else { $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <config> \t<files dstdir="build"> \t\t<file>{$par[$i]}</file> \t</files> </config> XML; $paths->xml_read($xmlstr); } } else {
*/ $dir = dirname(__FILE__); include_once $dir . "/preprocessor.class.php"; include_once $dir . "/point.ext.php"; date_default_timezone_set('Europe/Moscow'); /** * @param $p * @param $def * @return mixed * @tutorial preprocessor.pkg */ function pps(&$p, $def) { return empty($p) ? $def : $p; } $preprocessor = preprocessor::instance(); foreach ($_ENV as $k => $v) { $preprocessor->export('env_' . $k, $v); } echo '<%=$version%> '; $arg = ''; for ($i = 1; $i < $argc; $i++) { $arg .= ' ' . $argv[$i]; } //echo $arg; while (!empty($arg)) { //$preprocessor->debug($arg); if (preg_match('#^/force(?:\\s|\\=\'([^\']+)\')#', $arg, $m)) { $time = false;
public static function log($level = -1) { $preprocessor = preprocessor::instance(); if ($preprocessor->logLevel < $level) { return; } $na = func_num_args(); if ($na > 1) { for ($i = 1; $i < $na; $i++) { $v = func_get_arg($i); if (is_array($v)) { $v = print_r($v, true); } $preprocessor->logs[] = array($level, $v); } } //if($na==0){ print_r($this->logs);} if ($preprocessor->obcnt == 0 && count($preprocessor->logs) > 0) { foreach ($preprocessor->logs as $v) { if (!empty($v[1])) { echo $v[1]; } } $preprocessor->logs = array(); } }
public function init() { $this->preprocessor = preprocessor::instance(); }
/** * ловим ошибку - вставка кода в // комментарии */ function testPOINTComment() { $data = <<<HTML <?xml version='1.0' standalone='yes'?> <config> <files dstdir='tests'> <echo name="xx.txt"><![CDATA[ /* <% POINT::start('xxx');%> it's a text <% POINT::finish();%> */ // <%=POINT::get('xxx');%> ## <%=POINT::get('xxx');%> /* <%=POINT::get('xxx');%> */ ]]></echo> </files> </config> HTML; $result = <<<HTML // ---- point::xxx ---- it's a text ## ---- point::xxx ---- it's a text /* --- point::xxx --- */ it's a text HTML; $preprocessor = preprocessor::instance(); $preprocessor->xml_read($data); $preprocessor->process(); $data = file_get_contents('tests/xx.txt'); $this->assertEquals($this->nl2nl($result), $this->nl2nl($data)); POINT::clear(); unlink('tests/xx.txt'); }