From 4dbf9aec32f563c7c2b63e811c7dabd0bea326fb Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Fri, 3 Apr 2026 10:38:17 +0000 Subject: [PATCH] test --- parse2.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ parse_pdo.php | 20 +++++++++++++++ pos_test.php | 30 +++++++++++++++++++++++ pos_test2.php | 30 +++++++++++++++++++++++ pos_test3.php | 30 +++++++++++++++++++++++ pos_test4.php | 30 +++++++++++++++++++++++ test_prepare.php | 21 ++++++++++++++++ 7 files changed, 225 insertions(+) create mode 100644 parse2.php create mode 100644 parse_pdo.php create mode 100644 pos_test.php create mode 100644 pos_test2.php create mode 100644 pos_test3.php create mode 100644 pos_test4.php create mode 100644 test_prepare.php diff --git a/parse2.php b/parse2.php new file mode 100644 index 0000000..6b82c59 --- /dev/null +++ b/parse2.php @@ -0,0 +1,64 @@ + + $var_idx = $idx - 2; + while ($var_idx >= 0 && (!is_array($tokens[$var_idx]) || $tokens[$var_idx][0] !== T_VARIABLE)) { + $var_idx--; + } + $var_name = is_array($tokens[$var_idx]) ? $tokens[$var_idx][1] : 'unknown'; + + $assign_var = 'unknown'; + $assign_idx = $var_idx - 1; + while ($assign_idx >= 0 && $tokens[$assign_idx] !== '=') { + $assign_idx--; + } + if ($tokens[$assign_idx] === '=') { + $left_idx = $assign_idx - 1; + while ($left_idx >= 0 && (!is_array($tokens[$left_idx]) || $tokens[$left_idx][0] !== T_VARIABLE)) { + $left_idx--; + } + $assign_var = is_array($tokens[$left_idx]) ? $tokens[$left_idx][1] : 'unknown'; + } + + $stmt_str = ""; + $j = $idx + 1; + while($j < count($tokens) && $tokens[$j] !== ';') { + $stmt_str .= is_array($tokens[$j]) ? $tokens[$j][1] : $tokens[$j]; + $j++; + } + $qmarks = substr_count($stmt_str, '?'); + $prepares[] = ['var' => $assign_var, 'qmarks' => $qmarks, 'str' => trim($stmt_str)]; + } +} + +foreach ($prepares as $p) { + echo "{$p['var']} -> {$p['qmarks']} ? \n"; +} + +echo "\n--- EXECUTIONS ---\\n"; +for ($idx = 0; $idx < count($tokens); $idx++) { + $token = $tokens[$idx]; + if (is_array($token) && $token[1] === 'execute') { + $var_idx = $idx - 2; + while ($var_idx >= 0 && (!is_array($tokens[$var_idx]) || $tokens[$var_idx][0] !== T_VARIABLE)) { + $var_idx--; + } + $var_name = is_array($tokens[$var_idx]) ? $tokens[$var_idx][1] : 'unknown'; + + $exec_str = ""; + $j = $idx + 1; + while($j < count($tokens) && $tokens[$j] !== ';') { + $exec_str .= is_array($tokens[$j]) ? $tokens[$j][1] : $tokens[$j]; + $j++; + } + echo "$var_name -> execute: " . trim($exec_str) . "\n"; + } +} + diff --git a/parse_pdo.php b/parse_pdo.php new file mode 100644 index 0000000..60ffa7a --- /dev/null +++ b/parse_pdo.php @@ -0,0 +1,20 @@ + $line) { + if (preg_match('/\$(\w+)\s*=\s*\$pdo->prepare\("(.*?)"\)/', $line, $m)) { + $prepares[$m[1]] = substr_count($m[2], '?'); + } + if (preg_match('/\$(\w+)->execute\(\[(.*?)(\s*,.*?)?\]\)/', $line, $m)) { + $q_marks = $prepares[$m[1]] ?? -1; + $exec_count = isset($m[2]) && trim($m[2]) !== '' ? count(explode(',', $m[2])) : 0; + if ($q_marks !== -1 && $q_marks !== $exec_count) { + echo "MISMATCH on line " . ($i+1) . " for $" . $m[1] . "\n"; + echo "Expected: $q_marks\n"; + echo "Got: $exec_count (" . (isset($m[2]) ? $m[2] : '') . ")\n"; + } + } +} +echo "Done.\n"; \ No newline at end of file diff --git a/pos_test.php b/pos_test.php new file mode 100644 index 0000000..06ebf41 --- /dev/null +++ b/pos_test.php @@ -0,0 +1,30 @@ + null, + "table_number" => null, + "order_type" => "takeaway", + "customer_id" => null, + "outlet_id" => 1, + "payment_type_id" => 1, + "total_amount" => 1.5, + "vat" => 0.0, + "items" => [ + [ + "product_id" => 1, + "quantity" => 1, + "unit_price" => 1.5, + "variant_id" => null, + "vat_percent" => 0, + "vat_amount" => 0 + ] + ], + "redeem_loyalty" => false +]; +$ch = curl_init('http://127.0.0.1/api/order.php'); +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +$result = curl_exec($ch); +echo "Result:\n$result\n"; +curl_close($ch); + diff --git a/pos_test2.php b/pos_test2.php new file mode 100644 index 0000000..fb6d2f9 --- /dev/null +++ b/pos_test2.php @@ -0,0 +1,30 @@ + 100, // Update mode + "table_number" => null, + "order_type" => "takeaway", + "customer_id" => null, + "outlet_id" => 1, + "payment_type_id" => 1, + "total_amount" => 1.5, + "vat" => 0.0, + "items" => [ + [ + "product_id" => 1, + "quantity" => 1, + "unit_price" => 1.5, + "variant_id" => null, + "vat_percent" => 0, + "vat_amount" => 0 + ] + ], + "redeem_loyalty" => false +]; +$ch = curl_init('http://127.0.0.1/api/order.php'); +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +$result = curl_exec($ch); +echo "Result:\n$result\n"; +curl_close($ch); + diff --git a/pos_test3.php b/pos_test3.php new file mode 100644 index 0000000..70e1fd0 --- /dev/null +++ b/pos_test3.php @@ -0,0 +1,30 @@ + null, + "table_number" => null, + "order_type" => "takeaway", + "customer_id" => 1, // Assume customer 1 exists + "outlet_id" => 1, + "payment_type_id" => 1, + "total_amount" => 1.5, + "vat" => 0.0, + "items" => [ + [ + "product_id" => 1, + "quantity" => 1, + "unit_price" => 1.5, + "variant_id" => null, + "vat_percent" => 0, + "vat_amount" => 0 + ] + ], + "redeem_loyalty" => true +]; +$ch = curl_init('http://127.0.0.1/api/order.php'); +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +$result = curl_exec($ch); +echo "Result:\n$result\n"; +curl_close($ch); + diff --git a/pos_test4.php b/pos_test4.php new file mode 100644 index 0000000..05accdc --- /dev/null +++ b/pos_test4.php @@ -0,0 +1,30 @@ + null, + "table_number" => null, + "order_type" => "dine-in", + "customer_id" => null, + "outlet_id" => 1, + "payment_type_id" => 1, + "total_amount" => 1.5, + "vat" => 0.0, + "items" => [ + [ + "product_id" => 1, + "quantity" => 1, + "unit_price" => 1.5, + "variant_id" => null, + "vat_percent" => 0, + "vat_amount" => 0 + ] + ], + "redeem_loyalty" => false +]; +$ch = curl_init('http://127.0.0.1/api/order.php'); +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +$result = curl_exec($ch); +echo "Result:\n$result\n"; +curl_close($ch); + diff --git a/test_prepare.php b/test_prepare.php new file mode 100644 index 0000000..7c8c132 --- /dev/null +++ b/test_prepare.php @@ -0,0 +1,21 @@ +prepare($q); + echo "Update params count: " . preg_match_all('/\?/', $q) . "\n"; + + $q2 = "INSERT INTO orders (source, outlet_id, table_id, table_number, order_type, customer_id, customer_name, customer_phone, car_plate, ready_time, payment_type_id, total_amount, discount, vat, user_id, commission_amount, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'pending')"; + $stmt2 = $pdo->prepare($q2); + echo "Insert params count: " . preg_match_all('/\?/', $q2) . "\n"; +} catch (Exception $e) { + echo $e->getMessage(); +} +