62 lines
1.4 KiB
PHP
Executable File
62 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
/**************************
|
|
* Route *
|
|
* 08-12-2016 *
|
|
***************************
|
|
* Designed & Developed by *
|
|
* xdrm-brackets *
|
|
***************************
|
|
* https://xdrm.io/ *
|
|
**************************/
|
|
|
|
namespace router\core;
|
|
|
|
|
|
class ControllerFactory{
|
|
|
|
|
|
/* VERIFIE UN CONTROLLER
|
|
*
|
|
* @controller<String> Nom du controller
|
|
*
|
|
* @return exists<boolean> Si oui ou non le controller existe
|
|
*
|
|
*/
|
|
public static function checkController($controller){
|
|
/* (1) Check type + pattern */
|
|
if( !is_string($controller) || !preg_match('/^[A-Za-z_]\w+$/', $controller) )
|
|
return false;
|
|
|
|
/* (2) On vérifie que la classe existe */
|
|
if( !file_exists(__BUILD__."/router/controller/$controller.php") )
|
|
return false;
|
|
|
|
/* (3) Sinon il existe */
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
/* INSTANCIE UN CONTROLLER
|
|
*
|
|
* @controller<String> Nom du controller
|
|
* @arguments<Array> [OPTIONNEL] Arguments à passer au constructeur
|
|
*
|
|
* @return instance<Module> Instance du controller en question
|
|
*
|
|
*/
|
|
public static function getController($controller, $arguments=[]){
|
|
/* (1) On vérifie l'existance du controller */
|
|
if( !self::checkController($controller) )
|
|
return false;
|
|
|
|
/* (2) On récupère la classe */
|
|
$class_name = "\\router\\controller\\$controller";
|
|
|
|
/* (3) On retourne une instance */
|
|
return new $class_name($arguments);
|
|
}
|
|
|
|
}
|