3
3
/**
4
4
* MVC.php
5
5
* @author Fábio Nogueira
6
- * @version 0.0.3
6
+ * @version 0.0.4
7
7
*/
8
8
9
9
error_reporting (E_ALL & ~E_NOTICE );
10
- define ('MVC_VERSION ' , '0.0.2 ' );
10
+ define ('MVC_VERSION ' , '0.0.4 ' );
11
+
12
+ //carrega classes do core
13
+ require __DIR__ .'/Session.php ' ;
14
+ require __DIR__ .'/View.php ' ;
15
+ require __DIR__ .'/Controller.php ' ;
11
16
12
17
class MVC {
13
18
private static $ _config = array ();
@@ -113,27 +118,15 @@ public static function getParameter($index){
113
118
public static function getConfig (){
114
119
return self ::$ _config ;
115
120
}
116
- public static function config ($ config , &$ level =NULL ){
117
- foreach ($ config as $ key =>$ value ){
118
- if (is_array ($ value )){
119
- self ::$ _config [$ key ] = (isset (self ::$ _config [$ key ]) ? self ::$ _config [$ key ] : array ());
120
- self ::config ($ value , self ::$ _config [$ key ]);
121
- }else {
122
- if (is_null ($ level )){
123
- self ::$ _config [$ key ] = $ value ;
124
- }else {
125
- if (!is_array ($ level )){
126
- $ level = array ();
127
- }
128
- $ level [$ key ] = $ value ;
129
- }
130
- }
131
- }
121
+ public static function config ($ config ){
122
+ self ::$ _config = array_merge_recursive (self ::$ _config , $ config );
132
123
}
133
124
public static function run (){
125
+ $ cfg = self ::$ _config ;
126
+
134
127
//define algumas constantes úteis
135
- define ('TEMPLATE ' , self :: $ _config ['template ' ]);
136
- define ('BASE_URL ' , self :: $ _config ['url ' ]['base ' ]);
128
+ define ('TEMPLATE ' , $ cfg ['template ' ]);
129
+ define ('BASE_URL ' , $ cfg ['url ' ]['base ' ]);
137
130
138
131
//separa a url em controller, action e parâmetros
139
132
self ::splitUrl ();
@@ -142,16 +135,12 @@ public static function run(){
142
135
self ::info ();
143
136
}
144
137
145
- //carrega classes do core
146
- require __DIR__ .'/View.php ' ;
147
- require __DIR__ .'/Controller.php ' ;
148
-
149
- $ controllerClassName = self ::$ _url ['controller ' ]=='' ? 'MainController ' : ucfirst (self ::$ _url ['controller ' ] . self ::$ _config ['controllerSufix ' ]);
138
+ $ controllerClassName = self ::$ _url ['controller ' ]=='' ? 'MainController ' : ucfirst (self ::$ _url ['controller ' ] . $ cfg ['controllerSufix ' ]);
150
139
$ modelClassName = self ::$ _url ['controller ' ]=='' ? 'MainModel ' : ucfirst (self ::$ _url ['controller ' ] . 'Model ' );
151
140
$ actionName = self ::$ _url ['action ' ];
152
141
153
142
//se o arquivo do controller não existe
154
- if (!file_exists (ROOT . self :: $ _config ['controllerPath ' ] . $ controllerClassName . '.php ' )) {
143
+ if (!file_exists (ROOT .$ cfg ['controllerPath ' ] . $ controllerClassName . '.php ' )) {
155
144
self ::routerError ('controller not found ' );
156
145
}else {
157
146
if (!file_exists (ROOT .'model/ ' . $ modelClassName . '.php ' )){
@@ -162,7 +151,7 @@ public static function run(){
162
151
require __DIR__ .'/Model.php ' ;
163
152
}
164
153
165
- if (self :: $ _config ['ajax ' ] && function_exists ("ajax_bootstrap " ) ){
154
+ if ($ cfg ['ajax ' ] && function_exists ("ajax_bootstrap " ) ){
166
155
ajax_bootstrap ();
167
156
}
168
157
0 commit comments