PdbParser
in package
implements
PdbSchemaInterface
Provides a system for syncing a database to a database definition.
The database definition is stored in one or more XML files, which get merged together before the sync is done. Contains code that may be MySQL specific.
Table of Contents
Interfaces
- PdbSchemaInterface
- An object that represents the structure of a database.
Constants
- FOREIGN_KEY_ACTIONS : mixed = ['restrict' => 'RESTRICT', 'set-null' => 'SET N...
- MySQL names for the foreign key actions.
Properties
- $tables : array<string|int, PdbTable>
- $views : array<string|int, string>
- $errors : array<string, array<string|int, string>>
Methods
- getErrors() : array<string|int, array<string|int, string>>
- Get a list of errors.
- getErrorsLog() : PdbLog
- Get a formatted error log.
- getSchema() : PdbSchema
- Get the parsed schema struct.
- getTable() : null|PdbTable
- Get a table by it's (non-prefixed) name.
- getTableNames() : array<string|int, string>
- List non-prefixed table names.
- getTables() : array<string|int, PdbTable>
- Get a list of parsed tables.
- getView() : null|string
- Get a view by it's (non-prefixed) name.
- getViews() : array<string|int, PdbView>
- Get a list of parsed views.
- hasErrors() : bool
- Were there any load or sanity check errors?
- loadXml() : void
- Loads the XML definition file
- parseColumnType() : string
- Parse the column type definition.
- parseConstraintAction() : string
- parseSchema() : PdbSchema
- Load an XML file
- parseStringArray() : array<string|int, string>
- Extract a list of strings from a string.
- parseValues() : array<string|int, string>
- Get a list of strings from the target child element.
- sanityCheck() : bool
- Run a sanity check over all loaded tables
- parseTable() : PdbTable
- parseView() : string
Constants
FOREIGN_KEY_ACTIONS
MySQL names for the foreign key actions.
public
mixed
FOREIGN_KEY_ACTIONS
= ['restrict' => 'RESTRICT', 'set-null' => 'SET NULL', 'cascade' => 'CASCADE']
Properties
$tables
public
array<string|int, PdbTable>
$tables
= []
name => PdbTable
$views
public
array<string|int, string>
$views
= []
name => string
$errors
private
array<string, array<string|int, string>>
$errors
= []
name => string[]
Methods
getErrors()
Get a list of errors.
public
getErrors() : array<string|int, array<string|int, string>>
Return values
array<string|int, array<string|int, string>> —table => errors[]
getErrorsLog()
Get a formatted error log.
public
getErrorsLog() : PdbLog
Return values
PdbLoggetSchema()
Get the parsed schema struct.
public
getSchema() : PdbSchema
Return values
PdbSchemagetTable()
Get a table by it's (non-prefixed) name.
public
getTable(string $name) : null|PdbTable
Parameters
- $name : string
Return values
null|PdbTablegetTableNames()
List non-prefixed table names.
public
getTableNames() : array<string|int, string>
Tags
Return values
array<string|int, string>getTables()
Get a list of parsed tables.
public
getTables() : array<string|int, PdbTable>
Return values
array<string|int, PdbTable> —[ name => table ]
getView()
Get a view by it's (non-prefixed) name.
public
getView(string $name) : null|string
Parameters
- $name : string
Return values
null|stringgetViews()
Get a list of parsed views.
public
getViews() : array<string|int, PdbView>
Return values
array<string|int, PdbView> —[ name => table ]
hasErrors()
Were there any load or sanity check errors?
public
hasErrors() : bool
Return values
boolloadXml()
Loads the XML definition file
public
loadXml(string|DOMDocument $dom) : void
Parameters
- $dom : string|DOMDocument
-
DOMDocument or filename to load.
Tags
parseColumnType()
Parse the column type definition.
public
static parseColumnType(DOMElement $node) : string
In particular this will parse XML-style enum/set types.
Note: This does not normalise the types. You must use the PdbHelper::normalizeType() method before comparing types.
Parameters
- $node : DOMElement
Return values
stringparseConstraintAction()
public
static parseConstraintAction(string $action) : string
Parameters
- $action : string
Return values
stringparseSchema()
Load an XML file
public
parseSchema(string|DOMDocument $dom) : PdbSchema
Parameters
- $dom : string|DOMDocument
-
DOMDocument or filename to load.
Tags
Return values
PdbSchemaparseStringArray()
Extract a list of strings from a string.
public
static parseStringArray(string $value) : array<string|int, string>
The results are all lowercase + trimmed.
Parameters
- $value : string
Return values
array<string|int, string>parseValues()
Get a list of strings from the target child element.
public
static parseValues(DOMElement $node, string $tag) : array<string|int, string>
TODO Update to use kbphp (v2.16) XML.
Parameters
- $node : DOMElement
- $tag : string
Return values
array<string|int, string>sanityCheck()
Run a sanity check over all loaded tables
public
sanityCheck([array<string|int, PdbTable> $extra_tables = [] ]) : bool
Parameters
- $extra_tables : array<string|int, PdbTable> = []
Return values
boolparseTable()
private
parseTable(DOMElement $table_node) : PdbTable
Parameters
- $table_node : DOMElement
Tags
Return values
PdbTableparseView()
private
parseView(DOMElement $view_node) : string
Parameters
- $view_node : DOMElement