20 self::startTemplateEngine ( $config );
21 if (isset ( $config [
"sessionName"] ))
23 self::forward ( $url );
27 $u = self::parseUrl ( $url );
29 if (\is_array ( $ru ))
30 self::runAction ( $ru );
35 $u [0] = self::$ctrlNS . $u [0];
36 if (\class_exists ( $u [0] )) {
37 self::runAction ( $u );
39 \header (
'HTTP/1.0 404 Not Found',
true, 404 );
40 print
"The controller `" . $u [0] .
"` doesn't exists! <br/>";
45 public static function getNS($part =
"controllers") {
47 $ns =
$config [
"mvcNS"] [$part];
48 if ($ns !==
"" && $ns !== null) {
55 self::$ctrlNS = self::getNS ();
63 $url = \substr ( $url, 0, strlen ( $url ) - 1 );
64 self::$urlParts = \explode (
"/", $url );
66 return self::$urlParts;
71 $engineOptions = array (
'cache' => ROOT . DS .
"views/cache/" );
72 if (isset (
$config [
"templateEngine"] )) {
73 $templateEngine =
$config [
"templateEngine"];
74 if (isset (
$config [
"templateEngineOptions"] )) {
75 $engineOptions =
$config [
"templateEngineOptions"];
77 $engine =
new $templateEngine ( $engineOptions );
79 self::$config [
"templateEngine"] = $engine;
82 }
catch ( \Exception $e ) {
83 echo $e->getTraceAsString ();
87 public static function runAction($u, $initialize =
true, $finalize =
true) {
90 self::$controller = $ctrl;
91 self::$action =
"index";
92 if (\
sizeof ( $u ) > 1)
93 self::$action = $u [1];
94 if (\
sizeof ( $u ) > 2)
95 self::$actionParams=array_slice ( $u, 2 );
99 print
"`{$u[0]}` isn't a controller instance.`<br/>";
116 if (\array_key_exists (
"di",
$config )) {
118 if (\is_array ( $di )) {
119 foreach ( $di as $k => $v ) {
126 public static function runAsString($u, $initialize =
true, $finalize =
true) {
128 self::runAction ( $u, $initialize, $finalize );
129 return \ob_get_clean ();
133 $urlSize =
sizeof ( $u );
136 $controller->
index ();
141 if (\method_exists ( $controller,
$action )) {
142 $controller->$action ();
144 print
"The method `{$action}` doesn't exists on controller `" . $u [0] .
"`<br/>";
149 \call_user_func_array ( array ($controller,$u [1] ), self::$actionParams );
155 return self::$config;
163 foreach ( $needs as $need ) {
164 if (! isset ( $array [$need] ) ||
UString::isNull ( $array [$need] )) {
173 $needs = [
"type",
"dbName",
"serverName" ];
174 if (! isset (
$config [
"database"] )) {
175 $result [] =
"database";
177 self::needsKeyInConfigArray ( $result,
$config [
"database"], $needs );
185 if (! isset (
$config [
"mvcNS"] )) {
186 $result [] =
"mvcNS";
188 self::needsKeyInConfigArray ( $result,
$config [
"mvcNS"], [
"models" ] );
194 return self::$config [
"mvcNS"] [
"models"];
198 return ROOT . DS . self::getModelsDir ();
201 public static function errorHandler($message =
"", $code = 0, $severity = 1, $filename = null,
int $lineno = 0, $previous = NULL) {
202 if (\error_reporting () == 0) {
205 if (\error_reporting () & $severity) {
206 throw new \ErrorException ( $message, 0, $severity, $filename, $lineno, $previous );
211 return self::$controller;
215 return (
new \ReflectionClass(self::$controller))->getShortName();
223 return self::$action;
227 return self::$actionParams;
231 return \dirname ( __FILE__ );
235 return \dirname ( ROOT );
239 return basename(\dirname ( ROOT ));
243 $appDir=\dirname ( ROOT );
244 $filename=$appDir.
"/app/config/config.php";
245 self::$config=include($filename);
246 self::startTemplateEngine(self::$config);
247 return self::$config;
251 $appDir=\dirname ( ROOT );
252 $filename=$appDir.
"/app/config/config.php";
253 $oldFilename=$appDir.
"/app/config/config.old.php";
254 if (!file_exists($filename) || copy($filename, $oldFilename)) {
static getModelsCompletePath()
static runAsString($u, $initialize=true, $finalize=true)
static injectDependences($controller, $config)
static getControllerSimpleName()
static run(array &$config, $url)
static setConfig($config)
static getNS($part="controllers")
Base class for controllers.
static getRoute($path, $cachedResponse=true)
static saveConfig($content)
static callController(Controller $controller, $u)
static runAction($u, $initialize=true, $finalize=true)
static getApplicationName()
static needsKeyInConfigArray(&$result, $array, $needs)
static start($name=null)
Start new or resume existing session.
static getViewNameFileExtension()
static getApplicationDir()
This file is part of Ubiquity framework.
static endswith($hay, $needle)
static startTemplateEngine($config)
static checkModelsConfig()
static errorHandler($message="", $code=0, $severity=1, $filename=null, int $lineno=0, $previous=NULL)
static save($filename, $content, $flags=LOCK_EX)