TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Parser Class Reference

Public Member Functions

 __construct (string $statement)
 
 getLexer ()
 
 getAST ()
 
 match ($token)
 
 free ($deep=false, $position=0)
 
 parse ()
 
 syntaxError ($expected= '', $token=null)
 
 semanticalError ($message= '', $token=null)
 
 queryLanguage ()
 
 createStatement ()
 
 indexName ()
 
 indexType ()
 
 indexOptions ()
 

Protected Member Functions

 peekBeyondClosingParenthesis ($resetPeek=true)
 
 createTableStatement ()
 
 createTableClause ()
 
 createDefinition ()
 
 createDefinitionItem ()
 
 createIndexDefinitionItem ()
 
 createForeignKeyDefinitionItem ()
 
 createColumnDefinitionItem ()
 
 columnDataType ()
 
 columnDefaultValue ()
 
 dataTypeLength (bool $required=false)
 
 numericDataTypeOptions ()
 
 fractionalSecondsPart ()
 
 characterDataTypeOptions ()
 
 enumerationDataTypeOptions ()
 
 valueList ()
 
 valueListItem ()
 
 referenceDefinition ()
 
 indexColumnName ()
 
 referenceOption ()
 
 tableOptions ()
 
 tableOptionValue ()
 
 schemaObjectName ()
 

Protected Attributes

 $lexer
 
 $statement
 

Private Member Functions

 dataTypeDecimals ()
 

Detailed Description

An LL(*) recursive-descent parser for MySQL CREATE TABLE statements. Parses a CREATE TABLE statement, reports any errors in it, and generates an AST.

Definition at line 27 of file Classes/Database/Schema/Parser/Parser.php.

Constructor & Destructor Documentation

__construct ( string  $statement)

Creates a new statement parser object.

Parameters
string$statementThe statement to parse.

Definition at line 48 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\$statement.

Member Function Documentation

characterDataTypeOptions ( )
protected

Parse common options for numeric datatypes

Returns
array
Exceptions
TYPO3

Definition at line 1135 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_BINARY, Lexer\T_CHARACTER, Lexer\T_COLLATE, Lexer\T_SET, and Lexer\T_STRING.

Referenced by Parser\columnDataType().

columnDataType ( )
protected

