. */ namespace Doctrine\ORM\Query\Expr; /** * Abstract class for building DQL expressions * * @author Jonathan H. Wage * @author Guilherme Blanco * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ abstract class Base { protected $_preSeparator = '('; protected $_separator = ', '; protected $_postSeparator = ')'; protected $_allowedClasses = array(); private $_parts = array(); public function __construct($args = array()) { foreach ($args as $arg) { $this->add($arg); } } public function add($arg) { if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) { // If we decide to keep Expr\Base instances, we can use this check if ( ! is_string($arg)) { $class = get_class($arg); if ( ! in_array($class, $this->_allowedClasses)) { throw \Doctrine\Common\DoctrineException::updateMe("Class '{$class}' is not allowed in " . get_class($this) . " instance."); } } $this->_parts[] = $arg; } } public function count() { return count($this->_parts); } public function __tostring() { return $this->_preSeparator . implode($this->_separator, $this->_parts) . $this->_postSeparator; } }