BcDatabaseService
in package
implements
BcDatabaseServiceInterface
Uses
LogTrait, BcContainerTrait, ConfigurationTrait
Interfaces, Classes, Traits and Enums
- BcDatabaseServiceInterface
- BcDatabaseServiceInterface
Table of Contents
- $_encodingMaps : array<string|int, mixed>
- PHP←→DBエンコーディングマップ
- __construct() : mixed
- Constructor
- addColumn() : bool
- テーブルにカラムを追加する
- checkDbConnection() : mixed
- DB接続チェック
- clearAppTableList() : void
- アプリケーションに関連するテーブルリストのキャッシュをクリアする
- columnExists() : bool
- テーブルにカラムが存在するか確認する
- connectDb() : Connection
- データベースに接続する
- constructionTable() : bool
- テーブルを構築する
- createTable() : bool
- テーブルを作成する
- deleteTables() : bool
- テーブルを削除する
- dropTable() : bool
- テーブルを削除する
- getAppTableList() : array<string|int, mixed>
- アプリケーションに関連するテーブルリストを取得する
- getDataSource() : Connection
- データソースを取得する
- getDatasourceName() : string
- datasource名を取得
- getEncoding() : string
- Gets the database encoding
- getMigrationsTable() : Table
- マイグレーション用のテーブルオブジェクトを取得する。
- getSequence() : mixed
- シーケンスを取得する
- getService() : array<string|int, mixed>|mixed|object
- Get Service
- hasService() : bool
- Has Service
- initMessageTables() : bool
- メールメッセージテーブルを初期化する
- initSystemData() : bool
- システムデータを初期化する
- loadCsv() : bool
- CSVファイルをDBに読み込む
- loadCsvToArray() : false|array<string|int, mixed>
- CSVよりデータを配列として読み込む
- loadDefaultDataPattern() : bool
- 初期データを読み込む
- loadSchema() : bool
- スキーマを読み込む
- migrate() : bool
- データベースのマイグレーションを実行する
- removeColumn() : bool
- テーブルよりカラムを削除する
- renameColumn() : bool
- テーブルのカラム名を変更する
- renameTable() : bool
- テーブルをリネームする
- resetAllTables() : bool
- プラグインも含めて全てのテーブルをリセットする
- resetTables() : bool
- 複数のテーブルをリセットする
- tableExists() : bool
- テーブルの存在チェックを行う
- testConnectDb() : mixed
- データベース接続テスト
- truncate() : bool
- テーブルのデータをリセットする
- updateSequence() : mixed
- データベースシーケンスをアップデートする
- writeCsv() : bool
- DBのデータをCSVファイルとして書きだす
- writeSchema() : string|false
- モデル名を指定してスキーマファイルを生成する
- _convertFieldToCsv() : string
- CSV用のフィールドデータに変換する
- _convertRecordToCsv() : array<string|int, mixed>
- CSV用のレコードデータに変換する
- _dbEncToPhp() : string
- DB用エンコーディング名称をPHP用エンコーディング名称に変換する
- _generateSchema() : string
- テキストのスキーマ情報を生成する Bake\Command\FixtureCommand::_generateSchema() を移植
- _loadDefaultDataPattern() : bool
- 初期データを読み込む
- _phpEncToDb() : string
- PHP用エンコーディング名称をDB用のエンコーディング名称に変換する
- _values() : array<string|int, string>
- Formats Schema columns from Model Object Bake\Command\FixtureCommand::_values() を移植
- initAdapter() : mixed
- アダプターを初期化する
Properties
$_encodingMaps
PHP←→DBエンコーディングマップ
protected
array<string|int, mixed>
$_encodingMaps
= ['utf8' => 'UTF-8', 'sjis' => 'SJIS', 'ujis' => 'EUC-JP']
Methods
__construct()
Constructor
public
__construct() : mixed
Return values
mixed —addColumn()
テーブルにカラムを追加する
public
addColumn(string $tableName, string $columnName, string $type[, array<string|int, mixed> $options = [] ]) : bool
Parameters
- $tableName : string
- $columnName : string
- $type : string
- $options : array<string|int, mixed> = []
Tags
Return values
bool —checkDbConnection()
DB接続チェック
public
checkDbConnection(array<string|int, string> $config) : mixed
Parameters
- $config : array<string|int, string>
-
-
datasource
: 'MySQL' or 'Postgres' or 'SQLite' or 'CSV' -
database
: データベース名 SQLiteの場合はファイルパス CSVの場合はディレクトリへのパス -
host
: テキストDB or localhostの場合は不要 -
port
: 接続ポート テキストDBの場合は不要 -
login
: 接続ユーザ名 テキストDBの場合は不要 -
password
: 接続パスワード テキストDBの場合は不要
-
Tags
Return values
mixed —clearAppTableList()
アプリケーションに関連するテーブルリストのキャッシュをクリアする
public
clearAppTableList() : void
Tags
Return values
void —columnExists()
テーブルにカラムが存在するか確認する
public
columnExists(string $tableName, string $columnName) : bool
Parameters
- $tableName : string
- $columnName : string
Return values
bool —connectDb()
データベースに接続する
public
connectDb(array<string|int, mixed> $config[, mixed $name = 'default' ]) : Connection
Parameters
- $config : array<string|int, mixed>
- $name : mixed = 'default'
Tags
Return values
Connection —constructionTable()
テーブルを構築する
public
constructionTable(string $plugin[, string $dbConfigKeyName = 'default' ][, array<string|int, mixed> $dbConfig = [] ]) : bool
Parameters
- $plugin : string
- $dbConfigKeyName : string = 'default'
- $dbConfig : array<string|int, mixed> = []
Return values
bool —createTable()
テーブルを作成する
public
createTable(string $tableName[, array<string|int, mixed> $columns = [] ]) : bool
Parameters
- $tableName : string
- $columns : array<string|int, mixed> = []
Tags
Return values
bool —deleteTables()
テーブルを削除する
public
deleteTables([string $dbConfigKeyName = 'default' ][, array<string|int, mixed> $dbConfig = null ]) : bool
Parameters
- $dbConfigKeyName : string = 'default'
- $dbConfig : array<string|int, mixed> = null
Tags
Return values
bool —dropTable()
テーブルを削除する
public
dropTable(string $tableName) : bool
Parameters
- $tableName : string
Tags
Return values
bool —getAppTableList()
アプリケーションに関連するテーブルリストを取得する
public
getAppTableList([mixed $plugin = '' ]) : array<string|int, mixed>
Parameters
- $plugin : mixed = ''
Tags
Return values
array<string|int, mixed> —getDataSource()
データソースを取得する
public
getDataSource([mixed $dbConfigKeyName = 'default' ][, array<string|int, mixed> $dbConfig = null ]) : Connection
Parameters
- $dbConfigKeyName : mixed = 'default'
- $dbConfig : array<string|int, mixed> = null
Tags
Return values
Connection —getDatasourceName()
datasource名を取得
public
getDatasourceName([string $datasource = null ]) : string
Parameters
- $datasource : string = null
-
datasource name.postgre.mysql.etc.
Tags
Return values
string —getEncoding()
Gets the database encoding
public
getEncoding() : string
Tags
Return values
string —The database encoding
getMigrationsTable()
マイグレーション用のテーブルオブジェクトを取得する。
public
getMigrationsTable(string $tableName) : Table
Parameters
- $tableName : string
Tags
Return values
Table —getSequence()
シーケンスを取得する
public
getSequence(mixed $table[, mixed $field = 'id' ]) : mixed
Parameters
- $table : mixed
- $field : mixed = 'id'
Return values
mixed —getService()
Get Service
public
getService( $service) : array<string|int, mixed>|mixed|object
Parameters
Tags
Return values
array<string|int, mixed>|mixed|object —hasService()
Has Service
public
hasService( $service) : bool
Parameters
Tags
Return values
bool —initMessageTables()
メールメッセージテーブルを初期化する
public
initMessageTables() : bool
Tags
Return values
bool —initSystemData()
システムデータを初期化する
public
initSystemData([mixed $options = [] ]) : bool
Parameters
- $options : mixed = []
Tags
Return values
bool —loadCsv()
CSVファイルをDBに読み込む
public
loadCsv(array<string|int, mixed> $options) : bool
Parameters
- $options : array<string|int, mixed>
-
-
path
: 読み込み元のCSVのパス - `encoding: CSVファイルのエンコード
-
Tags
Return values
bool —loadCsvToArray()
CSVよりデータを配列として読み込む
public
loadCsvToArray(string $path[, mixed $encoding = 'auto' ]) : false|array<string|int, mixed>
Parameters
- $path : string
- $encoding : mixed = 'auto'
Tags
Return values
false|array<string|int, mixed> —loadDefaultDataPattern()
初期データを読み込む
public
loadDefaultDataPattern( $theme, $pattern) : bool
Parameters
Tags
Return values
bool —loadSchema()
スキーマを読み込む
public
loadSchema( $options) : bool
Parameters
Tags
Return values
bool —migrate()
データベースのマイグレーションを実行する
public
migrate(string $plugin[, string $connection = 'default' ]) : bool
Parameters
- $plugin : string
- $connection : string = 'default'
Return values
bool —removeColumn()
テーブルよりカラムを削除する
public
removeColumn(string $tableName, string $columnName) : bool
Parameters
- $tableName : string
- $columnName : string
Tags
Return values
bool —renameColumn()
テーブルのカラム名を変更する
public
renameColumn(string $tableName, string $columnName, string $newColumnName) : bool
Parameters
- $tableName : string
- $columnName : string
- $newColumnName : string
Return values
bool —renameTable()
テーブルをリネームする
public
renameTable(string $oldTableName, string $newTableName) : bool
Parameters
- $oldTableName : string
- $newTableName : string
Return values
bool —resetAllTables()
プラグインも含めて全てのテーブルをリセットする
public
resetAllTables([mixed $excludes = [] ]) : bool
プラグインは有効となっているもののみ 現在のテーマでないテーマの梱包プラグインを検出できない為
Parameters
- $excludes : mixed = []
Tags
Return values
bool —resetTables()
複数のテーブルをリセットする
public
resetTables([string $plugin = 'BaserCore' ][, array<string|int, mixed> $excludes = [] ]) : bool
Parameters
- $plugin : string = 'BaserCore'
- $excludes : array<string|int, mixed> = []
Tags
Return values
bool —tableExists()
テーブルの存在チェックを行う
public
tableExists(string $tableName) : bool
Parameters
- $tableName : string
Tags
Return values
bool —testConnectDb()
データベース接続テスト
public
testConnectDb(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
Return values
mixed —truncate()
テーブルのデータをリセットする
public
truncate( $table) : bool
Parameters
Tags
Return values
bool —updateSequence()
データベースシーケンスをアップデートする
public
updateSequence() : mixed
Return values
mixed —writeCsv()
DBのデータをCSVファイルとして書きだす
public
writeCsv(mixed $table, array<string|int, mixed> $options) : bool
Parameters
- $table : mixed
- $options : array<string|int, mixed>
-
-
path
: CSVの出力先となるパス -encoding
: 出力エンコーディング -table
: テーブル名 -init
: id、created、modified を初期化する(初期値:false)
Tags
Return values
bool —writeSchema()
モデル名を指定してスキーマファイルを生成する
public
writeSchema(mixed $table, array<string|int, mixed> $options) : string|false
Parameters
- $table : mixed
- $options : array<string|int, mixed>
-
-
path
: スキーマファイルの生成場所
-
Tags
Return values
string|false —スキーマファイルの内容
_convertFieldToCsv()
CSV用のフィールドデータに変換する
protected
_convertFieldToCsv(string $value[, bool $dc = true ]) : string
Parameters
- $value : string
- $dc : bool = true
-
( " を "" に変換するか)
Tags
Return values
string —_convertRecordToCsv()
CSV用のレコードデータに変換する
protected
_convertRecordToCsv(array<string|int, mixed> $record) : array<string|int, mixed>
Parameters
- $record : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —_dbEncToPhp()
DB用エンコーディング名称をPHP用エンコーディング名称に変換する
protected
_dbEncToPhp(string $enc) : string
Parameters
- $enc : string
Tags
Return values
string —_generateSchema()
テキストのスキーマ情報を生成する Bake\Command\FixtureCommand::_generateSchema() を移植
protected
_generateSchema(TableSchemaInterface $table) : string
Parameters
- $table : TableSchemaInterface
Tags
Return values
string —_loadDefaultDataPattern()
初期データを読み込む
protected
_loadDefaultDataPattern(string $pattern, string $theme[, string $plugin = 'BaserCore' ][, array<string|int, mixed> $excludes = [] ]) : bool
Parameters
- $pattern : string
- $theme : string
- $plugin : string = 'BaserCore'
- $excludes : array<string|int, mixed> = []
Tags
Return values
bool —_phpEncToDb()
PHP用エンコーディング名称をDB用のエンコーディング名称に変換する
protected
_phpEncToDb(string $enc) : string
Parameters
- $enc : string
Tags
Return values
string —_values()
Formats Schema columns from Model Object Bake\Command\FixtureCommand::_values() を移植
protected
_values(array<string|int, mixed> $values) : array<string|int, string>
Parameters
- $values : array<string|int, mixed>
-
options keys(type, null, default, key, length, extra)
Tags
Return values
array<string|int, string> —Formatted values
initAdapter()
アダプターを初期化する
protected
initAdapter() : mixed
アダプターはテーブルのマイグレーションに利用する