Tool::_writeSchema PHP Method

_writeSchema() protected method

スキーマを書き出す
protected _writeSchema ( string $field, array $values, string $path ) : boolean
$field string
$values array
$path string スキーマファイルの生成場所
return boolean
    protected function _writeSchema($field, $values, $path)
    {
        $db = ConnectionManager::getDataSource('default');
        $prefix = $db->config['prefix'];
        $tableList = $this->getControlSource($field);
        $modelList = array();
        foreach ($tableList as $key => $table) {
            $model = Inflector::camelize(Inflector::singularize(str_replace($prefix, '', $table)));
            $modelList[$key] = $model;
        }
        $result = true;
        foreach ($values as $value) {
            if (!$db->writeSchema(array('model' => $modelList[$value], 'path' => $path))) {
                $result = false;
            } else {
                // pathプロパティを削除
                $filename = $path . Inflector::tableize($modelList[$value]) . '.php';
                $File = new File($filename);
                $content = file_get_contents($filename);
                $reg = '/(\\r\\n\\r\\n|\\n\\n)[^\\n]+?\\$path[^\\n]+?;/is';
                $content = preg_replace($reg, '', $content);
                $File->write($content, 'w+');
                $File->close();
            }
        }
        return $result;
    }