-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.power
More file actions
97 lines (87 loc) · 2.18 KB
/
code.power
File metadata and controls
97 lines (87 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Date format to return
*
* @var string
* @since 5.0.2
*/
protected string $dateFormat = 'Y-m-d H:i:s';
/**
* Safely quote a value for database use, preserving data integrity.
*
* - Native ints/floats passed as-is
* - Clean integer strings are cast to int
* - Clean float strings are cast to float
* - Scientific notation is quoted to preserve original form
* - Leading-zero integers are quoted
* - Dates are formatted and quoted
* - Booleans are converted to TRUE/FALSE
* - Null is converted to NULL
* - All else is quoted with Joomla's db quote
*
* @param mixed $value The value to quote.
*
* @return mixed
* @since 3.2.0
*/
protected function quote($value)
{
// NULL handling
if ($value === null)
{
return 'NULL';
}
// DateTime handling
if ($value instanceof \DateTimeInterface)
{
return $this->db->quote($value->format($this->getDateFormat()));
}
// Native numeric types
if (is_int($value) || is_float($value))
{
return $value;
}
// Stringified numeric values
if (is_string($value) && is_numeric($value))
{
// Case 1: Leading-zero integers like "007"
if ($value[0] === '0' && strlen($value) > 1 && ctype_digit($value))
{
return $this->db->quote($value);
}
// Case 2: Scientific notation - preserve exact format
if (stripos($value, 'e') !== false)
{
return $this->db->quote($value);
}
// Case 3: Decimal float string (not scientific)
if (str_contains($value, '.'))
{
return (float) $value;
}
// Case 4: Pure integer string
if (ctype_digit($value))
{
return (int) $value;
}
}
// Boolean handling
if (is_bool($value))
{
return $value ? 'TRUE' : 'FALSE';
}
// Everything else
return $this->db->quote($value);
}
/**
* Get the date format used for SQL dumps.
*
* This format is used when quoting DateTimeInterface values
* to ensure consistent formatting in INSERT statements.
*
* @return string The SQL-compatible date format.
* @since 5.0.2
*/
protected function getDateFormat(): string
{
return $this->dateFormat;
}