function testParsers() { /* inputs and expected outputs */ $input_output = array('WillNotMatchAnythingEver' => array()); $chain = Parser::get_parse_chain(); foreach ($input_output as $input => $output) { $actual = $output; foreach ($chain as $class) { $obj = new $class(); $chk = $obj->check($input); $this->assertInternalType('boolean', $chk); if ($chk) { $actual = $obj->parse($input); break; } } $this->assertEquals($output, $actual); } }
/** Gather preparse modules @return array of Parser class names Scan the preparse directory for module files. Return an array of available modules. */ public static function get_preparse_chain() { return Parser::get_parse_chain('PreParser'); }
function preprocess() { $this->display = ""; $sd = MiscLib::scaleObject(); $entered = ""; if (isset($_REQUEST["reginput"])) { $entered = strtoupper(trim($_REQUEST["reginput"])); } if (substr($entered, -2) == "CL") { $entered = "CL"; } if ($entered == "RI") { $entered = CoreLocal::get("strEntered"); } if (CoreLocal::get("msgrepeat") == 1 && $entered != "CL") { $entered = CoreLocal::get("strRemembered"); CoreLocal::set('strRemembered', ''); } CoreLocal::set("strEntered", $entered); $json = array(); if ($entered != "") { if (in_array("Paycards", CoreLocal::get("PluginList"))) { /* this breaks the model a bit, but I'm putting * putting the CC parser first manually to minimize * code that potentially handles the PAN */ if (CoreLocal::get("PaycardsCashierFacing") == "1" && substr($entered, 0, 9) == "PANCACHE:") { /* cashier-facing device behavior; run card immediately */ $entered = substr($entered, 9); CoreLocal::set("CachePanEncBlock", $entered); } $pe = new paycardEntered(); if ($pe->check($entered)) { $valid = $pe->parse($entered); $entered = "PAYCARD"; CoreLocal::set("strEntered", ""); $json = $valid; } CoreLocal::set("quantity", 0); CoreLocal::set("multiple", 0); } /* FIRST PARSE CHAIN: * Objects belong in the first parse chain if they * modify the entered string, but do not process it * This chain should be used for checking prefixes/suffixes * to set up appropriate session variables. */ $parser_lib_path = $this->page_url . "parser-class-lib/"; if (!is_array(CoreLocal::get("preparse_chain"))) { CoreLocal::set("preparse_chain", PreParser::get_preparse_chain()); } foreach (CoreLocal::get("preparse_chain") as $cn) { if (!class_exists($cn)) { continue; } $p = new $cn(); if ($p->check($entered)) { $entered = $p->parse($entered); } if (!$entered || $entered == "") { break; } } if ($entered != "" && $entered != "PAYCARD") { /* * SECOND PARSE CHAIN * these parser objects should process any input * completely. The return value of parse() determines * whether to call lastpage() [list the items on screen] */ if (!is_array(CoreLocal::get("parse_chain"))) { CoreLocal::set("parse_chain", Parser::get_parse_chain()); } $result = False; foreach (CoreLocal::get("parse_chain") as $cn) { if (!class_exists($cn)) { continue; } $p = new $cn(); if ($p->check($entered)) { $result = $p->parse($entered); break; } } if ($result && is_array($result)) { // postparse chain: modify result if (!is_array(CoreLocal::get("postparse_chain"))) { CoreLocal::set("postparse_chain", PostParser::getPostParseChain()); } foreach (CoreLocal::get('postparse_chain') as $class) { if (!class_exists($class)) { continue; } $obj = new $class(); $result = $obj->parse($result); } $json = $result; if (isset($result['udpmsg']) && $result['udpmsg'] !== False) { if (is_object($sd)) { $sd->WriteToScale($result['udpmsg']); } } } else { $arr = array('main_frame' => false, 'target' => '.baseHeight', 'output' => DisplayLib::inputUnknown()); $json = $arr; if (is_object($sd)) { $sd->WriteToScale('errorBeep'); } } } } CoreLocal::set("msgrepeat", 0); if (isset($json['main_frame']) && $json['main_frame'] != False) { $this->change_page($json['main_frame']); return False; } if (isset($json['output']) && !empty($json['output'])) { $this->display = $json['output']; } if (isset($json['retry']) && $json['retry'] != False) { $this->add_onload_command("setTimeout(\"inputRetry('" . $json['retry'] . "');\", 150);\n"); } if (isset($json['receipt']) && $json['receipt'] != False) { $ref = isset($json['trans_num']) ? $json['trans_num'] : ReceiptLib::mostRecentReceipt(); $this->add_onload_command("receiptFetch('" . $json['receipt'] . "', '" . $ref . "');\n"); } if (CoreLocal::get('CustomerDisplay') === true) { $child_url = MiscLib::baseURL() . 'gui-modules/posCustDisplay.php'; $this->add_onload_command("setCustomerURL('{$child_url}');\n"); $this->add_onload_command("reloadCustomerDisplay();\n"); } return true; }
if ($p->check($entered)) { $entered = $p->parse($entered); } if (!$entered || $entered == "") { break; } } if ($entered != "" && $entered != "PAYCARD") { /* * SECOND PARSE CHAIN * these parser objects should process any input * completely. The return value of parse() determines * whether to call lastpage() [list the items on screen] */ if (!is_array(CoreLocal::get("parse_chain"))) { CoreLocal::set("parse_chain", Parser::get_parse_chain()); } $result = False; foreach (CoreLocal::get("parse_chain") as $cn) { if (!class_exists($cn)) { continue; } $p = new $cn(); if ($p->check($entered)) { $result = $p->parse($entered); break; } } if ($result && is_array($result)) { // postparse chain: modify result if (!is_array(CoreLocal::get("postparse_chain"))) {