test
This commit is contained in:
parent
6a8f33fcc9
commit
4dbf9aec32
64
parse2.php
Normal file
64
parse2.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
$content = file_get_contents('api/order.php');
|
||||
|
||||
$tokens = token_get_all($content);
|
||||
$vars = [];
|
||||
$prepares = [];
|
||||
for ($idx = 0; $idx < count($tokens); $idx++) {
|
||||
$token = $tokens[$idx];
|
||||
if (is_array($token) && $token[1] === 'prepare') {
|
||||
// find the variable before ->
|
||||
$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";
|
||||
}
|
||||
}
|
||||
|
||||
20
parse_pdo.php
Normal file
20
parse_pdo.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$content = file_get_contents('api/order.php');
|
||||
$lines = explode("\n", $content);
|
||||
|
||||
$prepares = [];
|
||||
foreach($lines as $i => $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";
|
||||
30
pos_test.php
Normal file
30
pos_test.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$data = [
|
||||
"order_id" => 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);
|
||||
|
||||
30
pos_test2.php
Normal file
30
pos_test2.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$data = [
|
||||
"order_id" => 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);
|
||||
|
||||
30
pos_test3.php
Normal file
30
pos_test3.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$data = [
|
||||
"order_id" => 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);
|
||||
|
||||
30
pos_test4.php
Normal file
30
pos_test4.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
$data = [
|
||||
"order_id" => 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);
|
||||
|
||||
21
test_prepare.php
Normal file
21
test_prepare.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require_once 'db/config.php';
|
||||
try {
|
||||
$pdo = db();
|
||||
$q = "UPDATE orders SET
|
||||
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 = 'pending'
|
||||
WHERE id = ?";
|
||||
$stmt = $pdo->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();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user