Skip to content

Commit

Permalink
Merge pull request #23 from formal-php/id-shortcut
Browse files Browse the repository at this point in the history
Add `Id::for()` shortcut
  • Loading branch information
Baptouuuu authored Jun 2, 2024
2 parents 8259227 + 30d0c61 commit 6e87270
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- `Formal\ORM\Id::for()`

## 2.0.2 - 2024-05-29

### Changed
Expand Down
6 changes: 3 additions & 3 deletions proofs/id.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ static function($assert) {
Set\Uuid::any(),
),
static function($assert, $a, $b) {
$idA = Id::of(stdClass::class, $a);
$idABis = Id::of(stdClass::class, $a);
$idB = Id::of(stdClass::class, $b);
$idA = Id::for(stdClass::class)($a);
$idABis = Id::for(stdClass::class)($a);
$idB = Id::for(stdClass::class)($b);

$assert->true($idA->equals($idA));
$assert->true($idA->equals($idABis));
Expand Down
13 changes: 13 additions & 0 deletions src/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public static function of(string $class, string $value): self
return new self($class, $value);
}

/**
* @template A of object
* @psalm-pure
*
* @param class-string<A> $class
*
* @return pure-callable(non-empty-string): self<A>
*/
public static function for(string $class): callable
{
return static fn(string $value) => self::of($class, $value);
}

/**
* @param self<T> $other
*/
Expand Down

0 comments on commit 6e87270

Please sign in to comment.