1
0
mirror of synced 2025-01-18 06:21:40 +03:00
2006-12-21 22:06:08 +00:00

61 lines
1.6 KiB
PHP

<?php
Doctrine::autoload("Doctrine_Query_Part");
class Doctrine_Query_From extends Doctrine_Query_Part {
/**
* DQL FROM PARSER
* parses the from part of the query string
* @param string $str
* @return void
*/
final public function parse($str) {
$str = trim($str);
$parts = Doctrine_Query::bracketExplode($str, 'JOIN');
$operator = false;
switch(trim($parts[0])) {
case 'INNER':
$operator = ':';
case 'LEFT':
array_shift($parts);
}
$last = '';
foreach($parts as $k => $part) {
$part = trim($part);
if(empty($part)) {
continue;
}
$e = explode(' ', $part);
if(end($e) == 'INNER' || end($e) == 'LEFT')
$last = array_pop($e);
$part = implode(' ', $e);
foreach(Doctrine_Query::bracketExplode($part, ',') as $reference) {
$reference = trim($reference);
$e = explode('.', $reference);
if($operator) {
$reference = array_shift($e) . $operator . implode('.', $e);
}
$table = $this->query->load($reference);
}
$operator = ($last == 'INNER') ? ':' : '.';
}
}
public function __toString() {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}