1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\ModelStates\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Spatie\ModelStates\State; |
7
|
|
|
use Spatie\ModelStates\HasStates; |
8
|
|
|
use Spatie\ModelStates\Transition; |
9
|
|
|
use Illuminate\Database\Eloquent\Model; |
10
|
|
|
|
11
|
|
|
class InvalidConfig extends Exception |
12
|
|
|
{ |
13
|
|
|
public static function unknownState(string $field, Model $model): InvalidConfig |
14
|
|
|
{ |
15
|
|
|
$modelClass = get_class($model); |
16
|
|
|
|
17
|
|
|
return new self("No state field found for {$modelClass}::{$field}, did you forget to provide a mapping in {$modelClass}::registerStates()?"); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public static function fieldNotFound(string $stateClass, Model $model): InvalidConfig |
21
|
|
|
{ |
22
|
|
|
$modelClass = get_class($model); |
23
|
|
|
|
24
|
|
|
return new self("No state field was found for the state {$stateClass} in {$modelClass}, did you forget to provide a mapping in {$modelClass}::registerStates()?"); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static function fieldDoesNotExtendState(string $field, string $expectedStateClass, string $actualClass): InvalidConfig |
28
|
|
|
{ |
29
|
|
|
return new self("State field `{$field}` expects state to be of type `{$expectedStateClass}`, instead got `{$actualClass}`"); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function doesNotExtendState(string $class): InvalidConfig |
33
|
|
|
{ |
34
|
|
|
return self::doesNotExtendBaseClass($class, State::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function doesNotExtendTransition(string $class): InvalidConfig |
38
|
|
|
{ |
39
|
|
|
return self::doesNotExtendBaseClass($class, Transition::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function doesNotExtendBaseClass(string $class, string $baseClass): InvalidConfig |
43
|
|
|
{ |
44
|
|
|
return new self("Class {$class} does not extend the `{$baseClass}` base class."); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function resolveTransitionNotFound(Model $model): InvalidConfig |
48
|
|
|
{ |
49
|
|
|
$modelClass = get_class($model); |
50
|
|
|
|
51
|
|
|
$trait = HasStates::class; |
52
|
|
|
|
53
|
|
|
return new self("The method `resolveTransition` was not found on model `{$modelClass}`, are you sure it uses the `{$trait} trait?`"); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|