-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address deprecations from Collection 2.2
- Loading branch information
Showing
13 changed files
with
144 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Internal; | ||
|
||
use Doctrine\Common\Collections\Criteria; | ||
use Doctrine\Common\Collections\Order; | ||
|
||
use function array_map; | ||
use function class_exists; | ||
use function method_exists; | ||
use function strtoupper; | ||
|
||
trait CriteriaOrderings | ||
{ | ||
/** | ||
* @return array<string, string> | ||
* | ||
* @psalm-suppress DeprecatedMethod We need to call the deprecated API if the new one does not exist yet. | ||
*/ | ||
private static function getCriteriaOrderings(Criteria $criteria): array | ||
{ | ||
if (! method_exists(Criteria::class, 'orderings')) { | ||
return $criteria->getOrderings(); | ||
} | ||
|
||
return array_map( | ||
static function (Order $order): string { | ||
return $order->value; | ||
}, | ||
$criteria->orderings() | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string, string> $orderings | ||
* | ||
* @return array<string, string>|array<string, Order> | ||
*/ | ||
private static function mapToOrderEnumIfAvailable(array $orderings): array | ||
{ | ||
if (! class_exists(Order::class)) { | ||
return $orderings; | ||
} | ||
|
||
return array_map( | ||
static function (string $order): Order { | ||
return Order::from(strtoupper($order)); | ||
}, | ||
$orderings | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.