26 foreach($this->controllerNamespaces as $namespace => $prefix)
27 if(($class_name == $namespace) || \
Rsi\Str::startsWith($class_name,$namespace))
28 return $prefix . str_replace(
'\\',
'/',substr($class_name,strlen($namespace)));
37 foreach($this->controllerNamespaces as $namespace => $prefix)
if(
38 (!$prefix || ($name == $prefix) || \
Rsi\Str::startsWith($name,$prefix .
'/')) &&
39 class_exists($class_name = $namespace . str_replace(
'/',
'\\',$prefix ? substr($name,strlen($prefix)) :
'\\' . $name)) &&
40 is_subclass_of($class_name,__NAMESPACE__ .
'\\Controller')
52 $this->
component(
'log')->debug(__CLASS__ .
"::controller('$name')",__FILE__,__LINE__);
56 !($class_name = $this->
controllerClassName($name = $name ? $this->unknownControllerName : $this->defaultControllerName))
57 )
throw new \DomainException(
"Controller for '$name' does not exists");
58 $controller =
new $class_name($this->_fred,array_replace_recursive(
59 $this->_fred->config(
'controller',[]),
60 $this->_fred->config(array_merge([
'controllers'],array_map(
'lcfirst',explode(
'/',$name))),[])
63 if(!$user->authenticated($controller->authSets) || !$user->authorized($controller->right))
64 $controller = $redir ? $this->
controller($user->authenticationControllerName ?: $this->deniedControllerName) :
false;
74 $timer = $log->start(
Log::DEBUG,__CLASS__ .
'::execute: router',__FILE__,__LINE__);
76 $request->viewControllerName = $name = $controller->name;
77 $log->stop($timer,null,null,__FILE__,__LINE__);
78 $this->
component(
'alive')->journal($name .
'::' . $controller->action);
79 $timer = $log->start(
Log::DEBUG,__CLASS__ .
'::execute: $controller->execute()',__FILE__,__LINE__);
80 $controller->execute();
81 $log->stop($timer,null,null,__FILE__,__LINE__);
82 if($request->viewControllerName != $name) $controller = $this->
controller($request->viewControllerName);
83 else $controller->reset();
84 foreach($request->errors as $id => $error) $this->
component(
'message')->error($error,
false);
85 $timer = $log->start(
Log::DEBUG,__CLASS__ .
'::execute: $controller->view->render()',__FILE__,__LINE__);
86 $this->
component(
'event')->trigger(self::EVENT_RENDER,$this,$controller);
87 $controller->view->render();
88 $log->stop($timer,null,null,__FILE__,__LINE__);
controllerClassName($name)
Class name for a controller.
execute()
Execute the request and render the view.
$controllerNamespaces
Namespace prefix (key) per controller name prefix (value).
const DEBUG
Debug-level message.
controller($name, $redir=true)
Get controller by name.
Front controller component.
controllerName($class_name)
Name for a controller by class name.
components(... $names)
Get multiple components in an array.
component($name)
Get a component (local or default).
$validControllerName
Regex for valid controller names (empty = do not check).