Gestion des 'varchar' spécifiques (flags)

This commit is contained in:
xdrm-brackets 2016-07-02 17:46:59 +02:00
parent fadb8c5d76
commit d0e89d349d
5 changed files with 283 additions and 43 deletions

View File

@ -1,23 +1,5 @@
{
"userDefault" :[
"create",
"link",
"unlink",
"search",
"getAll",
"getById",
"getByCode",
"getByUsername",
"getClusters",
"edit",
"delete"
],
"machineDefault" :[
"create",
@ -40,3 +22,225 @@
]
}
{
"userDefault": {
"create": {
"description": "blablabla",
"permissions": [],
"parameters": {
"code": { "description": "Code RFID de l'utilisateur.", "type": "rfid" },
"username": { "description": "Identifiant de l'utilisateur.", "type": "varchar(1,30)" },
"firstname": { "description": "Prénom de l'utilisateur.", "type": "varchar(3,30)" },
"lastname": { "description": "Nom de l'utilisateur.", "type": "varchar(3,30)" },
"mail": { "description": "Adresse mail de l'utilisateur.", "type": "mail" },
"password": { "description": "Mot de passe de l'utilisateur.", "type": "text" },
"status": { "description": "Status de l'utilisateur.", "type": "status" }
},
"output": {
"id_user": { "description": "UID de l'utilisateur créé.", "type": "id" },
"id_group": { "description": "UID du groupe de l'utilisateur.", "type": "id" }
}
},
"link": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"unlink": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"search": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"getAll": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"getById": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"getByCode": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"getByUsername": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"getClusters": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"edit": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
},
"delete": {
"description": "blablabla",
"permissions": [],
"parameters": {
},
"output": {
}
}
},
"module": {
"method": {
"description": "Test de l'API",
"permissions": [],
"parameters": {}
},
"phpunitParams": {
"description": "Méthode utile à phpunit pour le test des paramètres.",
"permissions": [],
"parameters": {
"p1": { "description": "Texte", "type": "text" },
"p2": { "description": "Entier positif", "type": "id" }
},
"output": {
"receivedArguments": { "description": "Liste des arguments reçus par la méthode", "type": "array<mixed>" }
}
},
"phpunitOptionalParams": {
"description": "Méthode utile à phpunit pour le test des paramètres optionnels.",
"permissions": [],
"parameters": {
"p1": { "description": "Texte", "type": "text" },
"p2": { "description": "Texte", "type": "text", "optional": false },
"p3": { "description": "Entier positif (optionnel)", "type": "id", "optional": true }
}
},
"phpunitPermissions": {
"description": "Méthode utile à phpunit pour le test des permissions.",
"permissions": ["a", "b"],
"parameters": {}
},
"markdown": {
"description": "Retourne une description en markdown des différents modules de l'API",
"permissions": [],
"options": { "download": true },
"parameters": {}
},
"apiBlueprint": {
"description": "Retourne une documentation de l'API au format API Blueprint.",
"permissions": [],
"options": { "download": true },
"parameters": {}
}
},
"upload": {
"call_log": {
"description": "Upload d'un journal d'appel au format .xml. Retour des données de call_log/unserialize",
"permissions": ["admin"],
"parameters": {
"file": { "description": "Fichier du journal d'appel.", "type": "FILE" }
},
"output": {
"tmp_id": { "description": "Identifiant temporaire du journal d'appel", "type": "varchar(40,40)" },
"directory": { "description": "Annuaire des contacts trouvés", "type": "array<array<mixed>>" },
"call": { "description": "Liste des identifiants des contacts triés par nombre d'appels", "type": "array<id>" },
"sms": { "description": "Liste des identifiants des contacts triés par nombre de sms", "type": "array<id>" }
}
}
},
"download": {
"multiple": {
"description": "Download des données relatives aux sujets donnés.",
"permissions": ["admin"],
"options": { "download": true },
"parameters": {
"subjects": { "description": "Identifiants des sujets d'enquêtes à intégrer.", "type": "array<id>", "optional": true },
"phone": { "description": "Si vaut TRUE, renvoie les sujets cellulaires.", "type": "boolean", "optional": true },
"facebook": { "description": "Si vaut TRUE, renvoie les sujet facebook.", "type": "boolean", "optional": true },
"survey": { "description": "Si vaut TRUE, renvoie les sujets ResTIC.", "type": "boolean", "optional": true },
"all": { "description": "Si vaut TRUE, renvoie tous les sujets enregistrés.", "type": "boolean", "optional": true }
}
}
}
}

View File

@ -191,16 +191,26 @@
/* [1] Si de type VARCHAR(min, max)
/* [1] Si de type VARCHAR(min, max, flags)
=========================================================*/
if( preg_match('/^varchar\((\d+), ?(\d+)\)$/', $type, $match) ){
if( preg_match('/^varchar\((\d+), ?(\d+)((?:, ?\w+)+)?\)$/', $type, $match) ){
// On recupere la taille min
$min = (int) $match[1];
// On recupere la taille max
$max = (int) $match[2];
// On effectue la verification
return $checker && is_string($value) && strlen($value) <= $max && strlen($value) >= $min;
// On recupere le sous-type si défini
$flags = isset($match[3]) ? explode(',', substr($match[3], 1)) : null;
// On effectue la verification de taille
$lenCheck = $checker && is_string($value) && strlen($value) <= $max && strlen($value) >= $min;
// On vérifie les FLAGS s'il est donné
if( is_array($flags) )
foreach( $flags as $flag )
$lenCheck = $lenCheck && self::check($flag, $value);
return $lenCheck;
}
@ -239,6 +249,11 @@
return $checker && is_numeric($value) && $value <= 2147483647 && $value >= 0;
break;
// Code RFID
case 'rfid':
return $checker && is_string($value) && preg_match('/^[\dA-F]{2}(\-[\dA-F]{2}){3,5}$/i', $value);
break;
// String quelconque (peut etre vide)
case 'text':
return $checker && is_string($value);
@ -248,14 +263,26 @@
return $checker && is_string($value) && strlen($value) <= 50 && preg_match('/^[\w\.-]+@[\w\.-]+\.[a-z]{2,4}$/i', $value);
break;
// Hash sha1
case 'sha1':
// Hash sha1/md5
case 'hash':
return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value);
break;
// Numéro de téléphone
case 'number':
return $checker && is_string($value) && preg_match('/^(?:0|\+33 ?|0?0?33 ?|)([1-9] ?(?:[0-9] ?){8})$/i', $value);
case 'alphanumeric':
case 'user.username':
case 'machine.name':
case 'group.name':
return $checker && is_string($value) && preg_match('/^[\w-]+$/i', $value);
break;
case 'user.firstname':
case 'user.lastname':
case 'letters':
return $checker && is_string($value) && preg_match('/^[a-z -]+$/i', $value);
break;
case 'status':
return $checker && is_numeric($value) && floor($value) == $value && $value >= 0 && $value <= 100;
break;
// Tableau non vide

View File

@ -5,6 +5,7 @@
use \manager\ResourceDispatcher;
use \manager\ManagerError;
use \manager\Repo;
use \manager\Database;
debug();
@ -303,6 +304,14 @@
}//editUser();
// new ResourceDispatcher('f/svg/search/st/sub-menu-side/ff0000', true);
var_dump( Database::check('varchar(3,5)', "blabl") );
var_dump( Database::check('varchar(3,5)', "bla -") );
var_dump( Database::check('varchar(3,5,subtest,subsub)', "blabl") );
?>