|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\System\StateMachine; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Feature; |
|
6
|
|
|
use Shopware\Core\Framework\HttpException; |
|
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
8
|
|
|
use Shopware\Core\System\StateMachine\Exception\IllegalTransitionException; |
|
9
|
|
|
use Shopware\Core\System\StateMachine\Exception\StateMachineInvalidEntityIdException; |
|
10
|
|
|
use Shopware\Core\System\StateMachine\Exception\StateMachineInvalidStateFieldException; |
|
11
|
|
|
use Shopware\Core\System\StateMachine\Exception\StateMachineNotFoundException; |
|
12
|
|
|
use Shopware\Core\System\StateMachine\Exception\StateMachineStateNotFoundException; |
|
13
|
|
|
use Shopware\Core\System\StateMachine\Exception\StateMachineWithoutInitialStateException; |
|
14
|
|
|
use Shopware\Core\System\StateMachine\Exception\UnnecessaryTransitionException; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
16
|
|
|
|
|
17
|
|
|
#[Package('checkout')] |
|
18
|
|
|
class StateMachineException extends HttpException |
|
19
|
|
|
{ |
|
20
|
|
|
public const ILLEGAL_STATE_TRANSITION = 'SYSTEM__ILLEGAL_STATE_TRANSITION'; |
|
21
|
|
|
public const STATE_MACHINE_INVALID_ENTITY_ID = 'SYSTEM__STATE_MACHINE_INVALID_ENTITY_ID'; |
|
22
|
|
|
public const STATE_MACHINE_INVALID_STATE_FIELD = 'SYSTEM__STATE_MACHINE_INVALID_STATE_FIELD'; |
|
23
|
|
|
public const STATE_MACHINE_NOT_FOUND = 'SYSTEM__STATE_MACHINE_NOT_FOUND'; |
|
24
|
|
|
public const STATE_MACHINE_STATE_NOT_FOUND = 'SYSTEM__STATE_MACHINE_STATE_NOT_FOUND'; |
|
25
|
|
|
public const STATE_MACHINE_WITHOUT_INITIAL_STATE = 'SYSTEM__STATE_MACHINE_WITHOUT_INITIAL_STATE'; |
|
26
|
|
|
public const UNNECESSARY_TRANSITION = 'SYSTEM__UNNECESSARY_TRANSITION'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param array<mixed> $possibleTransitions |
|
30
|
|
|
*/ |
|
31
|
|
|
public static function illegalStateTransition(string $currentState, string $transition, array $possibleTransitions): IllegalTransitionException |
|
32
|
|
|
{ |
|
33
|
|
|
return new IllegalTransitionException($currentState, $transition, $possibleTransitions); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function stateMachineInvalidEntityId(string $entityName, string $entityId): self |
|
37
|
|
|
{ |
|
38
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
39
|
|
|
return new StateMachineInvalidEntityIdException($entityName, $entityId); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return new self( |
|
43
|
|
|
Response::HTTP_BAD_REQUEST, |
|
44
|
|
|
self::STATE_MACHINE_INVALID_ENTITY_ID, |
|
45
|
|
|
'Unable to read entity "{{ entityName }}" with id "{{ entityId }}".', |
|
46
|
|
|
[ |
|
47
|
|
|
'entityName' => $entityName, |
|
48
|
|
|
'entityId' => $entityId, |
|
49
|
|
|
] |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public static function stateMachineInvalidStateField(string $fieldName): self |
|
54
|
|
|
{ |
|
55
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
56
|
|
|
return new StateMachineInvalidStateFieldException($fieldName); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return new self( |
|
60
|
|
|
Response::HTTP_BAD_REQUEST, |
|
61
|
|
|
self::STATE_MACHINE_INVALID_STATE_FIELD, |
|
62
|
|
|
'Field "{{ fieldName }}" does not exists or isn\'t of type StateMachineStateField.', |
|
63
|
|
|
[ |
|
64
|
|
|
'fieldName' => $fieldName, |
|
65
|
|
|
] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function stateMachineNotFound(string $stateMachineName): self |
|
70
|
|
|
{ |
|
71
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
72
|
|
|
return new StateMachineNotFoundException($stateMachineName); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return new self( |
|
76
|
|
|
Response::HTTP_BAD_REQUEST, |
|
77
|
|
|
self::STATE_MACHINE_NOT_FOUND, |
|
78
|
|
|
'The StateMachine named "{{ name }}" was not found.', |
|
79
|
|
|
['name' => $stateMachineName] |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function stateMachineStateNotFound(string $stateMachineName, string $technicalPlaceName): self |
|
84
|
|
|
{ |
|
85
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
86
|
|
|
return new StateMachineStateNotFoundException($stateMachineName, $technicalPlaceName); |
|
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return new self( |
|
90
|
|
|
Response::HTTP_BAD_REQUEST, |
|
91
|
|
|
self::STATE_MACHINE_STATE_NOT_FOUND, |
|
92
|
|
|
'The place "{{ place }}" for state machine named "{{ stateMachine }}" was not found.', |
|
93
|
|
|
[ |
|
94
|
|
|
'place' => $technicalPlaceName, |
|
95
|
|
|
'stateMachine' => $stateMachineName, |
|
96
|
|
|
] |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public static function stateMachineWithoutInitialState(string $stateMachineName): self |
|
101
|
|
|
{ |
|
102
|
|
|
if (!Feature::isActive('v6.6.0.0')) { |
|
103
|
|
|
return new StateMachineWithoutInitialStateException($stateMachineName); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return new self( |
|
107
|
|
|
Response::HTTP_BAD_REQUEST, |
|
108
|
|
|
self::STATE_MACHINE_WITHOUT_INITIAL_STATE, |
|
109
|
|
|
'The StateMachine named "{{ name }}" has no initial state.', |
|
110
|
|
|
['name' => $stateMachineName] |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public static function unnecessaryTransition(string $transition): UnnecessaryTransitionException |
|
115
|
|
|
{ |
|
116
|
|
|
return new UnnecessaryTransitionException($transition); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|