Skip to content

Commit 9cc9ddd

Browse files
committed
Include validate method in sqlP generated models
1 parent f5df45c commit 9cc9ddd

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

system/sqlp/mysqli.php

+19
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@ class %name%SQL {
1111

1212
private $db;
1313

14+
protected $filters = %filters%;
15+
16+
protected $paramTypes = %paramTypes%;
17+
1418
public function __construct(){
1519
$this->db = Db::getInstance();
1620
}
21+
22+
public function validate($data, $method, $table = '', $ignoreMissing = false) {
23+
$params = $this->paramTypes[$method] ?? [];
24+
if (!$params) {
25+
return false;
26+
}
27+
28+
foreach ($params as $name => $type) {
29+
if (isset($this->filters[$name])) {
30+
$params[$name] = $this->filters[$name];
31+
}
32+
}
33+
34+
return $this->db->validate($data, $params, $table, $ignoreMissing);
35+
}
1736

1837
%methods_start%
1938

system/sqlp/pgsql.php

+19
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,30 @@
1010
class %name%SQL {
1111

1212
private $db;
13+
14+
protected $filters = %filters%;
15+
16+
protected $paramTypes = %paramTypes%;
1317

1418
public function __construct(){
1519
$this->db = Db::getInstance();
1620
}
1721

22+
public function validate($data, $method, $table = '', $ignoreMissing = false) {
23+
$params = $this->paramTypes[$method] ?? [];
24+
if (!$params) {
25+
return false;
26+
}
27+
28+
foreach ($params as $name => $type) {
29+
if (isset($this->filters[$name])) {
30+
$params[$name] = $this->filters[$name];
31+
}
32+
}
33+
34+
return $this->db->validate($data, $params, $table, $ignoreMissing);
35+
}
36+
1837
%methods_start%
1938

2039
%methodMultipleTemplate_start%

system/sqlp/sqlite.php

+19
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,29 @@ class %name%SQL {
1111

1212
private $db;
1313

14+
protected $filters = %filters%;
15+
16+
protected $paramTypes = %paramTypes%;
17+
1418
public function __construct(){
1519
$this->db = Db::getInstance();
1620
}
1721

22+
public function validate($data, $method, $table = '', $ignoreMissing = false) {
23+
$params = $this->paramTypes[$method] ?? [];
24+
if (!$params) {
25+
return false;
26+
}
27+
28+
foreach ($params as $name => $type) {
29+
if (isset($this->filters[$name])) {
30+
$params[$name] = $this->filters[$name];
31+
}
32+
}
33+
34+
return $this->db->validate($data, $params, $table, $ignoreMissing);
35+
}
36+
1837
%methods_start%
1938

2039
%methodMultipleTemplate_start%

0 commit comments

Comments
 (0)