133 lines
4.2 KiB
PHP
Executable File
133 lines
4.2 KiB
PHP
Executable File
<?php
|
|
|
|
|
|
namespace error\core;
|
|
|
|
|
|
class Error{
|
|
|
|
/* SUCCESS */
|
|
const Success = 0;
|
|
|
|
/* Parsage json */
|
|
const ParsingFailed = 1;
|
|
|
|
/* ResourceDispatcher */
|
|
|
|
// Drapeaux invalides
|
|
const InvalidFlags = 2;
|
|
|
|
// Fichier inexistant
|
|
const UnreachableResource = 3;
|
|
|
|
|
|
/* ModuleRequest */
|
|
|
|
// Le @path n'est pas renseigne
|
|
const MissingPath = 4;
|
|
|
|
// Verification de la coherence du chemin (existe dans la conf)
|
|
const WrongPathModule = 5;
|
|
|
|
// Module non specifie dans la conf
|
|
const UnknownModule = 6;
|
|
|
|
// Methode non specifie pour ce Module dans la conf
|
|
const UnknownMethod = 7;
|
|
|
|
// Methode inamorcable
|
|
const UncallableMethod = 8;
|
|
|
|
// Erreur de parametre(s)
|
|
const ParamError = 9;
|
|
|
|
// Erreur dans le traitement
|
|
const ModuleError = 10;
|
|
|
|
/* Repo */
|
|
|
|
// Verification de la coherence du chemin (existe dans la conf)
|
|
const WrongPathRepo = 11;
|
|
|
|
// Module non specifie dans la conf
|
|
const UnknownRepo = 12;
|
|
|
|
// Erreur dans le traitement
|
|
const RepoError = 13;
|
|
|
|
/* Database */
|
|
|
|
// Erreur lors de la creation d'un objet PDO (connection)
|
|
const PDOConnection = 14;
|
|
|
|
/* API token */
|
|
// Token inexistant ou faux
|
|
const TokenError = 15;
|
|
|
|
const PermissionError = 16;
|
|
|
|
/* Erreur d'UPLOAD */
|
|
const UploadError = 17;
|
|
|
|
// Mauvais format de fichier
|
|
const FormatError = 18;
|
|
|
|
/* Cyclic Hash Error */
|
|
// Expired
|
|
const CyclicHashExpired = 19;
|
|
|
|
/* Erreur au niveau javascript */
|
|
//const JavascriptError = 19; // -> géré en js
|
|
|
|
|
|
/* EXPLICITE UN CODE D'ERREUR
|
|
*
|
|
* @error<Integer> Code d'erreur
|
|
*
|
|
* @return explicit<String> Description explicite du code d'erreur
|
|
*
|
|
*/
|
|
public static function explicit($error){
|
|
switch($error){
|
|
case self::Success: return "All right man!"; break;
|
|
|
|
case self::ParsingFailed: return "Parsing failed (json, xml, etc). Check your format."; break;
|
|
|
|
case self::InvalidFlags: return "You sent invalid flags."; break;
|
|
case self::UnreachableResource: return "Resource unreachable."; break;
|
|
case self::MissingPath: return "The @path is missing"; break;
|
|
case self::WrongPathModule: return "Invalid @path ('moduleName/methodName')."; break;
|
|
case self::WrongPathRepo: return "Invalid @path ('repoName/methodName')."; break;
|
|
case self::UnknownModule: return "Module not found."; break;
|
|
case self::UnknownRepo: return "Repository not found."; break;
|
|
case self::UnknownMethod: return "The method doesn't exist."; break;
|
|
case self::UncallableMethod: return "The method can't be called."; break;
|
|
|
|
case self::ParamError: return "Missing or wrong arguments."; break;
|
|
case self::ModuleError: return "Module error."; break;
|
|
case self::RepoError: return "Repository error."; break;
|
|
|
|
case self::PDOConnection: return "Database connection failed."; break;
|
|
|
|
case self::TokenError: return "Missing or wrong token."; break;
|
|
case self::PermissionError: return "Permission denied."; break;
|
|
case self::UploadError: return "Upload error"; break;
|
|
case self::FormatError: return "Format error."; break;
|
|
case self::CyclicHashExpired: return "Cyclic hash has to be renewed."; break;
|
|
|
|
default: return "Unknown Error..."; break;
|
|
}
|
|
|
|
// Erreur inconnue
|
|
return null;
|
|
}
|
|
|
|
|
|
public static function setHttpCode($error){
|
|
http_response_code( $error == self::Success ? 200 : 417 );
|
|
}
|
|
|
|
}
|
|
|
|
?>
|