Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Moved method parameters and table columns data from local method variable to model properties to also be able to use it for validate method

givanz5f0e04f5cf62
diff --git a/system/sqlp/sqlp.php b/system/sqlp/sqlp.php
index 4f85105..8b26b60 100755
--- a/system/sqlp/sqlp.php
+++ b/system/sqlp/sqlp.php
@@ -36,6 +36,10 @@ class Sqlp {
private $tree = [];
+ private $filters = [];
+
+ private $params = [];
+
private $db;
private $namespace;
@@ -414,17 +418,20 @@ class Sqlp {
$filter[$name] = $column;
}
- $filterArray = var_export($filter, true);
+ //$filterArray = var_export($filter, true);
$return = ! empty($match['return']) ? $match['return'] : $match['data'];
$return = '$params' . $this->sqlPhpArrayKey($return);
$key = '$params' . $this->sqlPhpArrayKey($match['data']);
+ $filterName = '$this->filters[\'' . $this->prefix . $match['columns'] . '\']';
- $filterFunction = '\';' . TAB . '$filterArray = ' . $filterArray . ";\n" . TAB;
+ //$filterFunction = '\';' . TAB . '$filterArray = ' . $filterArray . ";\n" . TAB;
+ $filterFunction = '\';' . TAB;
+ $this->filters[$this->prefix . $match['columns']] = $filter;
if ($isArray == 'true') {
- $filterFunction .= 'foreach ( ' . $key . ' as $key => &$filter) ' . $return . '[$key] = $this->db->filter($filter, $filterArray,' . $addMissingDefaults . ');' . TAB . '$sql = \'';
+ $filterFunction .= 'if (isset(' . $key . ') && is_array(' . $key . ')) foreach ( ' . $key . ' as $key => &$filter) ' . $return . '[$key] = $this->db->filter($filter, ' . $filterName . ',' . $addMissingDefaults . ');' . TAB . '$sql = \'';
} else {
- $filterFunction .= $return . '= $this->db->filter(' . $key . ', $filterArray,' . $addMissingDefaults . ');' . TAB . '$sql = \'';
+ $filterFunction .= $return . '= $this->db->filter(' . $key . ', ' . $filterName . ',' . $addMissingDefaults . ');' . TAB . '$sql = \'';
}
$statement = str_replace($match[0], $filterFunction, $statement);
@@ -452,6 +459,10 @@ class Sqlp {
$param['length'] = (int)preg_replace('/[^\d]/', '',$match[4]);
}
+ if (isset($match[5])) {
+ $param['comment'] = trim($match[5], " \n\r\t\v\x00-");
+ }
+
$parameters[] = $param;
}
}
@@ -510,12 +521,14 @@ class Sqlp {
//remove comments
$sql = preg_replace('@(--.*)\s+@', '', $sql);
+ $this->tree = [];
if (preg_match_all($this->config['functionRegex'], $sql, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$method['name'] = trim($match['name'], '`"\'');
//add slashes only for single quotes
$method['statement'] = str_replace("'", "\'",trim($match['statement']));
+ $method['statement'] = preg_replace('@(--.*)\s+@', '', $method['statement']);
$method['params'] = $this->parseParameters($match['params']);
@@ -526,6 +539,10 @@ class Sqlp {
}
}
+ function getModel() {
+ return $this->tree;
+ }
+
function generateModel() {
$methods = '';
@@ -614,12 +631,26 @@ class Sqlp {
}
} ,$method['params'])), "\n\t");
*/
+ /*
$method['param_types'] = 'array(' . trim(implode(', ', array_map(
function ($param) {
if ($param['in_out'] == 'IN' && ($type = $this->paramType($param['type']))) {
return '\'' . $param['name'] . '\' => \'' . $type . '\'';
}
} ,$method['params'])), ', ') . ')';
+ */
+
+ $paramTypes = [];
+
+ foreach ($method['params'] as $param) {
+ if ($param['in_out'] == 'IN' && ($type = $this->paramType($param['type']))) {
+ $paramTypes[$param['name']] = $type;
+ }
+ }
+
+ $this->paramTypes[$method['name']] = $paramTypes;
+
+ $method['param_types'] = '$this->paramTypes[\'' . $method['name'] . '\']';
$method['fetch'] = $this->fetchType('fetch_all');
@@ -661,10 +692,12 @@ class Sqlp {
}
$model = $this->template($this->model['model'],[
- 'name' => ucfirst($this->modelName),
- 'namespace' => ucfirst($this->namespace),
- 'filename' => $this->filename,
- 'methods' => $methods,
+ 'name' => ucfirst($this->modelName),
+ 'namespace' => ucfirst($this->namespace),
+ 'filename' => $this->filename,
+ 'methods' => $methods,
+ 'filters' => var_export($this->filters, true),
+ 'paramTypes' => var_export($this->paramTypes, true),
]);
return $model;