diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/collections/src/Expr/CompositeExpression.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/collections/src/Expr/CompositeExpression.php')
| -rw-r--r-- | vendor/doctrine/collections/src/Expr/CompositeExpression.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/doctrine/collections/src/Expr/CompositeExpression.php b/vendor/doctrine/collections/src/Expr/CompositeExpression.php new file mode 100644 index 0000000..b7b4544 --- /dev/null +++ b/vendor/doctrine/collections/src/Expr/CompositeExpression.php | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\Common\Collections\Expr; | ||
| 6 | |||
| 7 | use RuntimeException; | ||
| 8 | |||
| 9 | use function count; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Expression of Expressions combined by AND or OR operation. | ||
| 13 | */ | ||
| 14 | class CompositeExpression implements Expression | ||
| 15 | { | ||
| 16 | final public const TYPE_AND = 'AND'; | ||
| 17 | final public const TYPE_OR = 'OR'; | ||
| 18 | final public const TYPE_NOT = 'NOT'; | ||
| 19 | |||
| 20 | /** @var list<Expression> */ | ||
| 21 | private array $expressions = []; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * @param Expression[] $expressions | ||
| 25 | * | ||
| 26 | * @throws RuntimeException | ||
| 27 | */ | ||
| 28 | public function __construct(private readonly string $type, array $expressions) | ||
| 29 | { | ||
| 30 | foreach ($expressions as $expr) { | ||
| 31 | if ($expr instanceof Value) { | ||
| 32 | throw new RuntimeException('Values are not supported expressions as children of and/or expressions.'); | ||
| 33 | } | ||
| 34 | |||
| 35 | if (! ($expr instanceof Expression)) { | ||
| 36 | throw new RuntimeException('No expression given to CompositeExpression.'); | ||
| 37 | } | ||
| 38 | |||
| 39 | $this->expressions[] = $expr; | ||
| 40 | } | ||
| 41 | |||
| 42 | if ($type === self::TYPE_NOT && count($this->expressions) !== 1) { | ||
| 43 | throw new RuntimeException('Not expression only allows one expression as child.'); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Returns the list of expressions nested in this composite. | ||
| 49 | * | ||
| 50 | * @return list<Expression> | ||
| 51 | */ | ||
| 52 | public function getExpressionList() | ||
| 53 | { | ||
| 54 | return $this->expressions; | ||
| 55 | } | ||
| 56 | |||
| 57 | /** @return string */ | ||
| 58 | public function getType() | ||
| 59 | { | ||
| 60 | return $this->type; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 | * {@inheritDoc} | ||
| 65 | */ | ||
| 66 | public function visit(ExpressionVisitor $visitor) | ||
| 67 | { | ||
| 68 | return $visitor->walkCompositeExpression($this); | ||
| 69 | } | ||
| 70 | } | ||
