1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Stratadox\TableLoader\Builder; |
5
|
|
|
|
6
|
|
|
use function sprintf as withMessage; |
7
|
|
|
use UnexpectedValueException as UnexpectedValue; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Notifies the client code that the table mapping could not be produced. |
11
|
|
|
* |
12
|
|
|
* @author Stratadox |
13
|
|
|
*/ |
14
|
|
|
final class CannotMakeMapping extends UnexpectedValue implements CannotMakeTableMapping |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Produces an exception for when a relationship cannot be wired together |
18
|
|
|
* because the identity columns for the related label are unknown to the |
19
|
|
|
* builder. |
20
|
|
|
* |
21
|
|
|
* This can happen when the object mapping is not informed about which |
22
|
|
|
* columns for a related object. By default, the builder for the Joined (1) |
23
|
|
|
* table loader will automatically set the `identifying`(2) columns. When |
24
|
|
|
* not using the builder, the object mapping definitions(3) need to be given |
25
|
|
|
* this information manually. |
26
|
|
|
* |
27
|
|
|
* (1) @see Joined |
28
|
|
|
* (2) @see DefinesObjectMapping::identifying |
29
|
|
|
* (3) @see DefinesObjectMapping |
30
|
|
|
* |
31
|
|
|
* @param string $theirLabel |
32
|
|
|
* @param string $ourLabel |
33
|
|
|
* @return CannotMakeTableMapping |
34
|
|
|
*/ |
35
|
|
|
public static function missingTheIdentityColumns( |
36
|
|
|
string $theirLabel, |
37
|
|
|
string $ourLabel |
38
|
|
|
): CannotMakeTableMapping { |
39
|
|
|
return new CannotMakeMapping(withMessage( |
40
|
|
|
'Cannot make a mapping for the `%s` objects: ' . |
41
|
|
|
'Cannot resolve the identifying columns for the `%s` relation.', |
42
|
|
|
$ourLabel, |
43
|
|
|
$theirLabel |
44
|
|
|
)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Produces an exception for when a concrete class decision cannot be |
49
|
|
|
* produced due to a missing label. |
50
|
|
|
* |
51
|
|
|
* This can happen when the trigger(1) is not informed about the label it's |
52
|
|
|
* attached to. By default, the label is assigned automatically(2). |
53
|
|
|
* |
54
|
|
|
* (1) @see InCase |
55
|
|
|
* (2) @see Decide::prepareChoices |
56
|
|
|
* |
57
|
|
|
* @param string $choiceTrigger |
58
|
|
|
* @return CannotMakeTableMapping |
59
|
|
|
*/ |
60
|
|
|
public static function missingTheLabelFor( |
61
|
|
|
string $choiceTrigger |
62
|
|
|
): CannotMakeTableMapping { |
63
|
|
|
return new CannotMakeMapping(withMessage( |
64
|
|
|
'Cannot make a mapping for the `%s` objects: ' . |
65
|
|
|
'The label for the source relation was not provided.', |
66
|
|
|
$choiceTrigger |
67
|
|
|
)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|