|
| 1 | +# V4 to V5 |
| 2 | + |
| 3 | +## `Repository->put()` |
| 4 | + |
| 5 | +=== "Before" |
| 6 | + ```php |
| 7 | + $repository->put($aggregate); |
| 8 | + ``` |
| 9 | + |
| 10 | +=== "After" |
| 11 | + ```php |
| 12 | + $repository->put($aggregate)->unwrap(); |
| 13 | + ``` |
| 14 | + |
| 15 | +## `Repository->remove()` |
| 16 | + |
| 17 | +=== "Before" |
| 18 | + ```php |
| 19 | + $repository->remove($idOrSpecification); |
| 20 | + ``` |
| 21 | + |
| 22 | +=== "After" |
| 23 | + ```php |
| 24 | + $repository->remove($idOrSpecification)->unwrap(); |
| 25 | + ``` |
| 26 | + |
| 27 | +## `Repository->effect()` |
| 28 | + |
| 29 | +=== "Before" |
| 30 | + ```php |
| 31 | + $repository->effect($effect); |
| 32 | + ``` |
| 33 | + |
| 34 | +=== "After" |
| 35 | + ```php |
| 36 | + $repository->effect($effect)->unwrap(); |
| 37 | + ``` |
| 38 | + |
| 39 | +## Transactions |
| 40 | + |
| 41 | +=== "Before" |
| 42 | + ```php |
| 43 | + use Innmind\Immutable\Either; |
| 44 | + |
| 45 | + $manager |
| 46 | + ->transactional(static function() { |
| 47 | + if (/* some condition */) { |
| 48 | + return Either::right(new SomeValue); |
| 49 | + } |
| 50 | + |
| 51 | + return Either::left(new SomeError); |
| 52 | + }) |
| 53 | + ->match( |
| 54 | + static fn(SomeValue $value) => domSomething($value), |
| 55 | + static fn(SomeError $value) => domSomething($value), |
| 56 | + ); |
| 57 | + ``` |
| 58 | + |
| 59 | +=== "After" |
| 60 | + ```php hl_lines="14-15" |
| 61 | + use Formal\ORM\Adapter\Transaction\Failure |
| 62 | + use Innmind\Immutable\Either; |
| 63 | + |
| 64 | + $manager |
| 65 | + ->transactional(static function() { |
| 66 | + if (/* some condition */) { |
| 67 | + return Either::right(new SomeValue); |
| 68 | + } |
| 69 | + |
| 70 | + return Either::left(new SomeError); |
| 71 | + }) |
| 72 | + ->match( |
| 73 | + static fn(SomeValue $value) => domSomething($value), |
| 74 | + static fn(SomeError|Failure $value) => match (true) { |
| 75 | + $value instanceof Failure => throw $value->unwrap(), |
| 76 | + default => domSomething($value), |
| 77 | + }, |
| 78 | + ); |
| 79 | + ``` |
| 80 | + |
| 81 | + Errors happening during the transaction commit/rollback are now returned on the left side instead of thrown to let you decide if you prefer using exceptions or a monadic style. |
0 commit comments