Source for file Parser2.php
Documentation is available at Parser2.php
* Copyright (c) 1998-2008 Manuel Lemos, Tomas V.V.Cox,
* Stig. S. Bakken, Lukas Smith, Igor Feghali
* MDB2_Schema enables users to maintain RDBMS independant schema files
* in XML that can be used to manipulate both data and database schemas
* This LICENSE is in the BSD license style.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,
* Lukas Smith, Igor Feghali nor the names of his contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* Author: Igor Feghali <ifeghali@php.net>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @version CVS: $Id: Parser2.php,v 1.12 2008/11/30 03:34:00 clockwerx Exp $
* @link http://pear.php.net/packages/MDB2_Schema
require_once 'XML/Unserializer.php';
require_once 'MDB2/Schema/Validate.php';
* Parses an XML schema file
* @author Lukas Smith <smith@pooteeweet.org>
* @author Igor Feghali <ifeghali@php.net>
* @license BSD http://www.opensource.org/licenses/bsd-license.php
* @link http://pear.php.net/packages/MDB2_Schema
function __construct($variables, $fail_on_invalid_names = true , $structure = false , $valid_types = array (), $force_defaults = true )
// force ISO-8859-1 due to different defaults for PHP4 and PHP5
// todo: this probably needs to be investigated some more and cleaned up
$this->options['encoding'] = 'ISO-8859-1';
$this->options['XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE'] = true;
$this->options['XML_UNSERIALIZER_OPTION_ATTRIBUTES_ARRAYKEY'] = false;
$this->options['forceEnum'] = array ('table', 'field', 'index', 'foreign', 'insert', 'update', 'delete', 'sequence');
* todo: find a way to force the following items not to be parsed as arrays
* as it cause problems in functions with multiple arguments
//$this->options['forceNEnum'] = array('value', 'column');
parent ::XML_Unserializer ($this->options);
function MDB2_Schema_Parser2($variables, $fail_on_invalid_names = true , $structure = false , $valid_types = array (), $force_defaults = true )
$this->__construct($variables, $fail_on_invalid_names, $structure, $valid_types, $force_defaults);
$result = $this->unserialize ($this->filename, true );
if (PEAR ::isError ($result)) {
$this->filename = $filename;
$arr[$nKey] = &$arr[$oKey];
if (!empty ($database['name'])) {
if (!empty ($database['create'])) {
if (!empty ($database['overwrite'])) {
if (!empty ($database['charset'])) {
if (!empty ($database['description'])) {
if (!empty ($database['comments'])) {
if (!empty ($database['table']) && is_array($database['table'])) {
foreach ($database['table'] as $table) {
if (!empty ($database['sequence']) && is_array($database['sequence'])) {
foreach ($database['sequence'] as $sequence) {
if (PEAR ::isError ($result)) {
'constraints' => array (),
'initialization' => array ()
if (!empty ($table['name'])) {
if (!empty ($table['was'])) {
$this->table['was'] = $table['was'];
if (!empty ($table['description'])) {
$this->table['description'] = $table['description'];
if (!empty ($table['comments'])) {
$this->table['comments'] = $table['comments'];
if (!empty ($table['declaration']) && is_array($table['declaration'])) {
if (!empty ($table['declaration']['field']) && is_array($table['declaration']['field'])) {
foreach ($table['declaration']['field'] as $field) {
if (!empty ($table['declaration']['index']) && is_array($table['declaration']['index'])) {
foreach ($table['declaration']['index'] as $index) {
if (!empty ($table['declaration']['foreign']) && is_array($table['declaration']['foreign'])) {
foreach ($table['declaration']['foreign'] as $constraint) {
if (!empty ($table['initialization']) && is_array($table['initialization'])) {
if (!empty ($table['initialization']['insert']) && is_array($table['initialization']['insert'])) {
foreach ($table['initialization']['insert'] as $init) {
if (!empty ($table['initialization']['update']) && is_array($table['initialization']['update'])) {
foreach ($table['initialization']['update'] as $init) {
if (!empty ($table['initialization']['delete']) && is_array($table['initialization']['delete'])) {
foreach ($table['initialization']['delete'] as $init) {
if (PEAR ::isError ($result)) {
if (!empty ($field['name'])) {
if (!empty ($field['was'])) {
$this->field['was'] = $field['was'];
if (!empty ($field['type'])) {
$this->field['type'] = $field['type'];
if (!empty ($field['fixed'])) {
$this->field['fixed'] = $field['fixed'];
if (isset ($field['default'])) {
$this->field['default'] = $field['default'];
if (!empty ($field['notnull'])) {
$this->field['notnull'] = $field['notnull'];
if (!empty ($field['autoincrement'])) {
$this->field['autoincrement'] = $field['autoincrement'];
if (!empty ($field['unsigned'])) {
$this->field['unsigned'] = $field['unsigned'];
if (!empty ($field['length'])) {
$this->field['length'] = $field['length'];
if (!empty ($field['description'])) {
$this->field['description'] = $field['description'];
if (!empty ($field['comments'])) {
$this->field['comments'] = $field['comments'];
if (PEAR ::isError ($result)) {
if (!empty ($index['name'])) {
if (!empty ($index['was'])) {
$this->index['was'] = $index['was'];
if (!empty ($index['unique'])) {
$this->index['unique'] = $index['unique'];
if (!empty ($index['primary'])) {
$this->index['primary'] = $index['primary'];
if (!empty ($index['field'])) {
foreach ($index['field'] as $field) {
if (!empty ($field['name'])) {
if (!empty ($field['sorting'])) {
$this->field['sorting'] = $field['sorting'];
if (!empty ($field['length'])) {
$this->field['length'] = $field['length'];
if (PEAR ::isError ($result)) {
if (PEAR ::isError ($result)) {
'initiallydeferred' => '',
'references' => array ('table' => '', 'fields' => array ())
if (!empty ($constraint['name'])) {
if (!empty ($constraint['was'])) {
if (!empty ($constraint['match'])) {
$this->constraint['match'] = $constraint['match'];
if (!empty ($constraint['ondelete'])) {
$this->constraint['ondelete'] = $constraint['ondelete'];
if (!empty ($constraint['onupdate'])) {
$this->constraint['onupdate'] = $constraint['onupdate'];
if (!empty ($constraint['deferrable'])) {
$this->constraint['deferrable'] = $constraint['deferrable'];
if (!empty ($constraint['initiallydeferred'])) {
$this->constraint['initiallydeferred'] = $constraint['initiallydeferred'];
if (!empty ($constraint['field']) && is_array($constraint['field'])) {
foreach ($constraint['field'] as $field) {
$result = $this->val->validateConstraintField ($this->constraint['fields'], $field);
if (PEAR ::isError ($result)) {
if (!empty ($constraint['references']) && is_array($constraint['references'])) {
* As we forced 'table' to be enumerated
* we have to fix it on the foreign-references-table context
if (!empty ($constraint['references']['table']) && is_array($constraint['references']['table'])) {
$this->constraint['references']['table'] = $constraint['references']['table'][0 ];
if (!empty ($constraint['references']['field']) && is_array($constraint['references']['field'])) {
foreach ($constraint['references']['field'] as $field) {
$result = $this->val->validateConstraintReferencedField ($this->constraint['references']['fields'], $field);
if (PEAR ::isError ($result)) {
$this->constraint['references']['fields'][$field] = '';
if (PEAR ::isError ($result)) {
if (!empty ($element['select']) && is_array($element['select'])) {
$this->init = array ( 'select' => $this->init );
$this->table['initialization'][] = array ( 'type' => $type, 'data' => $this->init );
if (!empty ($element['field']) && is_array($element['field'])) {
foreach ($element['field'] as $field) {
$this->init['field'][] = array ( 'name' => $name, 'group' => $field );
* As we forced 'table' to be enumerated
* we have to fix it on the insert-select context
if (!empty ($element['table']) && is_array($element['table'])) {
$this->init['table'] = $element['table'][0 ];
if (!empty ($element['where']) && is_array($element['where'])) {
$this->init['where'] = $element['where'];
$arr = array ( 'type' => $element['key'] );
$element = $element['value'];
$arr['data'] = array ( 'name' => $element['name'] );
foreach ($element as $type => $value) {
foreach ($value as $argument) {
$argument = array ( $type => $argument );
$arr['data']['arguments'][] = $argument;
$arr['data']['arguments'][] = array ( 'type' => $type, 'data' => $value );
$arr['data'] = array ( 'operants' => array (), 'operator' => $element['operator'] );
unset ($element['operator']);
foreach ($element as $k => $v) {
$argument = array ( $k => $v );
$arr['data']['operants'][] = $argument;
'on' => array ('table' => '', 'field' => '')
if (!empty ($sequence['name'])) {
if (!empty ($sequence['was'])) {
$this->sequence['was'] = $sequence['was'];
if (!empty ($sequence['start'])) {
$this->sequence['start'] = $sequence['start'];
if (!empty ($sequence['description'])) {
$this->sequence['description'] = $sequence['description'];
if (!empty ($sequence['comments'])) {
$this->sequence['comments'] = $sequence['comments'];
if (!empty ($sequence['on']) && is_array($sequence['on'])) {
* As we forced 'table' to be enumerated
* we have to fix it on the sequence-on-table context
if (!empty ($sequence['on']['table']) && is_array($sequence['on']['table'])) {
$this->sequence['on']['table'] = $sequence['on']['table'][0 ];
* As we forced 'field' to be enumerated
* we have to fix it on the sequence-on-field context
if (!empty ($sequence['on']['field']) && is_array($sequence['on']['field'])) {
$this->sequence['on']['field'] = $sequence['on']['field'][0 ];
if (PEAR ::isError ($result)) {
function &raiseError($msg = null , $ecode = MDB2_SCHEMA_ERROR_PARSE )
$error = 'Parser error: '. $msg. "\n";
Documentation generated on Sun, 22 Feb 2009 22:30:07 +0000 by phpDocumentor 1.4.2. PEAR Logo Copyright © PHP Group 2004.
|