Skip to content

Commit 65bacda

Browse files
committed
dev
1 parent 7c0bf97 commit 65bacda

File tree

2 files changed

+97
-575
lines changed

2 files changed

+97
-575
lines changed

MVC.php

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
/**
44
* MVC.php
55
* @author Fábio Nogueira
6-
* @version 0.0.3
6+
* @version 0.0.4
77
*/
88

99
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';
1116

1217
class MVC{
1318
private static $_config = array();
@@ -113,27 +118,15 @@ public static function getParameter($index){
113118
public static function getConfig(){
114119
return self::$_config;
115120
}
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);
132123
}
133124
public static function run(){
125+
$cfg = self::$_config;
126+
134127
//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']);
137130

138131
//separa a url em controller, action e parâmetros
139132
self::splitUrl();
@@ -142,16 +135,12 @@ public static function run(){
142135
self::info();
143136
}
144137

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']);
150139
$modelClassName = self::$_url['controller']=='' ? 'MainModel' : ucfirst(self::$_url['controller'] . 'Model');
151140
$actionName = self::$_url['action'];
152141

153142
//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')) {
155144
self::routerError('controller not found');
156145
}else{
157146
if (!file_exists(ROOT.'model/' . $modelClassName . '.php')){
@@ -162,7 +151,7 @@ public static function run(){
162151
require __DIR__.'/Model.php';
163152
}
164153

165-
if (self::$_config['ajax'] && function_exists("ajax_bootstrap") ){
154+
if ($cfg['ajax'] && function_exists("ajax_bootstrap") ){
166155
ajax_bootstrap();
167156
}
168157

0 commit comments

Comments
 (0)