Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALFromParser.inc
1 <?php
13 require_once 'DAL/Parsers/DALQueryParser.inc';
14 require_once 'DAL/Parsers/DALUnionParser.inc';
15 require_once 'DAL/Parsers/DALSelectParser.inc';
16 require_once 'DAL/DALBaker.inc';
17 require_once 'XML/XML.inc';
18 
27 {
28 
29 
38  private function __construct()
39  {
40 
41  }//end __construct()
42 
43 
59  public static function parse(DomElement $fromTag)
60  {
61  if ($fromTag->tagName !== 'from') {
62  $fromTag = $fromTag->getElementsByTagName('from')->item(0);
63  }
64 
65  $from = array();
66  if ($fromTag !== NULL) {
67  $from['FROM'] = array();
68 
69  // Get union/union-all if there is one, else get tables.
70  $unionTag = self::getUnionTag($fromTag);
71  if ($unionTag !== NULL) {
72  $from['FROM'] = DALUnionParser::parse($fromTag);
73  } else {
74  $tables = XML::getElementsByTagNames(array('table', 'hook'), $fromTag);
75  foreach ($fromTag->childNodes as $table) {
76  if ($table->nodeType !== XML_ELEMENT_NODE) {
77  continue;
78  }
79 
80  // Make sure this is the first level.
81  if ($table->tagName === 'hook') {
82  $hook = DALBaker::getHookPrefix().$table->getAttribute('id');
83  // Add the hook to the 'FROM' array.
84  $from['FROM'][] = $hook;
85  } else if ($table->tagName === 'table') {
86  // Could have a select statement.
87  $tableInfo = array();
88  $tblSelect = $table->getElementsByTagName('select')->item(0);
89  if ($tblSelect !== NULL) {
90  $tableInfo['name'] = DALSelectParser::parse($tblSelect);
91  } else {
92  $tableInfo['name'] = $table->nodeValue;
93  }
94 
95  // Check if we have alias.
96  if ($table->getAttribute('alias') !== '') {
97  $tableInfo['alias'] = $table->getAttribute('alias');
98  }
99 
100  if (isset($tableInfo['alias']) === TRUE) {
101  $from['FROM'][] = $tableInfo;
102  } else {
103  $from['FROM'][] = $tableInfo['name'];
104  }
105  } else if ($table->tagName === 'function') {
106  self::validateFunctionTag($table);
107  $from['FROM'][] = self::parseSqlFunction($table);
108  }//end if
109  }//end foreach
110  }//end if
111  }//end if
112 
113  return $from;
114 
115  }//end parse()
116 
117 
118 }//end class
119 
120 ?>