|
|
|
<?php
|
|
|
|
namespace config;
|
|
|
|
|
|
|
|
class Validation
|
|
|
|
{
|
|
|
|
public static function val_action($action)
|
|
|
|
{
|
|
|
|
if (!isset($action)) {
|
|
|
|
throw new \Exception('pas d\'action');
|
|
|
|
//on pourrait aussi utiliser
|
|
|
|
//$action = $_GET['action'] ?? 'no';
|
|
|
|
// This is equivalent to:
|
|
|
|
//$action = if (isset($_GET['action'])) $action=$_GET['action'] else $action='no';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function val_form(string &$nom, string &$age, &$dVueEreur)
|
|
|
|
{
|
|
|
|
if (!isset($nom) || $nom == '') {
|
|
|
|
$dVueEreur[] = 'pas de nom';
|
|
|
|
$nom = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(htmlspecialchars($nom, ENT_QUOTES) === 0)) {
|
|
|
|
$dVueEreur[] = "testative d'injection de code (attaque sécurité)";
|
|
|
|
$nom = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($age) || $age == '' || !filter_var($age, FILTER_VALIDATE_INT)) {
|
|
|
|
$dVueEreur[] = "pas d'age ";
|
|
|
|
$age = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fonction qui nettoie une chaine de caractères
|
|
|
|
* @param string $str
|
|
|
|
* @return string Chaine valide
|
|
|
|
*/
|
|
|
|
public static function nettoyerString(string $str) : string{
|
|
|
|
$newstr = preg_replace('/\x00|<[^>]*>?/', '', $str);
|
|
|
|
return str_replace(["'", '"'], [''', '"'], $newstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fonction qui valide si un entier est positif
|
|
|
|
* @param $int
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function validerIntPossitif($int){
|
|
|
|
return filter_var($int, FILTER_VALIDATE_INT, array("min_range"=>1));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fonction qui verifie si un email est correct
|
|
|
|
* @param string $str
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function verifierEmail(string $str):bool{
|
|
|
|
return filter_var($str, FILTER_VALIDATE_EMAIL);
|
|
|
|
}
|
|
|
|
}
|