You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SAE_2A_FA-Reseau_ALICA/config/Validation.php

62 lines
1.8 KiB

<?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{
return filter_var($str, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE);
}
/**
* 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);
}
}