DataType ::= BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFILL] | SMALLINT[(length)] [UNSIGNED] [ZEROFILL] | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] | INT[(length)] [UNSIGNED] [ZEROFILL] | INTEGER[(length)] [UNSIGNED] [ZEROFILL] | BIGINT[(length)] [UNSIGNED] [ZEROFILL] | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL] | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL] | DATE | TIME[(fsp)] | TIMESTAMP[(fsp)] | DATETIME[(fsp)] | YEAR | CHAR[(length)] [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | VARCHAR(length) [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | BINARY[(length)] | VARBINARY(length) | TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB | TINYTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | TEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | MEDIUMTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | LONGTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | ENUM(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | SET(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | JSON

Returns
Exceptions
TYPO3

Definition at line 800 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\characterDataTypeOptions(), Parser\dataTypeDecimals(), Parser\dataTypeLength(), Parser\enumerationDataTypeOptions(), Parser\fractionalSecondsPart(), Parser\match(), Parser\numericDataTypeOptions(), Parser\syntaxError(), Lexer\T_BIGINT, Lexer\T_BINARY, Lexer\T_BIT, Lexer\T_BLOB, Lexer\T_CHAR, Lexer\T_DATE, Lexer\T_DATETIME, Lexer\T_DECIMAL, Lexer\T_DOUBLE, Lexer\T_ENUM, Lexer\T_FLOAT, Lexer\T_INT, Lexer\T_INTEGER, Lexer\T_JSON, Lexer\T_LONGBLOB, Lexer\T_LONGTEXT, Lexer\T_MEDIUMBLOB, Lexer\T_MEDIUMINT, Lexer\T_MEDIUMTEXT, Lexer\T_NUMERIC, Lexer\T_PRECISION, Lexer\T_REAL, Lexer\T_SET, Lexer\T_SMALLINT, Lexer\T_TEXT, Lexer\T_TIME, Lexer\T_TIMESTAMP, Lexer\T_TINYBLOB, Lexer\T_TINYINT, Lexer\T_TINYTEXT, Lexer\T_VARBINARY, Lexer\T_VARCHAR, Lexer\T_YEAR, and Parser\valueList().

Referenced by Parser\createColumnDefinitionItem().

columnDefaultValue ( )
protected

DefaultValue::= DEFAULT default_value

Returns
mixed
Exceptions
TYPO3

Definition at line 995 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Lexer\T_CURRENT_TIMESTAMP, Lexer\T_DEFAULT, Lexer\T_FLOAT, Lexer\T_INTEGER, Lexer\T_NULL, and Lexer\T_STRING.

Referenced by Parser\createColumnDefinitionItem().

createColumnDefinitionItem ( )
protected

CreateColumnDefinitionItem ::= col_name column_definition

column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'string'] [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}] [STORAGE {DISK|MEMORY|DEFAULT}] [reference_definition]

Returns
Exceptions
TYPO3

Definition at line 674 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\columnDataType(), Parser\columnDefaultValue(), Parser\match(), Parser\referenceDefinition(), Parser\schemaObjectName(), Parser\syntaxError(), Lexer\T_AUTO_INCREMENT, Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COLUMN_FORMAT, Lexer\T_COMMA, Lexer\T_COMMENT, Lexer\T_DEFAULT, Lexer\T_DISK, Lexer\T_DYNAMIC, Lexer\T_FIXED, Lexer\T_KEY, Lexer\T_MEMORY, Lexer\T_NOT, Lexer\T_NULL, Lexer\T_PRIMARY, Lexer\T_REFERENCES, Lexer\T_STORAGE, Lexer\T_STRING, and Lexer\T_UNIQUE.

Referenced by Parser\createDefinitionItem().

createDefinition ( )
protected

Parses the table field/index definition

createDefinition ::= ( col_name column_definition | [CONSTRAINT [symbol]] PRIMARY KEY index_type [index_option] ... | {INDEX|KEY} [index_name] index_type [index_option] ... | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] [index_name] index_type [index_option] ... | {FULLTEXT|SPATIAL} [INDEX|KEY] index_name [index_option] ... | [CONSTRAINT [symbol]] FOREIGN KEY index_name reference_definition | CHECK (expr) )

Returns
Exceptions
TYPO3

Definition at line 373 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\createDefinitionItem(), Parser\match(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, and Lexer\T_OPEN_PARENTHESIS.

Referenced by CreateTableStatement\__construct(), and Parser\createTableStatement().

createForeignKeyDefinitionItem ( )
protected

Parses an foreign key definition item contained in the create definition

Returns
Exceptions
TYPO3

Definition at line 540 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\indexColumnName(), Parser\indexName(), Parser\match(), Parser\referenceDefinition(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, Lexer\T_FOREIGN, Lexer\T_KEY, and Lexer\T_OPEN_PARENTHESIS.

Referenced by Parser\createDefinitionItem().

createStatement ( )

CreateStatement ::= CREATE [TEMPORARY] TABLE Abstraction to allow for support of other schema objects like views in the future.

Returns
Exceptions
TYPO3

Definition at line 291 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\$statement, Parser\createTableStatement(), Parser\match(), Parser\syntaxError(), Lexer\T_CREATE, Lexer\T_SEMICOLON, Lexer\T_TABLE, and Lexer\T_TEMPORARY.

Referenced by Parser\queryLanguage().

createTableClause ( )
protected

CreateTableClause ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name

Returns
Exceptions
TYPO3

Definition at line 333 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\schemaObjectName(), Lexer\T_EXISTS, Lexer\T_IF, Lexer\T_NOT, Lexer\T_TABLE, and Lexer\T_TEMPORARY.

Referenced by Parser\createTableStatement().

createTableStatement ( )
protected

CreateTableStatement ::= CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [tbl_options]

Exceptions
TYPO3

Definition at line 317 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\createDefinition(), Parser\createTableClause(), Lexer\T_SEMICOLON, and Parser\tableOptions().

Referenced by Parser\createStatement().

dataTypeDecimals ( )
private

Determine length and optional decimal parameter of a column field definition, i.E. DECIMAL(10,6)

Returns
array
Exceptions
TYPO3

Definition at line 1056 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, Lexer\T_INTEGER, and Lexer\T_OPEN_PARENTHESIS.

Referenced by Parser\columnDataType().

dataTypeLength ( bool  $required = false)
protected

Determine length parameter of a column field definition, i.E. INT(11) or VARCHAR(255)

Parameters
bool$required
Returns
int
Exceptions
TYPO3

Definition at line 1032 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\semanticalError(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_INTEGER, and Lexer\T_OPEN_PARENTHESIS.

Referenced by Parser\columnDataType(), Parser\fractionalSecondsPart(), and Parser\indexColumnName().

enumerationDataTypeOptions ( )
protected

Parse shared options for enumeration datatypes (ENUM and SET)

Returns
array
Exceptions
TYPO3

Definition at line 1174 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_CHARACTER, Lexer\T_COLLATE, Lexer\T_SET, and Lexer\T_STRING.

Referenced by Parser\columnDataType().

fractionalSecondsPart ( )
protected

Determine the fractional seconds part support for TIME, DATETIME and TIMESTAMP columns

Returns
int
Exceptions
TYPO3

Definition at line 1116 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\dataTypeLength(), and Parser\semanticalError().

Referenced by Parser\columnDataType().

free (   $deep = false,
  $position = 0 
)

Frees this parser, enabling it to be reused.

Parameters
bool$deepWhether to clean peek and reset errors.
int$positionPosition to reset.
Returns
void

Definition at line 129 of file Classes/Database/Schema/Parser/Parser.php.

getAST ( )

Parses and builds AST for the given Query.

Returns
Exceptions
TYPO3

Definition at line 70 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\queryLanguage().

Referenced by Parser\parse().

getLexer ( )

Gets the lexer used by the parser.

Returns
Lexer

Definition at line 59 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\$lexer.

indexColumnName ( )
protected
indexName ( )

Return the name of an index. No name has been supplied if the next token is USING which defines the index type.

Returns
AST
Exceptions
TYPO3

Definition at line 575 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\schemaObjectName(), Lexer\T_OPEN_PARENTHESIS, and Lexer\T_USING.

Referenced by CreateForeignKeyDefinitionItem\__construct(), CreateIndexDefinitionItem\__construct(), Parser\createForeignKeyDefinitionItem(), and Parser\createIndexDefinitionItem().

indexOptions ( )

IndexOptions ::= KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string'

Returns
array
Exceptions
TYPO3

Definition at line 625 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\schemaObjectName(), Parser\syntaxError(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, Lexer\T_COMMENT, Lexer\T_EQUALS, Lexer\T_KEY_BLOCK_SIZE, Lexer\T_PARSER, Lexer\T_STRING, Lexer\T_USING, and Lexer\T_WITH.

Referenced by Parser\createIndexDefinitionItem().

indexType ( )

IndexType ::= USING { BTREE | HASH }

Returns
string
Exceptions
TYPO3

Definition at line 591 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_BTREE, Lexer\T_HASH, and Lexer\T_USING.

Referenced by Parser\createIndexDefinitionItem().

numericDataTypeOptions ( )
protected

Parse common options for numeric datatypes

Returns
array
Exceptions
TYPO3

Definition at line 1084 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_UNSIGNED, and Lexer\T_ZEROFILL.

Referenced by Parser\columnDataType().

parse ( )

Parses a statement string.

Returns
Table[]
Exceptions
Doctrine
RuntimeException
InvalidArgumentException
TYPO3

Definition at line 152 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\getAST().

peekBeyondClosingParenthesis (   $resetPeek = true)
protected

Peeks beyond the matched closing parenthesis and returns the first token after that one.

Parameters
bool$resetPeekReset peek after finding the closing parenthesis.
Returns
array

Definition at line 233 of file Classes/Database/Schema/Parser/Parser.php.

References Lexer\T_CLOSE_PARENTHESIS, and Lexer\T_OPEN_PARENTHESIS.

queryLanguage ( )

queryLanguage ::= CreateTableStatement

Returns
Exceptions
TYPO3

Definition at line 266 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\$statement, Parser\createStatement(), Parser\syntaxError(), and Lexer\T_CREATE.

Referenced by Parser\getAST().

referenceDefinition ( )
protected

ReferenceDefinition ::= REFERENCES tbl_name (index_col_name,...) [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [ON DELETE reference_option] [ON UPDATE reference_option]

Returns
Exceptions
TYPO3

Definition at line 1248 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\indexColumnName(), Parser\match(), Parser\referenceOption(), Parser\schemaObjectName(), Parser\syntaxError(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, Lexer\T_DELETE, Lexer\T_MATCH, Lexer\T_ON, Lexer\T_OPEN_PARENTHESIS, Lexer\T_REFERENCES, and Lexer\T_UPDATE.

Referenced by Parser\createColumnDefinitionItem(), and Parser\createForeignKeyDefinitionItem().

referenceOption ( )
protected

ReferenceOption ::= RESTRICT | CASCADE | SET NULL | NO ACTION

Returns
string
Exceptions
TYPO3

Definition at line 1320 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_ACTION, Lexer\T_CASCADE, Lexer\T_NO, Lexer\T_NULL, Lexer\T_RESTRICT, and Lexer\T_SET.

Referenced by Parser\referenceDefinition().

schemaObjectName ( )
protected

Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers.

Returns
Exceptions
TYPO3

Definition at line 1557 of file Classes/Database/Schema/Parser/Parser.php.

Referenced by Identifier\__construct(), Parser\createColumnDefinitionItem(), Parser\createTableClause(), Identifier\getQuotedName(), Parser\indexColumnName(), Parser\indexName(), Parser\indexOptions(), and Parser\referenceDefinition().

semanticalError (   $message = '',
  $token = null 
)

Generates a new semantical error.

Parameters
string$messageOptional message.
array | null$tokenOptional token.
Returns
void
Exceptions
TYPO3

Definition at line 201 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\$statement, StatementException\semanticalError(), and StatementException\sqlError().

Referenced by Parser\createDefinitionItem(), Parser\dataTypeLength(), and Parser\fractionalSecondsPart().

tableOptions ( )
protected

Parse MySQL table options

ENGINE [=] engine_name | AUTO_INCREMENT [=] value | AVG_ROW_LENGTH [=] value | [DEFAULT] CHARACTER SET [=] charset_name | CHECKSUM [=] {0 | 1} | [DEFAULT] COLLATE [=] collation_name | COMMENT [=] 'string' | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'} | CONNECTION [=] 'connect_string' | DATA DIRECTORY [=] 'absolute path to directory' | DELAY_KEY_WRITE [=] {0 | 1} | ENCRYPTION [=] {'Y' | 'N'} | INDEX DIRECTORY [=] 'absolute path to directory' | INSERT_METHOD [=] { NO | FIRST | LAST } | KEY_BLOCK_SIZE [=] value | MAX_ROWS [=] value | MIN_ROWS [=] value | PACK_KEYS [=] {0 | 1 | DEFAULT} | PASSWORD [=] 'string' | ROW_FORMAT [=] {DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT} | STATS_AUTO_RECALC [=] {DEFAULT|0|1} | STATS_PERSISTENT [=] {DEFAULT|0|1} | STATS_SAMPLE_PAGES [=] value | TABLESPACE tablespace_name | UNION =

Returns
array
Exceptions
TYPO3

Definition at line 1382 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Parser\syntaxError(), Lexer\T_AUTO_INCREMENT, Lexer\T_AVG_ROW_LENGTH, Lexer\T_CHARACTER, Lexer\T_CHECKSUM, Lexer\T_COLLATE, Lexer\T_COMMENT, Lexer\T_COMPRESSION, Lexer\T_CONNECTION, Lexer\T_DATA, Lexer\T_DEFAULT, Lexer\T_DELAY_KEY_WRITE, Lexer\T_DIRECTORY, Lexer\T_ENCRYPTION, Lexer\T_ENGINE, Lexer\T_INDEX, Lexer\T_INSERT_METHOD, Lexer\T_KEY_BLOCK_SIZE, Lexer\T_MAX_ROWS, Lexer\T_MIN_ROWS, Lexer\T_PACK_KEYS, Lexer\T_PASSWORD, Lexer\T_ROW_FORMAT, Lexer\T_SEMICOLON, Lexer\T_SET, Lexer\T_STATS_AUTO_RECALC, Lexer\T_STATS_PERSISTENT, Lexer\T_STATS_SAMPLE_PAGES, Lexer\T_TABLESPACE, and Parser\tableOptionValue().

Referenced by Parser\createTableStatement().

tableOptionValue ( )
protected

Return the value of an option, skipping the optional equal sign.

Returns
mixed
Exceptions
TYPO3

Definition at line 1539 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), and Lexer\T_EQUALS.

Referenced by Parser\tableOptions().

valueList ( )
protected

Return all defined values for an enumeration datatype (ENUM, SET)

Returns
array
Exceptions
TYPO3

Definition at line 1209 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), Lexer\T_CLOSE_PARENTHESIS, Lexer\T_COMMA, Lexer\T_OPEN_PARENTHESIS, and Parser\valueListItem().

Referenced by Parser\columnDataType().

valueListItem ( )
protected

Return a value list item for an enumeration set

Returns
string
Exceptions
TYPO3

Definition at line 1232 of file Classes/Database/Schema/Parser/Parser.php.

References Parser\match(), and Lexer\T_STRING.

Referenced by Parser\valueList().

Member Data Documentation

$lexer
protected

Definition at line 34 of file Classes/Database/Schema/Parser/Parser.php.

Referenced by Parser\getLexer().