EventTypeModuleCode::findModelClassForTable PHP Method

findModelClassForTable() public static method

public static findModelClassForTable ( $table, $path = false )
    public static function findModelClassForTable($table, $path = false)
    {
        if (!$path) {
            $path = Yii::app()->basePath . '/models';
        }
        $dh = opendir($path);
        while ($file = readdir($dh)) {
            if (!preg_match('/^\\.\\.?$/', $file)) {
                if (is_dir($path . '/' . $file)) {
                    if ($class = self::findModelClassForTable($table, $path . '/' . $file)) {
                        return $class;
                    }
                } else {
                    if (preg_match('/\\.php$/', $file)) {
                        $blob = file_get_contents($path . '/' . $file);
                        if (preg_match('/public function tableName\\(\\).*?\\{.*?return \'(.*?)\';/s', $blob, $m)) {
                            if ($m[1] == $table) {
                                return preg_replace('/\\.php$/', '', $file);
                            }
                        }
                    }
                }
            }
        }
        closedir($dh);
        if ($path == Yii::app()->basePath . '/models') {
            $path = Yii::app()->basePath . '/modules';
            $dh = opendir($path);
            while ($file = readdir($dh)) {
                if (!preg_match('/^\\.\\.?$/', $file)) {
                    if (file_exists($path . '/' . $file . '/models')) {
                        if ($class = self::findModelClassForTable($table, $path . '/' . $file . '/models')) {
                            return $class;
                        }
                    }
                }
            }
            closedir($dh);
        }
        return false;
    }

Usage Example

コード例 #1
0
 public static function findModelClassForTable($table, $path = false)
 {
     if (!$path) {
         $path = Yii::app()->basePath . '/models';
     }
     $dh = opendir($path);
     while ($file = readdir($dh)) {
         if (!preg_match('/^\\.\\.?$/', $file)) {
             if (is_dir($path . '/' . $file)) {
                 if ($class = EventTypeModuleCode::findModelClassForTable($table, $path . '/' . $file)) {
                     return $class;
                 }
             } else {
                 if (preg_match('/\\.php$/', $file)) {
                     $blob = file_get_contents($path . '/' . $file);
                     if (preg_match('/public function tableName\\(\\).*?\\{.*?return \'(.*?)\';/s', $blob, $m)) {
                         if ($m[1] == $table) {
                             return preg_replace('/\\.php$/', '', $file);
                         }
                     }
                 }
             }
         }
     }
     closedir($dh);
     if ($path == Yii::app()->basePath . '/models') {
         $path = Yii::app()->basePath . '/modules';
         $dh = opendir($path);
         while ($file = readdir($dh)) {
             if (!preg_match('/^\\.\\.?$/', $file)) {
                 if (file_exists($path . '/' . $file . '/models')) {
                     if ($class = EventTypeModuleCode::findModelClassForTable($table, $path . '/' . $file . '/models')) {
                         return $class;
                     }
                 }
             }
         }
         closedir($dh);
     }
     return false;
 }
All Usage Examples Of EventTypeModuleCode::findModelClassForTable