diff -r 000000000000 -r 7f95f8617b0b vendor/doctrine/lib/Doctrine/ORM/Query/Expr/Base.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/doctrine/lib/Doctrine/ORM/Query/Expr/Base.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,85 @@ +. + */ + +namespace Doctrine\ORM\Query\Expr; + +/** + * Abstract base Expr class for building DQL parts + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +abstract class Base +{ + protected $_preSeparator = '('; + protected $_separator = ', '; + protected $_postSeparator = ')'; + protected $_allowedClasses = array(); + + protected $_parts = array(); + + public function __construct($args = array()) + { + $this->addMultiple($args); + } + + public function addMultiple($args = array()) + { + foreach ((array) $args as $arg) { + $this->add($arg); + } + } + + public function add($arg) + { + if ( $arg !== null || ($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 new \InvalidArgumentException("Expression of type '$class' not allowed in this context."); + } + } + + $this->_parts[] = $arg; + } + } + + public function count() + { + return count($this->_parts); + } + + public function __toString() + { + if ($this->count() == 1) { + return (string) $this->_parts[0]; + } + + return $this->_preSeparator . implode($this->_separator, $this->_parts) . $this->_postSeparator; + } +} \ No newline at end of file