Пример #1
0
 public static function load($input)
 {
     $file = '';
     if (strpos($input, "\n") === false && is_file($input)) {
         if (false === is_readable($input)) {
             throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input));
         }
         $file = $input;
         $input = file_get_contents($file);
     }
     $parser = new Parser();
     return $parser->load($input);
 }
Пример #2
0
 function testDumpLoad()
 {
     $tokens = ['d' => '[0-9]+', 'a', 'b', 'c', 'sp' => '\\s+'];
     $rules = ['A' => [[['d', ['+', ['|', 'a', 'b']], 'B'], true]], 'B' => [[['d'], true]]];
     $lexer = new Lexer($tokens);
     $parser = new Parser();
     $parser->setLexer($lexer);
     $parser->init($rules);
     $parser->setSkipTokens(['sp']);
     $data = $parser->dump();
     $s = serialize($data);
     $e = var_export($data, true);
     $parser = new Parser();
     $parser->setLexer($lexer);
     $v = eval("return {$e};");
     $parser->load($v);
     $parser->tree('123 a a b 1244');
     $parser = new Parser();
     $parser->setLexer($lexer);
     $data = unserialize($s);
     $parser->load($data);
     $parser->tree('123 a a b 1244');
     ob_start();
     $parser->printTree('123 a a b 1244');
     $text = ob_get_clean();
     $this->assertTrue(is_string($text));
 }
Пример #3
0
include OLIB_PATH . '/class.parser.php';
include OLIB_PATH . '/class.printjob.php';
include OLIB_PATH . '/class.cfg.php';
error_reporting(E_ERROR);
// setlocale(LC_ALL, 'ru_RU');
function toUnixTimestamp($d, $t)
{
    return mktime(substr($t, 0, 2), substr($t, 3, 2), 0, substr($d, 3, 2), substr($d, 0, 2), substr($d, 6, 4));
}
$fn = '/home/webserver/PCOUNTER.LOG';
//$fn			= '/home/webserver/PCOUNTER_2010_06.LOG';
$cn = 'printjoblogposition';
$tst = new Parser(array('username', 'document', 'prnname', 'date', 'time', 'pc', 'f1', 'f2', 'paper', 'param', 'size', 'pages', 'n1', 'n2'), ',');
$tst->fileOpen($fn, $cn);
while ($str = $tst->fileStr()) {
    $tst->load($str);
    $ora = new PrintJob();
    $ora->username[0] = substr($tst->username, 4);
    $ora->docum[0] = convert_cyr_string(addslashes(str_replace('\'', '', $tst->document)), 'd', 'w');
    $ora->prnname[0] = substr($tst->prnname, strpos($tst->prnname, '\\', 3) + 1);
    $ora->pcname[0] = substr($tst->pc, 2);
    $ora->paper[0] = $tst->paper;
    $ora->pages[0] = $tst->pages;
    $ora->bsize[0] = $tst->size;
    $ora->time[0] = toUnixTimestamp($tst->date, $tst->time);
    $param = explode('/', $tst->param);
    $ora->jt[0] = substr($param[1], 3);
    $ora->cp[0] = substr($param[2], 3);
    $ora->ts[0] = substr($param[3], 3);
    $ora->count = 1;
    $ora->insert();
Пример #4
0
 /**
  * Load method data from yaml file
  * @param $file
  */
 protected function loadFromYml($file)
 {
     $this->parser = new Parser($file);
     $this->parser->load($this);
 }
Пример #5
0
    {
        if ($this->errorHandlerIsActive) {
            set_error_handler([$this, 'errorHandler']);
        }
        $this->getDom()->loadXML($string);
        if ($this->errorHandlerIsActive) {
            restore_error_handler();
        }
        return $this;
    }
    /**
     * Custom XML lib error handler
     *
     * @param int $errorNo
     * @param string $errorStr
     * @param string $errorFile
     * @param int $errorLine
     * @throws \Magento\Framework\Exception\LocalizedException
     * @return void
     */
    public function errorHandler($errorNo, $errorStr, $errorFile, $errorLine)
    {
        if ($errorNo != 0) {
            $message = "{$errorStr} in {$errorFile} on line {$errorLine}";
        }
    }
}
$Parser = new Parser();
$Parser->load('welcome.xml');
$data = $Parser->xmlToArray();
print_r($data['page']);