diff options
Diffstat (limited to 'vendor/doctrine/orm/src/Query/Expr/OrderBy.php')
| -rw-r--r-- | vendor/doctrine/orm/src/Query/Expr/OrderBy.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Query/Expr/OrderBy.php b/vendor/doctrine/orm/src/Query/Expr/OrderBy.php new file mode 100644 index 0000000..ac9e160 --- /dev/null +++ b/vendor/doctrine/orm/src/Query/Expr/OrderBy.php | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Query\Expr; | ||
| 6 | |||
| 7 | use Stringable; | ||
| 8 | |||
| 9 | use function count; | ||
| 10 | use function implode; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Expression class for building DQL Order By parts. | ||
| 14 | * | ||
| 15 | * @link www.doctrine-project.org | ||
| 16 | */ | ||
| 17 | class OrderBy implements Stringable | ||
| 18 | { | ||
| 19 | protected string $preSeparator = ''; | ||
| 20 | protected string $separator = ', '; | ||
| 21 | protected string $postSeparator = ''; | ||
| 22 | |||
| 23 | /** @var string[] */ | ||
| 24 | protected array $allowedClasses = []; | ||
| 25 | |||
| 26 | /** @psalm-var list<string> */ | ||
| 27 | protected array $parts = []; | ||
| 28 | |||
| 29 | public function __construct( | ||
| 30 | string|null $sort = null, | ||
| 31 | string|null $order = null, | ||
| 32 | ) { | ||
| 33 | if ($sort) { | ||
| 34 | $this->add($sort, $order); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | public function add(string $sort, string|null $order = null): void | ||
| 39 | { | ||
| 40 | $order = ! $order ? 'ASC' : $order; | ||
| 41 | $this->parts[] = $sort . ' ' . $order; | ||
| 42 | } | ||
| 43 | |||
| 44 | /** @psalm-return 0|positive-int */ | ||
| 45 | public function count(): int | ||
| 46 | { | ||
| 47 | return count($this->parts); | ||
| 48 | } | ||
| 49 | |||
| 50 | /** @psalm-return list<string> */ | ||
| 51 | public function getParts(): array | ||
| 52 | { | ||
| 53 | return $this->parts; | ||
| 54 | } | ||
| 55 | |||
| 56 | public function __toString(): string | ||
| 57 | { | ||
| 58 | return $this->preSeparator . implode($this->separator, $this->parts) . $this->postSeparator; | ||
| 59 | } | ||
| 60 | } | ||
