123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
-
-
- namespace Doctrine\DBAL\Query\Expression;
-
-
- class CompositeExpression implements \Countable
- {
-
-
- const TYPE_AND = 'AND';
-
-
-
- const TYPE_OR = 'OR';
-
-
-
- private $type;
-
-
-
- private $parts = array();
-
-
-
- public function __construct($type, array $parts = array())
- {
- $this->type = $type;
-
- $this->addMultiple($parts);
- }
-
-
-
- public function addMultiple(array $parts = array())
- {
- foreach ((array) $parts as $part) {
- $this->add($part);
- }
-
- return $this;
- }
-
-
-
- public function add($part)
- {
- if ( ! empty($part) || ($part instanceof self && $part->count() > 0)) {
- $this->parts[] = $part;
- }
-
- return $this;
- }
-
-
-
- public function count()
- {
- return count($this->parts);
- }
-
-
-
- public function __toString()
- {
- if (count($this->parts) === 1) {
- return (string) $this->parts[0];
- }
-
- return '(' . implode(') ' . $this->type . ' (', $this->parts) . ')';
- }
-
-
-
- public function getType()
- {
- return $this->type;
- }
- }
|