From 976d6dc80c06a353683f8902f83a7a1100a98e2d Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 19 Apr 2023 11:24:32 +0200 Subject: [PATCH 1/4] Add Criteria merge --- src/Criteria.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Criteria.php b/src/Criteria.php index eb49cbc6..1470591c 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -8,7 +8,9 @@ use Doctrine\Common\Collections\Expr\Expression; use Doctrine\Deprecations\Deprecation; +use function array_filter; use function array_map; +use function array_merge; use function func_num_args; use function strtoupper; @@ -54,6 +56,21 @@ public static function expr() return self::$expressionBuilder; } + + /** + * Merges two Criteria together. + * + * @return self + */ + public static function merge(Criteria $leftCriteria, Criteria $rightCriteria) + { + return self::create() + ->andWhere(Criteria::expr()->andX(...array_filter([$leftCriteria->getWhereExpression(), $rightCriteria->getWhereExpression()]))) + ->orderBy(array_merge($leftCriteria->getOrderings(), $rightCriteria->getOrderings())) + ->setFirstResult($rightCriteria->getFirstResult() ?? $leftCriteria->getFirstResult()) + ->setMaxResults($rightCriteria->getMaxResults() ?? $leftCriteria->getFirstResult()); + } + /** * Construct a new Criteria. * From 4802d79e716bc11fd93cebb9cb4ef3d59001baa8 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 19 Apr 2023 11:27:37 +0200 Subject: [PATCH 2/4] Remove empty line --- src/Criteria.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Criteria.php b/src/Criteria.php index 1470591c..f358d0ac 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -56,7 +56,6 @@ public static function expr() return self::$expressionBuilder; } - /** * Merges two Criteria together. * From cc1232f9554b7ac6d75518d35cdf7b1670cf0d66 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 25 Apr 2023 18:57:03 +0200 Subject: [PATCH 3/4] Change self to static within criteria merge --- src/Criteria.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Criteria.php b/src/Criteria.php index f358d0ac..2a4cf5e0 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -59,11 +59,11 @@ public static function expr() /** * Merges two Criteria together. * - * @return self + * @return static */ public static function merge(Criteria $leftCriteria, Criteria $rightCriteria) { - return self::create() + return static::create() ->andWhere(Criteria::expr()->andX(...array_filter([$leftCriteria->getWhereExpression(), $rightCriteria->getWhereExpression()]))) ->orderBy(array_merge($leftCriteria->getOrderings(), $rightCriteria->getOrderings())) ->setFirstResult($rightCriteria->getFirstResult() ?? $leftCriteria->getFirstResult()) From b5f828375d02d89100c6742afa58eaef33d088a9 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 25 Apr 2023 19:20:14 +0200 Subject: [PATCH 4/4] Replace Criteria within Criteria with self --- src/Criteria.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Criteria.php b/src/Criteria.php index 2a4cf5e0..782f1013 100644 --- a/src/Criteria.php +++ b/src/Criteria.php @@ -59,12 +59,12 @@ public static function expr() /** * Merges two Criteria together. * - * @return static + * @return self */ public static function merge(Criteria $leftCriteria, Criteria $rightCriteria) { - return static::create() - ->andWhere(Criteria::expr()->andX(...array_filter([$leftCriteria->getWhereExpression(), $rightCriteria->getWhereExpression()]))) + return self::create() + ->andWhere(self::expr()->andX(...array_filter([$leftCriteria->getWhereExpression(), $rightCriteria->getWhereExpression()]))) ->orderBy(array_merge($leftCriteria->getOrderings(), $rightCriteria->getOrderings())) ->setFirstResult($rightCriteria->getFirstResult() ?? $leftCriteria->getFirstResult()) ->setMaxResults($rightCriteria->getMaxResults() ?? $leftCriteria->getFirstResult());