mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-07-29 06:09:50 +00:00
page de recher plus modifs vers un system de controllers
This commit is contained in:
36
assets/php/Controller.php
Normal file
36
assets/php/Controller.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class Controller {
|
||||
|
||||
public function getContent(String $route, $loader) {
|
||||
$map = array_filter(CLASSMAP, function($var) {
|
||||
return strpos($var, "App\Controller\\") === 0;
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
foreach ($map as $key => $t) {
|
||||
$loader->loadClass($key);
|
||||
}
|
||||
foreach (get_declared_classes() as $class) {
|
||||
if(is_subclass_of( $class, 'App\Controller')) {
|
||||
$r = new ReflectionClass($class);
|
||||
foreach ($r->getMethods() as $method) {
|
||||
preg_match_all('#@(.*?)\n#s', $method->getDocComment(), $annotations);
|
||||
foreach ($annotations[1] as $annot) {
|
||||
$arr = preg_split("/ /", $annot);
|
||||
if($arr[0] === "route") {
|
||||
if(preg_match($arr[1], $route)) {
|
||||
$instance = new $class();
|
||||
$function = ($method->getName());
|
||||
return $instance->$function();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user