vendor/doctrine/orm/src/Query/Expr/OrderBy.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM\Query\Expr;
  4. use Stringable;
  5. use function count;
  6. use function implode;
  7. /**
  8.  * Expression class for building DQL Order By parts.
  9.  *
  10.  * @link    www.doctrine-project.org
  11.  */
  12. class OrderBy implements Stringable
  13. {
  14.     protected string $preSeparator  '';
  15.     protected string $separator     ', ';
  16.     protected string $postSeparator '';
  17.     /** @var string[] */
  18.     protected array $allowedClasses = [];
  19.     /** @psalm-var list<string> */
  20.     protected array $parts = [];
  21.     public function __construct(
  22.         string|null $sort null,
  23.         string|null $order null,
  24.     ) {
  25.         if ($sort) {
  26.             $this->add($sort$order);
  27.         }
  28.     }
  29.     public function add(string $sortstring|null $order null): void
  30.     {
  31.         $order         = ! $order 'ASC' $order;
  32.         $this->parts[] = $sort ' ' $order;
  33.     }
  34.     /** @psalm-return 0|positive-int */
  35.     public function count(): int
  36.     {
  37.         return count($this->parts);
  38.     }
  39.     /** @psalm-return list<string> */
  40.     public function getParts(): array
  41.     {
  42.         return $this->parts;
  43.     }
  44.     public function __toString(): string
  45.     {
  46.         return $this->preSeparator implode($this->separator$this->parts) . $this->postSeparator;
  47.     }
  48. }