@@ -12,8 +12,8 @@ |
||
12 | 12 | |
13 | 13 | public function validate($value) |
14 | 14 | { |
15 | - if(is_null($value) && (!$this->null)) return false; |
|
16 | - if(strlen($value) > $this->max_length) return false; |
|
15 | + if (is_null($value) && (!$this->null)) return false; |
|
16 | + if (strlen($value) > $this->max_length) return false; |
|
17 | 17 | return true; |
18 | 18 | } |
19 | 19 | } |
@@ -12,8 +12,12 @@ |
||
12 | 12 | |
13 | 13 | public function validate($value) |
14 | 14 | { |
15 | - if(is_null($value) && (!$this->null)) return false; |
|
16 | - if(strlen($value) > $this->max_length) return false; |
|
15 | + if(is_null($value) && (!$this->null)) { |
|
16 | + return false; |
|
17 | + } |
|
18 | + if(strlen($value) > $this->max_length) { |
|
19 | + return false; |
|
20 | + } |
|
17 | 21 | return true; |
18 | 22 | } |
19 | 23 | } |
@@ -3,11 +3,11 @@ |
||
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | 5 | class DateTimeField extends Field{ |
6 | - public function __construct(...$args){ |
|
6 | + public function __construct(...$args){ |
|
7 | 7 | parent::__construct(...$args); |
8 | - } |
|
8 | + } |
|
9 | 9 | |
10 | - public function validate($value){ |
|
10 | + public function validate($value){ |
|
11 | 11 | return true; |
12 | - } |
|
12 | + } |
|
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -2,12 +2,12 @@ |
||
2 | 2 | namespace Lepton\Boson\DataTypes; |
3 | 3 | |
4 | 4 | #[\Attribute] |
5 | -class DateTimeField extends Field{ |
|
6 | - public function __construct(...$args){ |
|
5 | +class DateTimeField extends Field { |
|
6 | + public function __construct(...$args) { |
|
7 | 7 | parent::__construct(...$args); |
8 | 8 | } |
9 | 9 | |
10 | - public function validate($value){ |
|
10 | + public function validate($value) { |
|
11 | 11 | return true; |
12 | 12 | } |
13 | 13 | } |
14 | 14 | \ No newline at end of file |
@@ -81,49 +81,49 @@ discard block |
||
81 | 81 | public function __construct(protected string $model) |
82 | 82 | { |
83 | 83 | $this->lookup_map = array( |
84 | - "equals" => [ |
|
84 | + "equals" => [ |
|
85 | 85 | "operator" => "=", |
86 | 86 | "rhs" => fn ($x) => $x |
87 | - ], |
|
88 | - "startswith" => [ |
|
87 | + ], |
|
88 | + "startswith" => [ |
|
89 | 89 | "operator" => "LIKE", |
90 | 90 | "rhs" => fn ($x) => sprintf('%s%%', $x) |
91 | - ], |
|
91 | + ], |
|
92 | 92 | |
93 | - "endswith" => [ |
|
93 | + "endswith" => [ |
|
94 | 94 | "operator" => "LIKE", |
95 | 95 | "rhs" => fn ($x) => sprintf('%%%s', $x) |
96 | - ], |
|
96 | + ], |
|
97 | 97 | |
98 | - "contains" => [ |
|
98 | + "contains" => [ |
|
99 | 99 | "operator" => "LIKE", |
100 | 100 | "rhs" => fn ($x) => sprintf('%%%s%%', $x) |
101 | - ], |
|
101 | + ], |
|
102 | 102 | |
103 | - "lte" => [ |
|
103 | + "lte" => [ |
|
104 | 104 | "operator" => "<=", |
105 | 105 | "rhs" => fn ($x) => $x |
106 | - ], |
|
106 | + ], |
|
107 | 107 | |
108 | - "gte" => [ |
|
108 | + "gte" => [ |
|
109 | 109 | "operator" => ">=", |
110 | 110 | "rhs" => fn ($x) => $x |
111 | - ], |
|
111 | + ], |
|
112 | 112 | |
113 | - "lt" => [ |
|
113 | + "lt" => [ |
|
114 | 114 | "operator" => "<", |
115 | 115 | "rhs" => fn ($x) => $x |
116 | - ], |
|
116 | + ], |
|
117 | 117 | |
118 | - "gt" => [ |
|
118 | + "gt" => [ |
|
119 | 119 | "operator" => ">", |
120 | 120 | "rhs" => fn ($x) => $x |
121 | - ], |
|
121 | + ], |
|
122 | 122 | |
123 | - "neq" => [ |
|
123 | + "neq" => [ |
|
124 | 124 | "operator" => "<>", |
125 | 125 | "rhs" => fn ($x) => $x |
126 | - ] |
|
126 | + ] |
|
127 | 127 | ); |
128 | 128 | |
129 | 129 | $this->filters = array(); |
@@ -638,9 +638,9 @@ discard block |
||
638 | 638 | } |
639 | 639 | |
640 | 640 | return array( |
641 | - "column" => $last->getColumnFromField($column), |
|
642 | - "condition" => $condition, |
|
643 | - "join" => $join |
|
641 | + "column" => $last->getColumnFromField($column), |
|
642 | + "condition" => $condition, |
|
643 | + "join" => $join |
|
644 | 644 | ); |
645 | 645 | } |
646 | 646 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function rewind(): void |
179 | 179 | { |
180 | 180 | $this->index = -1; |
181 | - if (! isset($this->result)) { |
|
181 | + if (!isset($this->result)) { |
|
182 | 182 | $this->cache = array(); |
183 | 183 | $this->do(); |
184 | 184 | } |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | $db_columns = $this->current->db_columns(); |
220 | 220 | // Convert column names to field names |
221 | 221 | $fields = array(); |
222 | - foreach($items as $column => $value){ |
|
223 | - $fieldName = array_search($column ,$db_columns); |
|
222 | + foreach ($items as $column => $value) { |
|
223 | + $fieldName = array_search($column, $db_columns); |
|
224 | 224 | $fields[$fieldName] = $value; |
225 | 225 | } |
226 | 226 | $this->current->load(...$fields); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $this->current->clearEditedFields(); |
229 | 229 | } else { |
230 | 230 | $this->current = null; |
231 | - $this->index = -1; |
|
231 | + $this->index = -1; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | public function first() |
241 | 241 | { |
242 | - if(!isset($this->cache)) { |
|
242 | + if (!isset($this->cache)) { |
|
243 | 243 | $this->rewind(); |
244 | 244 | } |
245 | 245 | |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | |
399 | 399 | public function count(): int |
400 | 400 | { |
401 | - if (! isset($this->result)) { |
|
401 | + if (!isset($this->result)) { |
|
402 | 402 | $this->do(); |
403 | 403 | } |
404 | 404 | return $this->result->num_rows; |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | |
434 | 434 | |
435 | 435 | // Get the result |
436 | - $this->result = $result->fetch_result() ; |
|
436 | + $this->result = $result->fetch_result(); |
|
437 | 437 | return $this; |
438 | 438 | } |
439 | 439 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | $join = array(); |
466 | 466 | |
467 | 467 | // if there are any filters build WHERE clause |
468 | - if (count($this->filters)> 0) { |
|
468 | + if (count($this->filters) > 0) { |
|
469 | 469 | list($whereClause, $values, $join) = $this->buildWhereClause($this->filters); |
470 | 470 | array_unshift($join, array("table" => $this->model::getTableName())); |
471 | 471 | |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | } |
476 | 476 | |
477 | 477 | // it there are any ORDER BY, build the clause |
478 | - if (count($this->modifiers)> 0) { |
|
478 | + if (count($this->modifiers) > 0) { |
|
479 | 479 | $modifiers = $this->buildModifiers($this->modifiers); |
480 | 480 | $query .= sprintf(" %s", $modifiers); |
481 | 481 | } |
@@ -505,10 +505,10 @@ discard block |
||
505 | 505 | |
506 | 506 | $clause = array(); |
507 | 507 | for ($i = 1; $i < count($join); $i++) { |
508 | - $clause[] = sprintf( |
|
508 | + $clause[] = sprintf( |
|
509 | 509 | " %s ON %s.%s = %s.%s", |
510 | 510 | $join[$i]["table"], |
511 | - $join[$i-1]["table"], |
|
511 | + $join[$i - 1]["table"], |
|
512 | 512 | $join[$i]["column"], |
513 | 513 | $join[$i]["table"], |
514 | 514 | $join[$i]["column"] |
@@ -524,11 +524,11 @@ discard block |
||
524 | 524 | { |
525 | 525 | return implode( |
526 | 526 | ", ", |
527 | - array_map(function ($v, $k) { |
|
527 | + array_map(function($v, $k) { |
|
528 | 528 | if (is_array($v)) { |
529 | - return $k. " ".implode(', ', $v); |
|
529 | + return $k." ".implode(', ', $v); |
|
530 | 530 | } else { |
531 | - return $k. " ".$v; |
|
531 | + return $k." ".$v; |
|
532 | 532 | } |
533 | 533 | }, $modifiers, array_keys($modifiers)) |
534 | 534 | ); |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | $values = array(); |
567 | 567 | $join = array(); |
568 | 568 | |
569 | - foreach($filters as $key => $value) { |
|
569 | + foreach ($filters as $key => $value) { |
|
570 | 570 | $lookup = $this->lookup($key); |
571 | 571 | |
572 | 572 | $column = $lookup["column"]; |
@@ -615,8 +615,8 @@ discard block |
||
615 | 615 | |
616 | 616 | $join = array(); |
617 | 617 | foreach ($match as $k) { |
618 | - if($last->isForeignKey($k)) { |
|
619 | - $new= new ($last->getRelationshipParentModel($k))(); |
|
618 | + if ($last->isForeignKey($k)) { |
|
619 | + $new = new ($last->getRelationshipParentModel($k))(); |
|
620 | 620 | |
621 | 621 | $join[] = array( |
622 | 622 | "column"=> $last->getColumnFromField($k), |
@@ -413,11 +413,13 @@ |
||
413 | 413 | * @return QuerySet |
414 | 414 | */ |
415 | 415 | |
416 | - public function do(): QuerySet |
|
416 | + public function do { |
|
417 | + (): QuerySet |
|
417 | 418 | { |
418 | 419 | |
419 | 420 | // Build the query |
420 | 421 | list($query, $values) = $this->buildQuery(); |
422 | + } |
|
421 | 423 | |
422 | 424 | // Connect to DB |
423 | 425 | $db = Application::getDb(); |
@@ -3,21 +3,21 @@ |
||
3 | 3 | |
4 | 4 | class Functions{ |
5 | 5 | static function getDeclarationLine(\ReflectionProperty $prop){ |
6 | - $declaringClass = $prop->getDeclaringClass(); |
|
7 | - $propname = $prop->getName(); |
|
8 | - $classFile = new \SplFileObject($declaringClass->getFileName()); |
|
9 | - foreach ($classFile as $line => $content) { |
|
10 | - if (preg_match( |
|
11 | - '/ |
|
6 | + $declaringClass = $prop->getDeclaringClass(); |
|
7 | + $propname = $prop->getName(); |
|
8 | + $classFile = new \SplFileObject($declaringClass->getFileName()); |
|
9 | + foreach ($classFile as $line => $content) { |
|
10 | + if (preg_match( |
|
11 | + '/ |
|
12 | 12 | (private|protected|public|var|static) # match visibility or var |
13 | 13 | \s # followed 1 whitespace |
14 | 14 | \$'.$propname.' # followed by the var name $bar |
15 | 15 | /x', |
16 | - $content) |
|
17 | - ) { |
|
18 | - return $line + 1; |
|
19 | - } |
|
20 | - } |
|
21 | - return 1; |
|
16 | + $content) |
|
17 | + ) { |
|
18 | + return $line + 1; |
|
19 | + } |
|
20 | + } |
|
21 | + return 1; |
|
22 | 22 | } |
23 | 23 | } |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Lepton\Helpers; |
3 | 3 | |
4 | -class Functions{ |
|
5 | -static function getDeclarationLine(\ReflectionProperty $prop){ |
|
4 | +class Functions { |
|
5 | +static function getDeclarationLine(\ReflectionProperty $prop) { |
|
6 | 6 | $declaringClass = $prop->getDeclaringClass(); |
7 | 7 | $propname = $prop->getName(); |
8 | 8 | $classFile = new \SplFileObject($declaringClass->getFileName()); |
@@ -5,6 +5,6 @@ |
||
5 | 5 | |
6 | 6 | class MatchRoute extends BaseMatch |
7 | 7 | { |
8 | - public function __construct(public $controller, public $method, public $parameters){} |
|
8 | + public function __construct(public $controller, public $method, public $parameters){} |
|
9 | 9 | |
10 | 10 | } |
@@ -5,6 +5,6 @@ |
||
5 | 5 | |
6 | 6 | class MatchRoute extends BaseMatch |
7 | 7 | { |
8 | - public function __construct(public $controller, public $method, public $parameters){} |
|
8 | + public function __construct(public $controller, public $method, public $parameters) {} |
|
9 | 9 | |
10 | 10 | } |
@@ -5,9 +5,9 @@ |
||
5 | 5 | |
6 | 6 | class MatchFile extends BaseMatch |
7 | 7 | { |
8 | - public function __construct(public $filePath, public $contentType) |
|
9 | - { |
|
8 | + public function __construct(public $filePath, public $contentType) |
|
9 | + { |
|
10 | 10 | |
11 | - } |
|
11 | + } |
|
12 | 12 | |
13 | 13 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | class UrlResolver |
12 | 12 | { |
13 | 13 | |
14 | - public function __construct(private $pattern){} |
|
14 | + public function __construct(private $pattern) {} |
|
15 | 15 | |
16 | 16 | public function patternPrepare($pattern) |
17 | 17 | { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $is_match = preg_match(sprintf("/^%s$/", $pattern), $_SERVER['REQUEST_URI'], $parameters); |
52 | 52 | |
53 | 53 | // keep only string keys |
54 | - $parameters = array_filter($parameters, function ($k) { |
|
54 | + $parameters = array_filter($parameters, function($k) { |
|
55 | 55 | return is_string($k); |
56 | 56 | }, ARRAY_FILTER_USE_KEY); |
57 | 57 | return $is_match; |
@@ -17,10 +17,10 @@ |
||
17 | 17 | Liquid::set('INCLUDE_SUFFIX', 'html'); |
18 | 18 | Liquid::set('INCLUDE_PREFIX', ''); |
19 | 19 | $path = "app/Views"; |
20 | - $template = new Template($path); |
|
20 | + $template = new Template($path); |
|
21 | 21 | $template->registerFilter(new SiteFilter()); |
22 | 22 | $template->parseFile($view); |
23 | - $parameters = array_map(function ($x) { |
|
23 | + $parameters = array_map(function($x) { |
|
24 | 24 | if ($x instanceof QuerySet) { |
25 | 25 | return $x->do(); |
26 | 26 | } else { |
@@ -3,43 +3,43 @@ discard block |
||
3 | 3 | |
4 | 4 | class Database { |
5 | 5 | |
6 | - protected $connection; |
|
7 | - protected $query; |
|
8 | - protected $show_errors = TRUE; |
|
9 | - protected $query_closed = TRUE; |
|
10 | - |
|
11 | - public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
|
12 | - $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
13 | - if ($this->connection->connect_error) { |
|
14 | - $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
15 | - } |
|
16 | - $this->connection->set_charset($charset); |
|
17 | - } |
|
18 | - |
|
19 | - public function query($query, &...$args) { |
|
6 | + protected $connection; |
|
7 | + protected $query; |
|
8 | + protected $show_errors = TRUE; |
|
9 | + protected $query_closed = TRUE; |
|
10 | + |
|
11 | + public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
|
12 | + $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
|
13 | + if ($this->connection->connect_error) { |
|
14 | + $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
15 | + } |
|
16 | + $this->connection->set_charset($charset); |
|
17 | + } |
|
18 | + |
|
19 | + public function query($query, &...$args) { |
|
20 | 20 | if(!$this->query_closed){ |
21 | - $this->query_closed = TRUE; |
|
22 | - $this->query->close(); |
|
21 | + $this->query_closed = TRUE; |
|
22 | + $this->query->close(); |
|
23 | 23 | } |
24 | - if ($this->query = $this->connection->prepare($query)) { |
|
25 | - if(count($args)){ |
|
24 | + if ($this->query = $this->connection->prepare($query)) { |
|
25 | + if(count($args)){ |
|
26 | 26 | $types = implode(array_map(array($this, '_gettype'), $args)); |
27 | 27 | $this->query->bind_param($types, ...$args); |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - $this->query->execute(); |
|
31 | - if ($this->query->errno) { |
|
30 | + $this->query->execute(); |
|
31 | + if ($this->query->errno) { |
|
32 | 32 | $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error); |
33 | - } |
|
34 | - $this->query_closed = FALSE; |
|
33 | + } |
|
34 | + $this->query_closed = FALSE; |
|
35 | 35 | } else { |
36 | - $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
36 | + $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
37 | + } |
|
38 | + return $this; |
|
37 | 39 | } |
38 | - return $this; |
|
39 | - } |
|
40 | 40 | |
41 | 41 | |
42 | - public function fetch_all($callback = null) { |
|
42 | + public function fetch_all($callback = null) { |
|
43 | 43 | $params = array(); |
44 | 44 | $row = array(); |
45 | 45 | $meta = $this->query->result_metadata(); |
@@ -50,74 +50,74 @@ discard block |
||
50 | 50 | |
51 | 51 | $result = array(); |
52 | 52 | while ($this->query->fetch()) { |
53 | - $r = array(); |
|
54 | - foreach ($row as $key => $val) { |
|
53 | + $r = array(); |
|
54 | + foreach ($row as $key => $val) { |
|
55 | 55 | $r[$key] = $val; |
56 | - } |
|
57 | - if ($callback != null && is_callable($callback)) { |
|
56 | + } |
|
57 | + if ($callback != null && is_callable($callback)) { |
|
58 | 58 | $value = $callback($r);//call_user_func($callback, $r); |
59 | 59 | if ($value == 'break') break; |
60 | - } else { |
|
60 | + } else { |
|
61 | 61 | $result[] = $r; |
62 | - } |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | $this->query_closed = TRUE; |
65 | 65 | return $result; |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - public function fetch_array() { |
|
68 | + public function fetch_array() { |
|
69 | 69 | $params = array(); |
70 | 70 | $row = array(); |
71 | 71 | $meta = $this->query->result_metadata(); |
72 | 72 | while ($field = $meta->fetch_field()) { |
73 | - $params[] = &$row[$field->name]; |
|
73 | + $params[] = &$row[$field->name]; |
|
74 | 74 | } |
75 | 75 | $this->query->bind_result(...$params); |
76 | 76 | $result = array(); |
77 | - while ($this->query->fetch()) { |
|
78 | - foreach ($row as $key => $val) { |
|
79 | - $result[$key] = $val; |
|
80 | - } |
|
81 | - } |
|
82 | - return $result; |
|
83 | - } |
|
77 | + while ($this->query->fetch()) { |
|
78 | + foreach ($row as $key => $val) { |
|
79 | + $result[$key] = $val; |
|
80 | + } |
|
81 | + } |
|
82 | + return $result; |
|
83 | + } |
|
84 | 84 | |
85 | - public function fetch_result(){ |
|
86 | - return $this->query->get_result(); |
|
87 | - } |
|
85 | + public function fetch_result(){ |
|
86 | + return $this->query->get_result(); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - public function close() { |
|
93 | - return $this->connection->close(); |
|
94 | - } |
|
92 | + public function close() { |
|
93 | + return $this->connection->close(); |
|
94 | + } |
|
95 | 95 | |
96 | - public function num_rows() { |
|
97 | - $this->query->store_result(); |
|
98 | - return $this->query->num_rows; |
|
99 | - } |
|
96 | + public function num_rows() { |
|
97 | + $this->query->store_result(); |
|
98 | + return $this->query->num_rows; |
|
99 | + } |
|
100 | 100 | |
101 | - public function affected_rows() { |
|
102 | - return $this->query->affected_rows; |
|
103 | - } |
|
101 | + public function affected_rows() { |
|
102 | + return $this->query->affected_rows; |
|
103 | + } |
|
104 | 104 | |
105 | - public function last_insert_id() { |
|
105 | + public function last_insert_id() { |
|
106 | 106 | return $this->connection->insert_id; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | - public function error($error) { |
|
109 | + public function error($error) { |
|
110 | 110 | if ($this->show_errors) { |
111 | 111 | die($error); |
112 | 112 | } |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - private function _gettype($var) { |
|
116 | - if (is_string($var)) return 's'; |
|
117 | - if (is_float($var)) return 'd'; |
|
118 | - if (is_int($var)) return 'i'; |
|
119 | - return 'b'; |
|
120 | - } |
|
115 | + private function _gettype($var) { |
|
116 | + if (is_string($var)) return 's'; |
|
117 | + if (is_float($var)) return 'd'; |
|
118 | + if (is_int($var)) return 'i'; |
|
119 | + return 'b'; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | ?> |
124 | 124 | \ No newline at end of file |
@@ -11,29 +11,29 @@ discard block |
||
11 | 11 | public function __construct($dbhost = 'localhost', $dbuser = 'root', $dbpass = '', $dbname = '', $charset = 'utf8') { |
12 | 12 | $this->connection = new \mysqli($dbhost, $dbuser, $dbpass, $dbname); |
13 | 13 | if ($this->connection->connect_error) { |
14 | - $this->error('Failed to connect to MySQL - ' . $this->connection->connect_error); |
|
14 | + $this->error('Failed to connect to MySQL - '.$this->connection->connect_error); |
|
15 | 15 | } |
16 | 16 | $this->connection->set_charset($charset); |
17 | 17 | } |
18 | 18 | |
19 | 19 | public function query($query, &...$args) { |
20 | - if(!$this->query_closed){ |
|
20 | + if (!$this->query_closed) { |
|
21 | 21 | $this->query_closed = TRUE; |
22 | 22 | $this->query->close(); |
23 | 23 | } |
24 | 24 | if ($this->query = $this->connection->prepare($query)) { |
25 | - if(count($args)){ |
|
25 | + if (count($args)) { |
|
26 | 26 | $types = implode(array_map(array($this, '_gettype'), $args)); |
27 | 27 | $this->query->bind_param($types, ...$args); |
28 | 28 | } |
29 | 29 | |
30 | 30 | $this->query->execute(); |
31 | 31 | if ($this->query->errno) { |
32 | - $this->error('Unable to process MySQL query (check your params) - ' . $this->query->error); |
|
32 | + $this->error('Unable to process MySQL query (check your params) - '.$this->query->error); |
|
33 | 33 | } |
34 | 34 | $this->query_closed = FALSE; |
35 | 35 | } else { |
36 | - $this->error('Unable to prepare MySQL statement (check your syntax) - ' . $this->connection->error); |
|
36 | + $this->error('Unable to prepare MySQL statement (check your syntax) - '.$this->connection->error); |
|
37 | 37 | } |
38 | 38 | return $this; |
39 | 39 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $r[$key] = $val; |
56 | 56 | } |
57 | 57 | if ($callback != null && is_callable($callback)) { |
58 | - $value = $callback($r);//call_user_func($callback, $r); |
|
58 | + $value = $callback($r); //call_user_func($callback, $r); |
|
59 | 59 | if ($value == 'break') break; |
60 | 60 | } else { |
61 | 61 | $result[] = $r; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | return $result; |
83 | 83 | } |
84 | 84 | |
85 | - public function fetch_result(){ |
|
85 | + public function fetch_result() { |
|
86 | 86 | return $this->query->get_result(); |
87 | 87 | } |
88 | 88 |
@@ -17,12 +17,12 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function query($query, &...$args) { |
20 | - if(!$this->query_closed){ |
|
20 | + if(!$this->query_closed) { |
|
21 | 21 | $this->query_closed = TRUE; |
22 | 22 | $this->query->close(); |
23 | 23 | } |
24 | 24 | if ($this->query = $this->connection->prepare($query)) { |
25 | - if(count($args)){ |
|
25 | + if(count($args)) { |
|
26 | 26 | $types = implode(array_map(array($this, '_gettype'), $args)); |
27 | 27 | $this->query->bind_param($types, ...$args); |
28 | 28 | } |
@@ -56,7 +56,9 @@ discard block |
||
56 | 56 | } |
57 | 57 | if ($callback != null && is_callable($callback)) { |
58 | 58 | $value = $callback($r);//call_user_func($callback, $r); |
59 | - if ($value == 'break') break; |
|
59 | + if ($value == 'break') { |
|
60 | + break; |
|
61 | + } |
|
60 | 62 | } else { |
61 | 63 | $result[] = $r; |
62 | 64 | } |
@@ -113,9 +115,15 @@ discard block |
||
113 | 115 | } |
114 | 116 | |
115 | 117 | private function _gettype($var) { |
116 | - if (is_string($var)) return 's'; |
|
117 | - if (is_float($var)) return 'd'; |
|
118 | - if (is_int($var)) return 'i'; |
|
118 | + if (is_string($var)) { |
|
119 | + return 's'; |
|
120 | + } |
|
121 | + if (is_float($var)) { |
|
122 | + return 'd'; |
|
123 | + } |
|
124 | + if (is_int($var)) { |
|
125 | + return 'i'; |
|
126 | + } |
|
119 | 127 | return 'b'; |
120 | 128 | } |
121 | 129 |