BcUtil::getSchemaPath PHP Method

getSchemaPath() public static method

スキーマ情報のパスを取得する
public static getSchemaPath ( string $plugin = null ) : string
$plugin string プラグイン名
return string Or false
    public static function getSchemaPath($plugin = null)
    {
        if (!$plugin) {
            $plugin = 'Core';
        } else {
            $plugin = Inflector::camelize($plugin);
        }
        if ($plugin == 'Core') {
            return BASER_CONFIGS . 'Schema';
        }
        $paths = App::path('Plugin');
        foreach ($paths as $path) {
            $_path = $path . $plugin . DS . 'Config' . DS . 'Schema';
            if (is_dir($_path)) {
                return $_path;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 /**
  * CSVファイルを書きだす
  *
  * @param string $configKeyName
  * @param string $path
  * @return boolean
  * @access protected
  */
 function _writeCsv($configKeyName, $plugin, $path, $exclude = array())
 {
     $pluginTables = array();
     if ($plugin != 'core') {
         $pluginPath = BcUtil::getSchemaPath($plugin);
         $Folder = new Folder($pluginPath);
         $files = $Folder->read(true, true, false);
         $pluginTables = $files[1];
         foreach ($pluginTables as $key => $pluginTable) {
             if (preg_match('/^(.+)\\.php$/', $pluginTable, $matches)) {
                 $pluginTables[$key] = $matches[1];
             } else {
                 unset($pluginTables[$key]);
             }
         }
     }
     $pluginKey = Inflector::underscore($plugin);
     $db = ConnectionManager::getDataSource($configKeyName);
     $db->cacheSources = false;
     $tables = $db->listSources();
     $result = true;
     foreach ($tables as $table) {
         if (preg_match("/^" . $db->config['prefix'] . "([^_].+)\$/", $table, $matches) && !preg_match("/^" . Configure::read('BcEnv.pluginDbPrefix') . "[^_].+\$/", $matches[1])) {
             $table = $matches[1];
             if (in_array($table, $exclude)) {
                 continue;
             }
             if ($pluginKey != 'core') {
                 // プラグインの場合は対象プラグイン名が先頭にない場合スキップ
                 //if (!preg_match("/^" . $pluginKey . "_([^_].+)$/", $table)) {
                 if (!in_array($table, $pluginTables)) {
                     // メールプラグインの場合、先頭に、「mail_」 がなくとも 末尾にmessagesがあれば対象とする
                     if ($pluginKey != 'mail') {
                         continue;
                     } elseif (!preg_match("/messages\$/", $table)) {
                         continue;
                     }
                 }
             }
             if (!$db->writeCsv(array('path' => $path . $table . '.csv', 'encoding' => 'SJIS', 'init' => false, 'plugin' => $plugin == 'core' ? null : $plugin))) {
                 $result = false;
             }
         }
     }
     return $result;
 }
All Usage Examples Of BcUtil::getSchemaPath