. */ /** * Term = Factor {("*" | "/") Factor} * * @package Doctrine * @subpackage Query * @author Guilherme Blanco * @author Janne Vanhala * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ class Doctrine_Query_Production_Term extends Doctrine_Query_Production { protected $_factors = array(); public function syntax($paramHolder) { // Term = Factor {("*" | "/") Factor} $this->_factors[] = $this->AST('Factor', $paramHolder); while ($this->_isNextToken('*') || $this->_isNextToken('/')) { if ($this->_isNextToken('*')) { $this->_parser->match('*'); $this->_factors[] = '*'; } else { $this->_parser->match('/'); $this->_factors[] = '/'; } $this->_factors[] = $this->AST('Factor', $paramHolder); } // Optimize depth instances in AST if (count($this->_factors) == 1) { return $this->_factors[0]; } } public function semantical($paramHolder) { for ($i = 0, $l = count($this->_factors); $i < $l; $i++) { if ($this->_factors[$i] != '*' && $this->_factors[$i] != '/') { $this->_factors[$i]->semantical($paramHolder); } } } public function buildSql() { return implode(' ', $this->_mapFactors()); } protected function _mapFactors() { return array_map(array(&$this, '_mapFactor'), $this->_factors); } protected function _mapFactor($value) { return (is_string($value) ? $value : $value->buildSql()); } /** * Visitor support. */ public function accept($visitor) { foreach ($this->_factors as $factor) { $factor->accept($visitor); } $visitor->visitTerm($this); } /* Getters */ public function getFactors() { return $this->_factors; } }