Ejemplo n.º 1
0
 /**
  * MVCクラスモジュールの読み込み処理
  * @param string クラス名
  * @param string クラスの読み込事にエラーが在る場合にbooleanを返すかどうか
  * @param string クラスの読み込事にエラーが在る場合にbooleanを返すかどうか
  * @return mixed 成功時は対象のクラス名 失敗した場合はFALSEを返す
  */
 public static function loadMVCModule($argClassName = NULL, $argClassExistsCalled = FALSE, $argTargetPath = '')
 {
     static $currentTargetPath = '';
     $targetPath = '';
     if (NULL !== $argClassName) {
         $controlerClassName = $argClassName;
     } else {
         // コントロール対象を自動特定
         $controlerClassName = 'Index';
         if (isset($_GET['_c_']) && strlen($_GET['_c_']) > 0) {
             $controlerClassName = str_replace('-', '_', ucfirst($_GET['_c_']));
             if (FALSE !== strpos($_GET['_c_'], '/') && strlen($_GET['_c_']) > 1) {
                 $matches = NULL;
                 if (preg_match('/(.*)\\/([^\\/]*)$/', $_GET['_c_'], $matches) && is_array($matches) && isset($matches[2])) {
                     $controlerClassName = str_replace('-', '_', ucfirst($matches[2]));
                     if (isset($matches[1]) && strlen($matches[1]) > 0) {
                         $targetPath = $matches[1] . '/';
                         if ('' === $currentTargetPath) {
                             $currentTargetPath = $targetPath;
                         }
                     }
                 }
             }
         }
     }
     if ('' !== $argTargetPath) {
         $targetPath = $argTargetPath;
     }
     if ('' === $targetPath) {
         $targetPath = $currentTargetPath;
     }
     $version = '';
     if (isset($_GET['_v_']) && strlen($_GET['_v_']) > 0) {
         $version = $_GET['_v_'];
     }
     debug('path=' . $targetPath);
     debug('class=' . $controlerClassName);
     if (!class_exists($controlerClassName, FALSE)) {
         // コントローラを読み込み
         if ('' !== $version) {
             // バージョン一致のファイルを先ず走査する
             loadModule('default.controlmain.' . $targetPath . $version . '/' . $controlerClassName, TRUE);
         }
         if (!class_exists($controlerClassName, FALSE)) {
             loadModule('default.controlmain.' . $targetPath . $controlerClassName, TRUE);
         }
         if (!class_exists($controlerClassName, FALSE)) {
             loadModule('default.controlmain.' . $controlerClassName, TRUE);
         }
         if (class_exists($controlerClassName, FALSE)) {
             // FlowGenerateする必要がなさそうなのでココで終了
             return $controlerClassName;
         } else {
             if ('' === self::$flowXMLBasePath) {
                 // エラー終了
                 return FALSE;
             } else {
                 // ココからはFlow処理
                 if (TRUE === self::$flowXMLBasePath) {
                     // self::$flowXMLBasePathがTRUEとなっていた場合はConfigureにFLOWXML_PATH定義が無いか調べる
                     if (class_exists('Configure', FALSE) && NULL !== Configure::constant('FLOWXML_PATH')) {
                         self::$flowXMLBasePath = Configure::FLOWXML_PATH;
                     }
                 }
                 // Flow出来ない!
                 if ('' === self::$flowXMLBasePath) {
                     // エラー終了
                     return FALSE;
                 }
                 // XML定義の存在チェック
                 // クラス名は分解しておく
                 $classHint = explode('_', $controlerClassName);
                 debug($targetPath);
                 debug($classHint);
                 $classXMLName = $classHint[0];
                 debug($classXMLName);
                 $flowXMLPath = '';
                 if ('' !== $version) {
                     // バージョン一致のファイルを先ず走査する
                     if (file_exists_ip(self::$flowXMLBasePath . '/' . $targetPath . $version . '/' . $classXMLName . '.flow.xml')) {
                         $flowXMLPath = self::$flowXMLBasePath . '/' . $targetPath . $version . '/' . $classXMLName . '.flow.xml';
                     }
                 }
                 if ('' === $flowXMLPath) {
                     // バージョン関係ナシのファイルを走査する
                     if (file_exists_ip(self::$flowXMLBasePath . '/' . $targetPath . $classXMLName . '.flow.xml')) {
                         $flowXMLPath = self::$flowXMLBasePath . '/' . $targetPath . $classXMLName . '.flow.xml';
                     }
                 }
                 debug($flowXMLPath);
                 if ('' === $flowXMLPath) {
                     // エラー終了
                     return FALSE;
                 }
                 // flowファイルの履歴を残しておく
                 self::$flowXMLPaths[] = array('class' => $controlerClassName, 'xml' => $flowXMLPath);
                 // Flowに応じたクラス定義の自動生成を委任
                 loadModule('Flow');
                 if (FALSE === Flow::generate($flowXMLPath, $controlerClassName, $targetPath)) {
                     // エラー終了
                     return FALSE;
                 }
                 if (!class_exists($controlerClassName, FALSE)) {
                     // エラー終了
                     return FALSE;
                 }
             }
         }
     }
     return $controlerClassName;
 }