update framework code libs - validator/model loader

* lib - class.validator > fix validator class for required and non required
  in class.validator when many parameters are sent..
  the validator if you used required only validate the last one..
  fix so if this is not required and the first one is required,
  let the validation pass or do not pass any
* lib - class.validator > support for GET and POST autodetection validator
  allows to send and assigation of the array vars validations
  this allows to you to use also PUT for api calls..
  autodetection of the type, if will be GET or POST array
  if no speciall call is given..
* lib - class.model > mkid autoincrement string/key for ODBC/sql ansi DBMS
  Create PICCORO's crazy ID posta is not crazy..
  allows to use autoincremnet no matter if database support it or not
  this permit that you can create a simpel nont dependendant database.
  with this you identify several things, full date, where when inserted
  it sorts itself since it will never give a smaller number
* editor config, set to 0 spaces ini files
* ignore shit of mocosoft vscode
main
mckaygerhard 2024-04-17 22:41:58 -04:00
parent 502b02ba3d
commit 3b2eac3cbc
8 changed files with 2089 additions and 28 deletions

View File

@ -14,5 +14,8 @@ max_line_length = off
[*.md]
indent_size = false
[*.ini]
indent_size = 0
[*.sql]
indent_size = 2

6
.gitignore vendored
View File

@ -1,3 +1,6 @@
# no shit allowed
.vscode
# ---> Laravel
/vendor/
node_modules/
@ -17,7 +20,6 @@ public_html/storage
public_html/hot
storage/*.key
.env
Homestead.yaml
Homestead.json
/.vagrant
@ -39,4 +41,4 @@ storage/
/server
/extras/pruebas/
/public/pruebas.php
/test/
/test/

1994
lib/class.markdown.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ abstract class model {
protected $db = null;
protected $auth = null;
protected $router = null;
protected $view = null;
public $view = null;
/* Constructor
*
@ -22,6 +22,17 @@ abstract class model {
$this->view = $view;
}
/**
* Crea el ID loco de PICCORO posta no es loco..
* allows touse autoincremnet ODBC compiland and SQL ansi!
* con esto identificas varias cosas, fecha, donde cuando
* ah y de paso se ordena solo ya que nunca dara unnumero menor
* @return string YYYYMMDDHHmmss
*/
private function mkid() {
return date('YmdHis');
}
/* Borrow function from other model
*
* INPUT: string module name
@ -47,7 +58,24 @@ abstract class model {
return new $model_class($this->db, $this->auth, $this->router, $this->view);
}
/* show ap[i output in json format
/*implemnetacion basica vistas sin mucho paja*/
public function view($viewfile = null, $data = null) {
if(is_array($data)) {
foreach ($data as $key => $value) {
$this->values[$key] = $value;
$this->$key = $value;
$$key = $value;
}
}
if (file_exists($viewfile = DIR_VIEWS . $viewfile.".php")) {
$this->view = $viewfile;
include($this->view);
}
}
/* show api output in json format
*
* INPUT: array
* OUTPUT: string

View File

@ -23,6 +23,7 @@
"minlen" => "La longitud de [label] debe ser al menos [minlen].",
"maxlen" => "La longitud de [label] no debe exceder de [maxlen].."
);
private $arrayvars = null;
/* Constructor
*
@ -30,7 +31,13 @@
* OUTPUT: -
* ERROR: -
*/
public function __construct() {
public function __construct($arrayvars = null) {
if(is_array($arrayvars) and count($arrayvars) > 0)
$this->arrayvars = $arrayvars;
elseif(is_array($_POST) and count($_POST) > 0)
$this->arrayvars = $_POST;
else
$this->arrayvars = $_GET;
}
/* Add validation feedback to output
@ -52,13 +59,34 @@
$this->msg = $message;
}
private function _required($name,$rule) {
$result = false;
if (array_key_exists($name,$this->arrayvars)) {
if(trim($this->arrayvars[$name]) != '')
$result = true;
else
$this->add_message("required", $rule);
}
else
$this->add_message("required", $rule);
//*/ trigger_error($rule["required"].' rsulta para '.$name.' en '.$result, E_USER_WARNING);
return $result;
}
/* Start validation process
*
* INPUT: array pattern to validate POST data
* OUTPUT: boolean validation oke
* ERROR: -
*/
public function execute($pattern) {
public function execute($pattern,$arrayvars = null) {
if(is_array($arrayvars) and count($arrayvars) > 0)
$this->arrayvars = $arrayvars;
elseif(is_array($_POST) and count($_POST) > 0)
$this->arrayvars = $_POST;
else
$this->arrayvars = $_GET;
$result = true;
foreach ($pattern as $name => $rule) {
@ -66,51 +94,47 @@
$rule["label"] = $name;
}
if ($rule["required"] === true) {
if ($_POST[$name] == "") {
$this->add_message("required", $rule);
$result = false;
continue;
}
if($rule["required"] == true) {
$result = $this->_required($name,$rule);
}
switch ($rule["type"]) {
case "boolean":
if (($_POST[$name] != null) && ($_POST[$name] != "On")) {
if (($this->arrayvars[$name] != null) && ($this->arrayvars[$name] != "On")) {
$this->add_message("boolean", $rule);
$result = false;
}
break;
case "email":
if ($_POST[$name] != "") {
if (valid_email($_POST[$name]) == false) {
if ($this->arrayvars[$name] != "") {
if (valid_email($this->arrayvars[$name]) == false) {
$this->add_message("email", $rule);
$result = false;
}
}
break;
case "enum":
if ($_POST[$name] != "") {
if (in_array($_POST[$name], $rule["values"]) == false) {
if ($this->arrayvars[$name] != "") {
if (in_array($this->arrayvars[$name], $rule["values"]) == false) {
$this->add_message("enum", $rule);
$result = false;
}
}
break;
case "integer":
if (valid_input($_POST[$name], VALIDATE_NUMBERS) == false) {
if (valid_input($this->arrayvars[$name], VALIDATE_NUMBERS) == false) {
$this->add_message("integer", $rule);
$result = false;
} else {
if (isset($rule["min"])) {
if ($_POST[$name] < $rule["min"]) {
if ($this->arrayvars[$name] < $rule["min"]) {
$this->add_message("intmin", $rule);
$result = false;
}
}
if (isset($rule["max"])) {
if ($_POST[$name] > $rule["max"]) {
if ($this->arrayvars[$name] > $rule["max"]) {
$this->add_message("intmax", $rule);
$result = false;
}
@ -118,43 +142,43 @@
}
break;
case "float":
if (is_numeric($_POST[$name]) == false) {
if (is_numeric($this->arrayvars[$name]) == false) {
$this->add_message("float", $rule);
$result = false;
}
break;
case "string":
if (isset($rule["minlen"])) {
if (strlen($_POST[$name]) < $rule["minlen"]) {
if (strlen($this->arrayvars[$name]) < $rule["minlen"]) {
$this->add_message("minlen", $rule);
$result = false;
}
}
if (isset($rule["maxlen"])) {
if (strlen($_POST[$name]) > $rule["maxlen"]) {
if (strlen($this->arrayvars[$name]) > $rule["maxlen"]) {
$this->add_message("maxlen", $rule);
$result = false;
}
}
if (isset($rule["charset"])) {
if (valid_input($_POST[$name], $rule["charset"]) == false) {
if (valid_input($this->arrayvars[$name], $rule["charset"]) == false) {
$this->add_message("charset", $rule);
$result = false;
}
}
if (isset($rule["pattern"])) {
if (preg_match("/".$rule["pattern"]."/", $_POST[$name]) == false) {
if (preg_match("/".$rule["pattern"]."/", $this->arrayvars[$name]) == false) {
$this->add_message("pattern", $rule);
$result = false;
}
}
break;
case "timestamp":
if ($_POST[$name] != "") {
if (valid_timestamp($_POST[$name]) == false) {
if ($this->arrayvars[$name] != "") {
if (valid_timestamp($this->arrayvars[$name]) == false) {
$this->add_message("timestamp", $rule);
$result = false;
}

View File

@ -206,6 +206,16 @@
return $str;
}
/*
* backguard compatibility determine if some variable is countable
*/
if (!function_exists('is_countable')) {
function is_countable($var) {
trigger_error("Older PHP engine detected using workaround for is_countable", E_USER_WARNING);
return (is_array($var) || $var instanceof Countable);
}
}
/* Localized date string
*
* INPUT: string format[, integer timestamp]

View File

@ -41,6 +41,6 @@ else
{
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
header($protocol . ' 412');
$GLOBALS['http_response_code'] = $code;
$GLOBALS['http_response_code'] = 412;
include(DIR_VIEWS."index.php");
}