File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed
app/ModelStates/ModelStates Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ See [GitHub releases](https://github.com/mll-lab/laravel-utils/releases).
9
9
10
10
## Unreleased
11
11
12
+ ### Changed
13
+
14
+ - Respect ` Transition::canTransition() ` in ` IsStateManager::$canTransitionTo ` https://github.com/mll-lab/laravel-utils/pull/38
15
+
12
16
## v10.7.0
13
17
14
18
### Added
Original file line number Diff line number Diff line change 3
3
namespace App \ModelStates \ModelStates ;
4
4
5
5
use App \ModelStates \StateManager ;
6
+ use App \ModelStates \Transitions \CustomInvalidTransition ;
6
7
use MLL \LaravelUtils \ModelStates \State ;
7
8
use MLL \LaravelUtils \ModelStates \StateConfig ;
8
9
@@ -13,7 +14,9 @@ public static function config(): StateConfig
13
14
return (new StateConfig ())
14
15
->allowTransition (StateA::class, StateB::class)
15
16
->allowTransition ([StateA::class, StateB::class], StateC::class)
16
- ->allowTransition (StateA::class, StateD::class);
17
+ ->allowTransition (StateA::class, StateD::class)
18
+ ->allowTransition (StateC::class, StateA::class)
19
+ ->allowTransition (StateD::class, StateA::class, CustomInvalidTransition::class);
17
20
}
18
21
19
22
public static function defaultState (): ModelState
Original file line number Diff line number Diff line change @@ -28,8 +28,13 @@ public function getCanTransitionToAttribute(): Collection
28
28
$ state = $ stateable ->state ;
29
29
assert ($ state instanceof State);
30
30
31
+ $ stateMachine = $ stateable ->stateMachine ();
32
+
31
33
return $ stateable ->stateClass ()::config ()
32
- ->possibleNextStates ($ state );
34
+ ->possibleNextStates ($ state )
35
+ ->filter (fn (State $ nextState ): bool => $ stateMachine
36
+ ->instantiateTransitionClass ($ state ::class, $ nextState ::class)
37
+ ->canTransition ());
33
38
}
34
39
35
40
/** @return Collection<array-key, Transition> */
Original file line number Diff line number Diff line change @@ -119,7 +119,19 @@ public function testReturnsListOfPossibleNextStates(): void
119
119
]), $ model ->stateManager ->canTransitionTo );
120
120
121
121
$ model ->state = new StateB ();
122
- self ::assertEquals (new SupportCollection ([StateC::class => new StateC ()]), $ model ->stateManager ->canTransitionTo );
122
+ self ::assertEquals (new SupportCollection ([
123
+ StateC::class => new StateC (),
124
+ ]), $ model ->stateManager ->canTransitionTo );
125
+
126
+ $ model ->state = new StateC ();
127
+ self ::assertEquals (new SupportCollection ([
128
+ StateA::class => new StateA (),
129
+ ]), $ model ->stateManager ->canTransitionTo );
130
+
131
+ $ model ->state = new StateA ();
132
+ $ model ->state = new StateD ();
133
+ self ::assertEquals (new SupportCollection ([
134
+ ]), $ model ->stateManager ->canTransitionTo );
123
135
}
124
136
125
137
public function testReturnsListOfPossibleNextTransitionsForCustomTransition (): void
@@ -206,6 +218,8 @@ public function testGenerateMermaidGraph(): void
206
218
STATE_A-->FOO_BAR;
207
219
STATE_A-->STATE_C;
208
220
STATE_A-->STATE_D;
221
+ STATE_C-->STATE_A;
222
+ STATE_D-->|"CustomInvalidTransition"|STATE_A;
209
223
210
224
linkStyle default interpolate basis;
211
225
MERMAID;
You can’t perform that action at this time.
0 commit comments