Squiz Matrix
4.12.2
|
Static Public Member Functions | |
static | getSystemSchemaDocument ($systemName) |
static | addSystemSchema ($systemName) |
static | addSystemQueries ($systemName) |
static | processQueriesFile ($systemName, $fileName) |
static | mergeQuery ($systemName, $queryName) |
static | generateQueryXML ($systemName, $queryName) |
static | queryXMLExists ($systemName, $queryName) |
static | getQueryXML ($systemName, $queryName) |
static | saveQueryXML ($system, $queryName, DomDocument $doc) |
static | addQuery ($systemName, DomElement $query) |
static | addQueryFragment ($systemName, DomElement $fragment) |
static | addSubQuery ($systemName, DomElement $subQuery) |
static | bakeQueriesFile ($systemName) |
static | bakeQueryMethod ($systemName, $queryName) |
static | printSubQueries ($systemName, $queryName) |
static | getHookCodeId ($hookId) |
static | getHookArrayId ($hookId) |
static | getSeperator ($tagName) |
static | parseSchema (DomElement $schema) |
static | validateQueries (DomElement $queries) |
static | queryIdIsUnique (DomDocument $doc, DomElement $query) |
static | validateQuery (DomElement $query) |
static | getQueryType (DomElement $query) |
static | fragmentExists ($system, $queryid, $hookid) |
static | convertToSql (DomElement $xmlQuery, array $sqlArray=array()) |
static | getConverter ($dbType=NULL) |
static | getTableColumnTypes ($systemid, $table, $column=NULL) |
static | getQuerySource ($systemid, $queryid) |
static | createSystemOvenPath ($system) |
static | loadQueriesXML ($systemid) |
static | getBakedQueryFileName ($systemid, $queryid) |
static | loadBakedQuery ($systemid, $queryid) |
static | loadSystemSchemaXML ($systemid) |
static | constructSql (DomElement $query) |
static | getHookPrefix () |
static | getComparisonOperators ($type=NULL) |
static | getDatabaseType ($dsn=NULL) |
Static Protected Member Functions | |
static | _dbDropTable ($tableName, DALConverter $converter=NULL) |
static | _dbTableExists ($tableName, DALConverter $converter=NULL) |
static | _printAlternateAssertions (DomElement $alternate, $contents) |
static | _recurseAddAssertion (array $assertions, array $currentStack=array()) |
static | _recursePrintAssertions (array $tree, DomElement $baseQuery, $baseQueryId, $level=0) |
static | _mergeAllAssertions (DomElement $baseQuery, array $assertions) |
static | _getQueryAssertions ($systemName, $queryName) |
static | _getAssertionVariableName (DomElement $assertion) |
static | _combineFragment (DomElement $query, DomElement $fragment) |
static | _prepareFragment (DomElement $query) |
static | _printAssertionCalls (array $assertions) |
static | _printAssertionInitialisation (DomElement $assertion) |
static | _printAssertionArgument (DomElement $argNode) |
static | _printNodeSql (DomElement $query, $baseId='', array $idParts=array()) |
static | _writeQueryObject ($id, array $sqlArray, $sql) |
static | _printPlaceHolderVariables ($systemName, $queryName) |
static | _generateHookArray ($systemName, $queryName) |
static | _printHookCode (array $hookIds) |
static | _printKeywords ($systemName, $queryName) |
static | _printBindings ($systemName, $queryName, $printBindings=TRUE) |
static | _extractBindings (DomElement $fragment) |
static | _extractKeywords (DomElement $fragment) |
static | _extractPlaceHolders (DomElement $fragment) |
static | _getPdoDataType ($systemId, $table, $column, $dataType=NULL) |
DALbaker.
Baker class for the Database Abstraction Layer, containing methods for converting XML queries into PHP code.
Definition at line 30 of file DALBaker.inc.
|
staticprotected |
Integrates a fragment into the base query.
Returns a DomElement representing the new, combined query. The combining is performed by determining what elements are present in the fragment. If they are not present in the query, the whole section is added. If however the element is present in the query, then the fragment's element's child nodes are traversed and added to the query's corresponding element.
For example, if the fragment has a WHERE element, and the query doesn't, the fragment's WHERE element is copied over. If the query does have a WHERE element, then the child nodes of the fragment's WHERE element are added as children of the query's WHERE element individually.
DomElement | $query | The base query. |
DomElement | $fragment | The fragment to integrate. This should be a representation of the fragment from the opening select tag onwards. |
Definition at line 1038 of file DALBaker.inc.
|
staticprotected |
Drops the given table.
Returns true if table was dropped.
string | $tableName | Name of the table to drop. |
DALConverter | $converter | DAL Converter object. |
Definition at line 209 of file DALBaker.inc.
|
staticprotected |
Returns true if the given table exists in the database.
string | $tableName | Name of the table to drop. |
DALConverter | $converter | DAL Converter object. |
Definition at line 235 of file DALBaker.inc.
|
staticprotected |
Extracts the :value bindings from a fragment of a query.
The return value contains the original query, along with new binding elements attached. To find these bindings, all elements need to be searched. This is because with bindings, they can appear in many different areas of an XML query definition. To ensure all elements are only searched for fragments that actually have atleast one binding in them, the XML source of the fragment is searched using a regular expression. If there is a binding found, all elemets of the fragment are obtained, and iterated over. Elements with exactly 1 child are the only ones examined for bindings. If a binding is found, it's parent element(s) are examined to find details about the value ie. the column it applies to, the table etc. These details are added to the newly created <binding> element, and the element is appended to the <bindings> element of the fragments <query> element.
DomElement | $fragment | The object representing the fragment to search in. |
Definition at line 1938 of file DALBaker.inc.
|
staticprotected |
Extracts the keywords ([keyword]) from a fragment of a query.
Each keyword defined in the XML file as [keyword]. Where keyword can be any string with characters a-Z, A-Z and 0-9. The return value contains the original query, along with new keyword elements attached.
DomElement | $fragment | The object representing the fragment to search in. |
Definition at line 2049 of file DALBaker.inc.
|
staticprotected |
Extracts hard-coded values from a query and converts them to bindings.
Finds only hard-coded values that exist inside
tags, and creates a <placeholder> element under the parent <placeholders> element. This new element contains the value, along with a variable name that is composed by combining the table of the value and its column. This variable name is subsituted into the query in place of the original value. This allows the baked out code for the query, to bind the value to the query at run time.
DomElement | $fragment | The object representing the fragment to search in. |
Definition at line 2092 of file DALBaker.inc.
|
staticprotected |
Generates an array of data representing the sub-queries.
string | $systemName | The system to print the sub-queries for. |
string | $queryName | The query to print the sub-queries for. |
DALBakerException | When a specified hook doesn't exist. |
Definition at line 1575 of file DALBaker.inc.
|
staticprotected |
Generates a variable name that corresponds to the assertion node.
Eg. If an assertion is passed that has a channel attribute 'Users::isSystemAdmin', then '$usersIsSystemAdmin' will be returned.
If however a function call is specified in the assertion, then the variable name will be equal to the function name, and its' arguments.
It is used when baking query methods, so that assertions can be consistent and clashes or wrong references can be avoided.
DomElement | $assertion | The channel to generate the variable for. |
DALBakerException | If an assetion doesn't have a funciton call. |
Definition at line 721 of file DALBaker.inc.
|
staticprotected |
Retrieves the PDO data type for a column.
Used when printing bindings for queries.
string | $systemId | System the column is from. |
string | $table | Table the column is in. |
string | $column | The column name. |
string | $dataType | The datatype to bind this value with. Will override any other value. |
Definition at line 2208 of file DALBaker.inc.
|
staticprotected |
Returns an array of assertion objects that are in the query.
string | $systemName | The system where the query belongs. |
string | $queryName | The name of the query. |
Definition at line 690 of file DALBaker.inc.
|
staticprotected |
Combines the passed assertions with the base query.
With all passed assertions, the main query is modified to add the assertion's logic.
DomElement | $baseQuery | The parts of the query that are present without any assertions. |
array | $assertions | An array of DomElements representing each assertion that needs to be merged. |
Definition at line 663 of file DALBaker.inc.
|
staticprotected |
Performs additional operations on a fragment before it is added.
Converts any hard-coded values present into Query Data Placeholders, and adds a <placeholder> element with the value as a child of the main query tag. Also calls _extractBindings() once these new QDPs are inserted which adds <binding> tags for any (query or system defined) bindings to the main query tag. The return DomElement therefore contains all of this data, and is ready to be inserted into the XML file of the channel.
DomElement | $query | The fragment or query to prepare. |
Definition at line 1098 of file DALBaker.inc.
|
staticprotected |
Prints out a condition to control logic of an alternate query.
DomElement | $alternate | The object containing the alternate query and its assertions. |
string | $contents | The PHP code to execute if the condition is met. |
Definition at line 494 of file DALBaker.inc.
|
staticprotected |
Prints out the value of an argument according to its' data type.
If a string is passed, its' value is printed with quotes, if it is an int then the quotes will be omitted etc.
DomElement | $argNode | The argument object to print. |
Definition at line 1440 of file DALBaker.inc.
|
staticprotected |
Prints out the appropriate assignments for the passed assertions.
The returned string contains PHP code that has on each line a variable that is assigned to a channel that an assertion requires.
Eg: For assert-true: $fooSomeChannel = (Foo::SomeChannel() === TRUE);
For assert-false: $fooSomeChannel = (Foo::SomeChannel() === FALSE);
For assert-null: $fooSomeChannel = (Foo::SomeChannel() === NULL);
For assert-empty: $fooSomeChannel = (empty(Foo::SomeChannel()) === TRUE);
The conditions contained in the remaining code then only need to check that an assertion's variable is identical to TRUE as if it is, then the assertion condition passed.
The code will contain code to include the appropriate files from each system that the assertions require to be evaluated.
array | $assertions | The assertions to print calls for. |
Definition at line 1247 of file DALBaker.inc.
|
staticprotected |
Prints out the variable initialisation for the assertion passed.
Assigns the value of the assertion's channel or function call, then assigns it to a variable name generated from the assertion's contents. The returned string is in the form $variable = $method;
DomElement | $assertion | The assertion to print the initialisation for. |
DALBakerException | When the assertion contains no function call. |
Definition at line 1304 of file DALBaker.inc.
|
staticprotected |
Prints code to prepare the query and bind the placeholders to data.
This returns the code that is executed after the $sql variable is obtained from the assertion's conditions. The $dbh variable is initialised by getting the database connection from the DAL. Using the connection, the obtained $sql is prepared. All bindings are then obtained from the XML for the query. If they are a placeholder for a hard-coded value, then the placeholder is bound to the initialised variable, otherwise, the binding is done for an index into the passed $data array.
string | $systemName | The system to print the bindings for. |
string | $queryName | The query to print the bindings for. |
boolean | $printBindings | If TRUE, will print bindings, otherwise will print entries into the query array. |
Definition at line 1844 of file DALBaker.inc.
|
staticprotected |
With an array of hook data, prints out the correct PHP code.
The data provided must be in the form: array ( [$hook_id] => array ( [parent-type] => '', [sub-queries] => array ( array ( [assertion_var] => 'name_of_var', [sub-query] => DOMElement, ), ... ),
),
);
array | $hookIds | Data for the hooks to print. |
Definition at line 1668 of file DALBaker.inc.
|
staticprotected |
Prints code to replace keywords inside the SQL string.
Each keyword defined in the XML file as [keyword]. Where keyword is part of the channel event basket. If keyword does not exists in the event basket then sql will not be modified and most likely cause SQL error.
string | $systemName | The system to print the bindings for. |
string | $queryName | The query to print the bindings for. |
Definition at line 1795 of file DALBaker.inc.
|
staticprotected |
Returns an SQL string that corresponds to the passed DomElement.
The returned string contains a full assigment to a variables $sql. This allows the code to be inserted straight into the body of an assertion's condition body.
DomElement | $query | The object containing the query's structure. |
string | $baseId | The base ID to base the file on. |
array | $idParts | The parts of the ID to make up the hash of to add to the end of the filename. |
Definition at line 1474 of file DALBaker.inc.
|
staticprotected |
Returns PHP code for any placeholder elements that exist in the query.
The code returned contains assignments that set each variable to the hard-coded value that was defined in the original query. These variables are then bound to the query later in the generated code.
string | $systemName | The system to print the placeholders for. |
string | $queryName | The query to print the placeholders for. |
Definition at line 1529 of file DALBaker.inc.
|
staticprotected |
Recursively add an assertion to the tree structure.
Returns an array that contains structures for each assertion present in the $assertions array (by recursively calling itself). The array is in the form: array( 'if_condition' => array( 'current_assertion' => DomElement 'assertions' => array(), 'children' => array(), ), 'else_condition' => array( 'assertions' => array(), 'children' => array(), ), );
array | $assertions | An array of assertions that are yet to be added to the tree structure. |
array | $currentStack | An array of assertions that currently apply to this branch of the tree. |
Definition at line 535 of file DALBaker.inc.
|
staticprotected |
Recursively prints out the PHP code for the tree of a query.
Prints out the conditional statements that match the assertions and fragments present in the query.
array | $tree | The tree that has been built by _recurseAddAssertion() via the calling function. |
DomElement | $baseQuery | The Node of the base query, containing the structure that exists regardless of assertions. |
string | $baseQueryId | The base name of the query to print. |
integer | $level | The level that the current assertion is at. This is used to indent the code. |
Definition at line 589 of file DALBaker.inc.
|
staticprotected |
Creates and writes out a query object.
string | $id | The object containing the query's structure. |
array | $sqlArray | The array representation of the query. |
string | $sql | The SQL of the query. |
DALException | When the query object being written already exists. |
Definition at line 1499 of file DALBaker.inc.
|
static |
Adds a base query definition to the query's XML file.
Extracts any hard-coded values, along with bindings and adds the data to the query object. Then saves the new data to the XML file.
string | $systemName | The system to add the query to. |
DomElement | $query | The node containing the query to add. |
Definition at line 895 of file DALBaker.inc.
|
static |
Adds a base query fragment definition to the query's XML file.
Extracts any hard-coded values, along with bindings and adds the data to the query object. Then saves the new data to the XML file.
string | $systemName | The system the fragment has come from. |
DomElement | $fragment | The node containing the fragment to add. |
Definition at line 940 of file DALBaker.inc.
|
static |
Adds a sub-query that wishes to hook into a main query.
Extracts any hard-coded values, along with bindings and adds the data to the query object. Then saves the new data to the XML file.
string | $systemName | The system the fragment has come from. |
DomElement | $subQuery | The node containing the fragment to add. |
Definition at line 984 of file DALBaker.inc.
|
static |
Adds the queries from a system to their appropriate Oven locations.
string | $systemName | The system to add the query to. |
DALBakerException | When an ID isn't specifued for a query. |
Definition at line 265 of file DALBaker.inc.
|
static |
Adds and creates the schema for the supplied system.
Will find the schema.xml file from the system's directory, iterate through each of the elements it wishes to create, and will then create or update the database.
string | $systemName | The system whose schema to add. |
Definition at line 154 of file DALBaker.inc.
|
static |
Bakes out a system's queries and business logic into PHP files.
Calls bakeQueryMethod() for each query that the system has defined. For the query to be baked correctly it is required that its' XML files have been created in the system's oven directory.
string | $systemName | Name of the system to bake the code for. |
DALBakerException | If the system name supplied is empty. |
Definition at line 1134 of file DALBaker.inc.
|
static |
Bakes out a method for a single query.
Reads in the XML files that have been generated for this query, gets all fragments and their assertions, and bakes out an appropriate method that will return an SQL statement that corresponds to the current system state and the systems currently installed.
string | $systemName | The name of the system to which the query belongs. |
string | $queryName | The name of the query to bake. |
Definition at line 1183 of file DALBaker.inc.
|
static |
Constructs an SQL query from DomElement.
This is the main function where the SQL array is constructed from XML. It will combine queries from different parts of the system.
DomElement | $query | DomElement that represents a single query. |
Definition at line 2679 of file DALBaker.inc.
|
static |
Converts given XML query to its SQL format.
DomElement | $xmlQuery | Single XML query. |
array | $sqlArray | The Array representation of the SQL, if it has already been generated. |
Definition at line 2421 of file DALBaker.inc.
|
static |
Creates systems DAL oven directory.
Returns true on success, false if directory already exists, and throws ChannelExeption if it cannot create the directory.
string | $system | System name. |
ChannelException | When the path cannot be created. |
Definition at line 2555 of file DALBaker.inc.
|
static |
Returns true if the fragment exists.
string | $system | Id of the system. |
string | $queryid | Id of the main query. |
string | $hookid | Id of the fragment. |
Definition at line 2386 of file DALBaker.inc.
|
static |
Generates a base file for adding XML data for the query specified.
string | $systemName | The name of the system the query is from. |
string | $queryName | The name of the query to create the XML file for. |
Definition at line 786 of file DALBaker.inc.
|
static |
Returns the file name of the baked query file.
string | $systemid | Id of the system. |
string | $queryid | Id of the query. |
Definition at line 2606 of file DALBaker.inc.
|
static |
Returns list of allowed where clause conditions.
string | $type | Type of the condition. It will return its sign. |
Definition at line 2719 of file DALBaker.inc.
|
static |
Returns the DAL converter class for a given db type.
If no dbType is given then the db type specified in DALConf will be used.
string | $dbType | Database Type. |
Definition at line 2443 of file DALBaker.inc.
|
static |
Parses the connection string and returns the database type.
array | $dsn | The DSN array to parse. If NULL, the DSN setting of the current connection will be used. |
Definition at line 2743 of file DALBaker.inc.
|
static |
Returns a string like $hook_iddArray corresponding to the hook id passed.
This ID is used for the variable name of the array storing all fragments that wish to reference the hook.
string | $hookId | The hook id to retrieve the array ID for. |
Definition at line 1743 of file DALBaker.inc.
|
static |
Returns a string like HOOKID:hook_id corresponding to the hook id passed.
This ID is used for replacements in PHP code.
string | $hookId | The hook id to retireve the code ID for. |
Definition at line 1725 of file DALBaker.inc.
|
static |
Returns a prefix for the hooks.
Baker will later on look for this prefix in SQL query string and replace them with other SQL queries.
Definition at line 2703 of file DALBaker.inc.
|
static |
Returns query in its XML format.
DomElement of the query in queries.xml file is returned. Null if query was not found.
string | $systemid | System name that the query belongs to. |
string | $queryid | Id of the query. |
Definition at line 2524 of file DALBaker.inc.
|
static |
Returns the given queries type.
DomElement | $query | The query element. |
Definition at line 2363 of file DALBaker.inc.
|
static |
Retrieve the object representing the query's XML file.
string | $systemName | The name of the system the query is in. |
string | $queryName | The name of the query to retrieve the XML file for. |
Definition at line 837 of file DALBaker.inc.
|
static |
Gets the text for a seperator from the tag type passed.
string | $tagName | The tag name to get the seperator for. |
Definition at line 1759 of file DALBaker.inc.
|
static |
Returns the DomDocument for the schema.xml of the specfied system.
Returns null if the system does not contain a system.xml file.
string | $systemName | The name of the system to retrieve the schema for. |
Definition at line 125 of file DALBaker.inc.
|
static |
Gets the column types of a specific table in a system.
If column argument is NULL then array of all column types will be returned. If column argument is not NULL then a single type will be returned. Returns NULL if table/column not found.
string | $systemid | Id of the system. |
string | $table | Name of the table. |
string | $column | Name of a single column. |
Definition at line 2474 of file DALBaker.inc.
|
static |
Returns the DomElement of the baked query file.
string | $systemid | Id of the system. |
string | $queryid | Id of the query. |
Definition at line 2623 of file DALBaker.inc.
|
static |
Returns the DomDocument object for the system's queries XML.
Returns NULL if queries.xml cannot be loaded.
string | $systemid | System name. |
Definition at line 2582 of file DALBaker.inc.
|
static |
Loads the System's schema XML file.
Returns NULL if schema file could not be loaded.
string | $systemid | Id of the system. |
Definition at line 2648 of file DALBaker.inc.
|
static |
Merges the base query and all of its' fragments.
Returns a string containing the PHP code for the query, and any possible combinations of queries with the assertions present.
string | $systemName | The system to which the query belongs. |
string | $queryName | The name of the query to generate. |
DALBakerException | When there is no primary query found. |
Definition at line 366 of file DALBaker.inc.
|
static |
Converts XML schema to php array.
DomElement | $schema | Schema node of a schema. |
Definition at line 2244 of file DALBaker.inc.
|
static |
Prints out the data for searching and replacing sub-queries.
string | $systemName | The system to print the sub-queries for. |
string | $queryName | The query to print the sub-queries for. |
Definition at line 1557 of file DALBaker.inc.
|
static |
Processes a queries.xml file to prepare it for baking
string | $systemName | The system to add queries to. |
string | $fileName | The name of the queries file. |
DALBakerException | When an ID isn't specified for a query. |
Definition at line 293 of file DALBaker.inc.
|
static |
Returns FALSE if given query id already used by another query.
DomDocument | $doc | DomDocument object. |
DomElement | $query | Query element. |
Definition at line 2301 of file DALBaker.inc.
|
static |
Returns TRUE if the XML file for a system exists.
string | $systemName | The name of the system to check for. |
string | $queryName | The name of the query to check the XML file for. |
Definition at line 817 of file DALBaker.inc.
|
static |
Save the passed representation of the query.
string | $system | The name of the system the query is in. |
string | $queryName | The name of the query to save. |
DomDocument | $doc | The Object representing the new XML contents. |
Definition at line 864 of file DALBaker.inc.
|
static |
Validates all the queries under the given queries node.
Throws DALParserException if any errors found.
DomElement | $queries | The queries node of the queries XML file. |
DALParserException | When a query tag doesn't have a system attribute. |
Definition at line 2270 of file DALBaker.inc.
|
static |
Validates the given query.
Throws DALParserException if any errors found.
DomElement | $query | The query element. |
DALParserException | When a query is missing an ID, its' ID is not unique, or the query is invalidly formatted. |
Definition at line 2331 of file DALBaker.inc.