upd: build/error/core (added new errors)
This commit is contained in:
parent
72321d4646
commit
d97f81c2bc
|
@ -1,2 +0,0 @@
|
|||
Order deny,allow
|
||||
Deny from all
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace error\core;
|
||||
|
||||
|
||||
class Err{
|
||||
/* [1] Success
|
||||
=========================================================*/
|
||||
const Success = 0;
|
||||
|
||||
|
||||
/* [2] Fichiers / Ressources
|
||||
=========================================================*/
|
||||
/* (1) Parsage json/xml */
|
||||
const ParsingFailed = 1;
|
||||
/* (2) Fichier inexistant */
|
||||
const UnreachableResource = 2;
|
||||
/* (3) Erreur d'upload */
|
||||
const UploadError = 3;
|
||||
/* (4) Mauvais format de fichier */
|
||||
const FormatError = 4;
|
||||
|
||||
|
||||
/* [3] Permissions
|
||||
=========================================================*/
|
||||
/* (1) Token inexistant ou incorrect */
|
||||
const TokenError = 5;
|
||||
/* (2) Permission non autorisée */
|
||||
const PermissionError = 6;
|
||||
|
||||
|
||||
|
||||
|
||||
/* [4] API
|
||||
=========================================================*/
|
||||
/* (1) Le module n'est pas activé */
|
||||
const DisabledModule = 7;
|
||||
|
||||
/* (2) Le @path n'est pas renseigne */
|
||||
const MissingPath = 8;
|
||||
/* (3) Verification de la coherence du chemin (existe dans la conf) */
|
||||
const WrongPathModule = 9;
|
||||
|
||||
/* (4) Module non specifie dans la conf */
|
||||
const UnknownModule = 10;
|
||||
/* (5) Methode non specifie pour ce Module dans la conf */
|
||||
const UnknownMethod = 11;
|
||||
|
||||
/* (6) Module non amorcable */
|
||||
const UncallableModule = 12;
|
||||
/* (7) Methode non amorcable */
|
||||
const UncallableMethod = 13;
|
||||
|
||||
/* (8) Erreur méthode HTTP */
|
||||
const UnknownHttpMethod = 14;
|
||||
|
||||
/* (9) Erreur de configuration */
|
||||
const ConfigError = 15;
|
||||
/* (10) Paramètre manquant */
|
||||
const MissingParam = 16;
|
||||
/* (11) Paramètre incorrect */
|
||||
const WrongParam = 17;
|
||||
/* (12) Erreur dans le traitement */
|
||||
const ModuleError = 18;
|
||||
|
||||
|
||||
/* [5] Database
|
||||
=========================================================*/
|
||||
/* (1) Base de données
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Erreur lors de la creation d'un objet PDO (connection) */
|
||||
const PDOConnection = 19;
|
||||
|
||||
/* (2) Repositories
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Verification de la coherence du chemin (existe dans la conf) */
|
||||
const WrongPathRepo = 20;
|
||||
|
||||
/* (2) Module non specifie dans la conf */
|
||||
const UnknownRepo = 21;
|
||||
|
||||
/* (3) Erreur dans le traitement */
|
||||
const RepoError = 22;
|
||||
|
||||
/* (3) ORM
|
||||
---------------------------------------------------------*/
|
||||
/* (1) Table n'existe pas */
|
||||
const UnknownTable = 23;
|
||||
/* (2) Pas permissions de lire le schéma */
|
||||
const NotAllowedSchema = 24;
|
||||
|
||||
|
||||
/* [6] Erreurs diverses
|
||||
=========================================================*/
|
||||
|
||||
/* (1) Aucune donnée trouvée */
|
||||
const NoMatchFound = 25;
|
||||
|
||||
/* (2) Mauvais chemin de template */
|
||||
const UnknownTemplate = 26;
|
||||
|
||||
/* (3) géolocalisation échouée */
|
||||
const UnknownAddress = 27;
|
||||
|
||||
/* (4) Erreur inconnue */
|
||||
const UnknownError = 28;
|
||||
|
||||
/* (5) Entrée existante */
|
||||
const AlreadyExists = 29;
|
||||
|
||||
/* (6) Corps manquant */
|
||||
const MissingBody = 30;
|
||||
|
||||
/* (7) Header manquant */
|
||||
const MissingHeaders = 31;
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,130 +3,201 @@
|
|||
|
||||
namespace error\core;
|
||||
|
||||
use \error\core\Err;
|
||||
|
||||
class Error{
|
||||
|
||||
/* SUCCESS */
|
||||
const Success = 0;
|
||||
private $error = null;
|
||||
private $arguments = [];
|
||||
|
||||
/* Parsage json */
|
||||
const ParsingFailed = 1;
|
||||
/* ERROR CONSTRUCTOR
|
||||
*
|
||||
* @error<const> Const error
|
||||
* @arg1<String> [OPT] Argument 1
|
||||
* @arg2<String> [OPT] Argument 2
|
||||
* @arg...<String> [OPT] Argument ...
|
||||
*
|
||||
* @return instance<Error> Error instance
|
||||
*
|
||||
*/
|
||||
public function __construct($const){
|
||||
call_user_func_array([$this, 'set'], func_get_args());
|
||||
}
|
||||
|
||||
/* ResourceDispatcher */
|
||||
/* ERROR GETTER
|
||||
*
|
||||
* @return Err<Err::Constant> Error
|
||||
*
|
||||
*/
|
||||
public function get(){ return $this->error; }
|
||||
|
||||
// Drapeaux invalides
|
||||
const InvalidFlags = 2;
|
||||
/* ERROR SETTER
|
||||
*
|
||||
* @error<const> Const error
|
||||
* @arg1<String> [OPT] Argument 1
|
||||
* @arg2<String> [OPT] Argument 2
|
||||
* @arg...<String> [OPT] Argument ...
|
||||
*
|
||||
* @return instance<Error> Error instance
|
||||
*
|
||||
*/
|
||||
public function set($const){
|
||||
/* [1] On découpe les arguments
|
||||
=========================================================*/
|
||||
/* (1) On récupère l'erreur */
|
||||
$this->error = !is_numeric($const) ? Err::UnknownError : $const;
|
||||
|
||||
// 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
|
||||
/* (2) On récupère les arguments */
|
||||
$this->arguments = array_slice(func_get_args(), 1);
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
public function explicit(){
|
||||
switch($this->error){
|
||||
case Err::Success: return $this->Success(); break;
|
||||
case Err::ParsingFailed: return $this->ParsingFailed(); break;
|
||||
case Err::UnreachableResource: return $this->UnreachableResource(); break;
|
||||
case Err::UploadError: return $this->UploadError(); break;
|
||||
case Err::FormatError: return $this->FormatError(); break;
|
||||
case Err::TokenError: return $this->TokenError(); break;
|
||||
case Err::PermissionError: return $this->PermissionError(); break;
|
||||
case Err::DisabledModule: return $this->DisabledModule(); break;
|
||||
case Err::MissingPath: return $this->MissingPath(); break;
|
||||
case Err::WrongPathModule: return $this->WrongPathModule(); break;
|
||||
case Err::UnknownModule: return $this->UnknownModule(); break;
|
||||
case Err::UnknownMethod: return $this->UnknownMethod(); break;
|
||||
case Err::UncallableModule: return $this->UncallableModule(); break;
|
||||
case Err::UncallableMethod: return $this->UncallableMethod(); break;
|
||||
case Err::UnknownHttpMethod: return $this->UnknownHttpMethod(); break;
|
||||
case Err::ConfigError: return $this->ConfigError(); break;
|
||||
case Err::MissingParam: return $this->MissingParam(); break;
|
||||
case Err::WrongParam: return $this->WrongParam(); break;
|
||||
case Err::ModuleError: return $this->ModuleError(); break;
|
||||
case Err::PDOConnection: return $this->PDOConnection(); break;
|
||||
case Err::WrongPathRepo: return $this->WrongPathRepo(); break;
|
||||
case Err::UnknownRepo: return $this->UnknownRepo(); break;
|
||||
case Err::RepoError: return $this->RepoError(); break;
|
||||
case Err::UnknownTable: return $this->UnknownTable(); break;
|
||||
case Err::NotAllowedSchema: return $this->NotAllowedSchema(); break;
|
||||
case Err::NoMatchFound: return $this->NoMatchFound(); break;
|
||||
case Err::UnknownTemplate: return $this->UnknownTemplate(); break;
|
||||
case Err::UnknownAddress: return $this->UnknownAddress(); break;
|
||||
case Err::UnknownError: return $this->UnknownError(); break;
|
||||
case Err::AlreadyExists: return $this->AlreadyExists(); break;
|
||||
case Err::MissingBody: return $this->MissingBody(); break;
|
||||
case Err::MissingHeaders: return $this->MissingHeaders(); 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;
|
||||
default: return $this->UnknownDebugError(); break;
|
||||
}
|
||||
|
||||
// Erreur inconnue
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function setHttpCode($error){
|
||||
http_response_code( $error == self::Success ? 200 : 417 );
|
||||
private function Success(){
|
||||
return 'all right';
|
||||
}private function ParsingFailed(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return $this->arguments[0].' parsing failed';
|
||||
else
|
||||
return 'parsing failed';
|
||||
}private function UnreachableResource(){
|
||||
return 'unreachable resource';
|
||||
}private function UploadError(){
|
||||
return 'upload error';
|
||||
}private function FormatError(){
|
||||
return 'format error';
|
||||
}private function TokenError(){
|
||||
return 'bad or expired token';
|
||||
}private function PermissionError(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return "missing permission: '".$this->arguments[0]."'";
|
||||
else
|
||||
return 'permission error';
|
||||
}private function DisabledModule(){
|
||||
return 'disabled module';
|
||||
}private function MissingPath(){
|
||||
return 'missing path';
|
||||
}private function WrongPathModule(){
|
||||
return 'wrong module\'s path';
|
||||
}private function UnknownModule(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return 'unknown module \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'unknown module';
|
||||
}private function UnknownMethod(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return 'unknown method \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'unknown method';
|
||||
}private function UncallableModule(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return 'uncallable module \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'uncallable module';
|
||||
}private function UncallableMethod(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return 'uncallable method \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'uncallable method';
|
||||
}private function UnknownHttpMethod(){
|
||||
return 'unknown HTTP method';
|
||||
}private function ConfigError(){
|
||||
return 'configuration error';
|
||||
}private function MissingParam(){
|
||||
if( count($this->arguments) > 0 )
|
||||
return 'missing param \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'missing param';
|
||||
}private function WrongParam(){
|
||||
if( count($this->arguments) > 0 )
|
||||
if( count($this->arguments) > 1 )
|
||||
return 'wrong param \''.$this->arguments[0].'\' expected to be of type \''.$this->arguments[1].'\'';
|
||||
else
|
||||
return 'wrong param \''.$this->arguments[0].'\'';
|
||||
else
|
||||
return 'wrong param';
|
||||
}private function ModuleError(){
|
||||
return 'module error';
|
||||
}private function PDOConnection(){
|
||||
return 'database error';
|
||||
}private function WrongPathRepo(){
|
||||
return 'wrong repository\'s path';
|
||||
}private function UnknownRepo(){
|
||||
return 'unknown repository';
|
||||
}private function RepoError(){
|
||||
return 'repository error';
|
||||
}private function UnknownTable(){
|
||||
return 'unknown table';
|
||||
}private function NotAllowedSchema(){
|
||||
return 'schema browsing not allowed';
|
||||
}private function NoMatchFound(){
|
||||
return 'no match found';
|
||||
}private function UnknownTemplate(){
|
||||
return 'unknown template';
|
||||
}private function UnknownAddress(){
|
||||
return 'unknown';
|
||||
}private function UnknownError(){
|
||||
return 'unknown error';
|
||||
}private function AlreadyExists(){
|
||||
return 'item already exists';
|
||||
}private function MissingBody(){
|
||||
return 'body is missing';
|
||||
}private function MissingHeaders(){
|
||||
return 'headers are missing';
|
||||
}private function UnknownDebugError(){
|
||||
return 'unknown debug error';
|
||||
}
|
||||
|
||||
|
||||
public function setHttpCode(){
|
||||
http_response_code( $this->error == Err::Success ? 200 : 417 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue