2016-11-06 16:04:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2016-11-08 08:54:59 +00:00
|
|
|
namespace error\core;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
|
|
|
|
2016-11-08 08:54:59 +00:00
|
|
|
class Error{
|
2016-11-06 16:04:17 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
/* Cyclic Hash Error */
|
|
|
|
// Expired
|
|
|
|
const CyclicHashExpired = 19;
|
|
|
|
|
2016-11-06 16:04:17 +00:00
|
|
|
/* 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){
|
2016-11-08 09:25:15 +00:00
|
|
|
case self::Success: return "All right man!"; break;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
case self::ParsingFailed: return "Parsing failed (json, xml, etc). Check your format."; break;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
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;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
case self::ParamError: return "Missing or wrong arguments."; break;
|
|
|
|
case self::ModuleError: return "Module error."; break;
|
|
|
|
case self::RepoError: return "Repository error."; break;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
case self::PDOConnection: return "Database connection failed."; break;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
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;
|
2016-11-06 16:04:17 +00:00
|
|
|
|
2016-11-08 09:25:15 +00:00
|
|
|
default: return "Unknown Error..."; break;
|
2016-11-06 16:04:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Erreur inconnue
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function setHttpCode($error){
|
|
|
|
http_response_code( $error == self::Success ? 200 : 417 );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|