2016-02-04 20:15:43 +00:00
|
|
|
<?php
|
|
|
|
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-10-18 17:09:47 +00:00
|
|
|
namespace error\core;
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
use \error\core\Err;
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2016-10-18 17:09:47 +00:00
|
|
|
class Error{
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
private $error = null;
|
|
|
|
private $arguments = [];
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
/* 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());
|
|
|
|
}
|
2016-07-21 19:12:53 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
/* ERROR GETTER
|
|
|
|
*
|
|
|
|
* @return Err<Err::Constant> Error
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get(){ return $this->error; }
|
2016-07-21 19:12:53 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* (2) On récupère les arguments */
|
|
|
|
$this->arguments = array_slice(func_get_args(), 1);
|
|
|
|
}
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2016-02-04 22:45:03 +00:00
|
|
|
|
|
|
|
/* EXPLICITE UN CODE D'ERREUR
|
|
|
|
*
|
|
|
|
* @return explicit<String> Description explicite du code d'erreur
|
|
|
|
*
|
|
|
|
*/
|
2017-01-30 17:39:21 +00:00
|
|
|
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;
|
2017-02-20 10:59:44 +00:00
|
|
|
case Err::ConfigError: return $this->ConfigError(); break;
|
2017-01-30 17:39:21 +00:00
|
|
|
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;
|
2017-02-20 10:59:44 +00:00
|
|
|
case Err::AlreadyExists: return $this->AlreadyExists(); break;
|
2017-01-30 17:39:21 +00:00
|
|
|
|
|
|
|
default: return $this->UnknownDebugError(); break;
|
2016-02-04 22:45:03 +00:00
|
|
|
}
|
2017-01-30 17:39:21 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 22:45:03 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
private function Success(){
|
|
|
|
return 'all right';
|
|
|
|
}private function ParsingFailed(){
|
|
|
|
if( count($this->arguments) > 0 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "{$this->arguments[0]} parsing failed";
|
2017-01-30 17:39:21 +00:00
|
|
|
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(){
|
|
|
|
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 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "unknown module '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
else
|
|
|
|
return 'unknown module';
|
|
|
|
}private function UnknownMethod(){
|
|
|
|
if( count($this->arguments) > 0 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "unknown method '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
else
|
|
|
|
return 'unknown method';
|
|
|
|
}private function UncallableModule(){
|
|
|
|
if( count($this->arguments) > 0 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "uncallable module '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
else
|
|
|
|
return 'uncallable module';
|
|
|
|
}private function UncallableMethod(){
|
|
|
|
if( count($this->arguments) > 0 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "uncallable method '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
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 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "missing param '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
else
|
|
|
|
return 'missing param';
|
|
|
|
}private function WrongParam(){
|
|
|
|
if( count($this->arguments) > 0 )
|
|
|
|
if( count($this->arguments) > 1 )
|
2017-02-20 10:59:44 +00:00
|
|
|
return "wrong param '{$this->arguments[0]}' expected to be of type '{$this->arguments[1]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
else
|
2017-02-20 10:59:44 +00:00
|
|
|
return "wrong param '{$this->arguments[0]}'";
|
2017-01-30 17:39:21 +00:00
|
|
|
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 UnknownDebugError(){
|
|
|
|
return 'unknown debug error';
|
2017-02-20 10:59:44 +00:00
|
|
|
}private function AlreadyExists(){
|
|
|
|
if( count($this->arguments) > 0 )
|
|
|
|
return "'{$this->arguments[0]}' already exists";
|
|
|
|
|
|
|
|
return 'entry already exists';
|
2016-02-04 22:45:03 +00:00
|
|
|
}
|
2016-02-04 20:15:43 +00:00
|
|
|
|
2016-07-02 15:10:41 +00:00
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
public function setHttpCode(){
|
|
|
|
http_response_code( $this->error == Err::Success ? 200 : 417 );
|
2016-07-02 15:10:41 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 20:15:43 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 17:39:21 +00:00
|
|
|
|
2016-07-02 15:10:41 +00:00
|
|
|
?>
|