예제 #1
0
파일: router.php 프로젝트: qzsolt/framework
 public static function initialize()
 {
     self::getInstance();
     $controller = APP_PATH . DS . 'controllers' . DS . strtolower(self::replace('controller')) . '.php';
     if (file_exists($controller)) {
         include_once $controller;
         $controller = '\\controller\\' . ucfirst(self::replace('controller'));
         if (class_exists($controller, false)) {
             if (method_exists($controller, self::replace('method'))) {
                 if (sizeof(self::$params) == 0) {
                     call_user_func(array(new $controller(), self::replace('method')));
                 } else {
                     call_user_func_array(array(new $controller(), self::replace('method')), self::$params);
                 }
             } else {
                 if (self::$method != DEFAULT_METHOD) {
                     $params = array();
                     if (!in_array(self::$method, self::$params)) {
                         $params[] = self::$method;
                     }
                     self::$method = DEFAULT_METHOD;
                     self::$params = array_merge($params, self::$params);
                     return self::initialize();
                 }
             }
         }
     } else {
         if (self::$controller != DEFAULT_CONTROLLER) {
             $params = array();
             if (self::$controller != DEFAULT_CONTROLLER) {
                 $params[] = self::$controller;
             }
             if (self::$method != DEFAULT_METHOD) {
                 $params[] = self::$method;
             }
             $method = $params[0];
             if (self::$controller == $params[0]) {
                 array_shift($params);
             }
             self::$controller = DEFAULT_CONTROLLER;
             self::$method = $method;
             self::$params = array_merge($params, self::$params);
             return self::initialize();
         }
     }
 }