12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
-
-
- namespace Doctrine\ORM\Query\Expr;
-
-
- 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 ( ! 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;
- }
- }
|