1 | <?php |
||
40 | class EnumMappingBehavior extends base\Behavior |
||
41 | { |
||
42 | public const EVENT_TO_ENUMS = 'toEnums'; |
||
43 | public const EVENT_TO_VALUES = 'toValues'; |
||
44 | |||
45 | /** |
||
46 | * Key used for EnumMappingBehavior class, value is array of attributes that must be converted into this enum |
||
47 | * |
||
48 | * ```php |
||
49 | * [ |
||
50 | * 'attribute1' => FirstYourEnum::class, |
||
51 | * 'attribute2' => SecondYourEnum::class, |
||
52 | * ] |
||
53 | * ``` |
||
54 | * |
||
55 | * @var array |
||
56 | * @since 2.0 |
||
57 | */ |
||
58 | public $map; |
||
59 | |||
60 | /** |
||
61 | * In some cases database enum type can work only with string, so this parameter help behaviour to cast variable to |
||
62 | * needs type |
||
63 | * |
||
64 | * ```php |
||
65 | * [ |
||
66 | * 'attribute1' => 'integer', |
||
67 | * 'attribute2' => 'float', |
||
68 | * ] |
||
69 | * ``` |
||
70 | * |
||
71 | * @var array |
||
72 | * @since 1.1 |
||
73 | */ |
||
74 | public $attributesType = []; |
||
75 | |||
76 | /** |
||
77 | * If you want use keys for mapping just add related attribute to this property |
||
78 | * |
||
79 | * ```php |
||
80 | * [ |
||
81 | * 'attribute1', // values for this attribute will be as key in enum |
||
82 | * ] |
||
83 | * ``` |
||
84 | * |
||
85 | * @var array |
||
86 | * @since 2.2 |
||
87 | */ |
||
88 | public $useKeyFor = []; |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function events(): array |
||
105 | |||
106 | /** |
||
107 | * @throws base\InvalidConfigException |
||
108 | */ |
||
109 | public function toValues(): void |
||
124 | |||
125 | /** |
||
126 | * @throws base\InvalidConfigException |
||
127 | * @throws \UnexpectedValueException |
||
128 | */ |
||
129 | public function toEnums(): void |
||
144 | |||
145 | /** |
||
146 | * @param mixed $variable |
||
147 | * @param string $attribute |
||
148 | */ |
||
149 | protected function castTypeIfExist(&$variable, string $attribute): void |
||
155 | |||
156 | /** |
||
157 | * @throws base\InvalidConfigException |
||
158 | */ |
||
159 | protected function validateAttributes(): void |
||
167 | |||
168 | protected function isUseKey(string $attribute): bool |
||
172 | } |
||
173 |