31 public static function forward(
string $url,
bool $initialize =
true,
bool $finalize =
true): void {
32 $methodUrl=$_SERVER[
'REQUEST_METHOD'].$url;
33 if(isset(self::$routes[$methodUrl])){
34 $m=self::$routes[$methodUrl];
35 $m($initialize,$finalize);
40 if (\is_array ( $ru )) {
41 if (isset ( $ru [
'controller'] )) {
42 (self::$routes[$methodUrl]=
function($i,$f)use($ru){
43 static::runAction ( $ru, $i, $f );
44 })($initialize,$finalize);
46 (self::$routes[$methodUrl]=
function() use($ru){
51 (self::$routes[$methodUrl]=
function() use($ru){
57 $ru =[
'controller'=>self::$ctrlNS . $u [0],
'action'=> $u [1]??
'index',
'params'=> \array_slice ( $u, 2 )];
58 (self::$routes[$methodUrl]=
function($i,$f)use($ru){
59 static::runAction ( $ru, $i, $f );
60 })($initialize,$finalize);
64 public static function runAction(array &$u,
bool $initialize =
true,
bool $finalize =
true): void {
65 self::$controller = $ctrl = $u [
'controller'];
66 self::$action = $action = $u [
'action'];
67 self::$actionParams = $u[
'params']??[];
70 if (
null !== $controller = self::getControllerInstance ( $ctrl )) {
71 if($mainParams=$u[
'mainParams']??
false){
72 static::setMainParams($controller,$mainParams);
74 $binaryCalls = $controller->_binaryCalls ?? (self::IS_VALID + self::INITIALIZE + self::FINALIZE);
75 if (($binaryCalls & self::IS_VALID) && ! $controller->isValid ( $action )) {
76 $controller->onInvalidControl ();
78 if (($binaryCalls & self::INITIALIZE) && $initialize) {
79 $controller->initialize ();
82 $controller->$action ( ...(self::$actionParams) );
83 }
catch ( \Error $e ) {
84 if (! \method_exists ( $controller, $action )) {
85 static::onError ( 404,
"This action does not exist on the controller " . $ctrl, $controller );
87 static::logError($e->getCode(), $e->getMessage());
88 if (self::$config [
'debug']) {
91 static::onError ( 500, $e->getMessage (), $controller );
95 if (($binaryCalls & self::FINALIZE) && $finalize) {
96 $controller->finalize ();
100 Logger::warn (
'Startup',
'The controller `' . $ctrl .
'` doesn\'t exist! <br/>',
'runAction' );
101 static::onError ( 404 );
103 }
catch ( \Error $eC ) {
104 static::logError($eC->getCode(), $eC->getMessage());
105 if (self::$config [
'debug']) {
108 static::onError ( 500, $eC->getMessage () );