Skip to content

Commit

Permalink
feat(Recollection): add getDefaultOrderBy() (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi authored Jun 18, 2024
1 parent 76dbcb5 commit a3e726f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Changelog

## 0.5.0
## 0.1.1

* feat(Recollection): add `getDefaultOrderBy()`

## 0.1.0

* build: initial commit
* fix: rename `matching()` to `withCriteria()` to avoid conflict with PHPStan
`allCollectionsSelectable`
* refactor: split common code to `rekalogika/collections-common`
* feat: new package `rekalogika/collections-orm`
* feat: new package `rekalogika/collections-orm`
18 changes: 16 additions & 2 deletions packages/collections-domain/src/Recollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,21 @@ public function __construct(
private readonly ?int $hardLimit = null,
private readonly ?bool $strict = null,
) {
// handle collection

if (!$collection instanceof Selectable) {
throw new UnexpectedValueException('The wrapped collection must implement the Selectable interface.');
}

$this->collection = $collection;

// handle orderBy

if ($orderBy === null) {
$orderBy = Configuration::$defaultOrderBy;
} elseif (\is_string($orderBy)) {
$orderBy = $this->getDefaultOrderBy();
}

if (\is_string($orderBy)) {
$orderBy = [$orderBy => Order::Ascending];
}

Expand All @@ -93,6 +99,14 @@ public function __construct(
$this->criteria = Criteria::create()->orderBy($this->orderBy);
}

/**
* @return array<string,Order>|string
*/
protected function getDefaultOrderBy(): array|string
{
return Configuration::$defaultOrderBy;
}

/**
* @param null|Collection<TKey,T> $collection
* @param null|array<string,Order>|string $orderBy
Expand Down

0 comments on commit a3e726f

Please sign in to comment.