1 | <?php |
||
18 | abstract class AbstractSchema implements RelationInterface |
||
19 | { |
||
20 | /** |
||
21 | * Relation type to be stored in packed schema. |
||
22 | */ |
||
23 | const RELATION_TYPE = null; |
||
24 | |||
25 | /** |
||
26 | * Options to be packed in schema (not all options are required in runtime). |
||
27 | */ |
||
28 | const PACK_OPTIONS = []; |
||
29 | |||
30 | /** |
||
31 | * Most of relations provides ability to specify many different configuration options, such |
||
32 | * as key names, pivot table schemas, foreign key request, ability to be nullabe and etc. |
||
33 | * |
||
34 | * To simple schema definition in real projects we can fill some of this values automatically |
||
35 | * based on some "environment" values such as parent/outer record table, role name, primary key |
||
36 | * and etc. |
||
37 | * |
||
38 | * Example: |
||
39 | * Record::INNER_KEY => '{outer:role}_{outer:primaryKey}' |
||
40 | * |
||
41 | * Result: |
||
42 | * Outer Record is User with primary key "id" => "user_id" |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | const OPTIONS_TEMPLATE = []; |
||
47 | |||
48 | /** |
||
49 | * @var RelationDefinition |
||
50 | */ |
||
51 | protected $definition; |
||
52 | |||
53 | /** |
||
54 | * Provides ability to define missing relation options based on template. |
||
55 | * |
||
56 | * @see self::OPTIONS_TEMPLATE |
||
57 | * @var RelationOptions |
||
58 | */ |
||
59 | protected $options; |
||
60 | |||
61 | /** |
||
62 | * @param RelationDefinition $definition |
||
63 | */ |
||
64 | public function __construct(RelationDefinition $definition) |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | public function getDefinition(): RelationDefinition |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function packRelation(): array |
||
88 | |||
89 | /** |
||
90 | * Define relation configuration option. |
||
91 | * |
||
92 | * @param string $option |
||
93 | * |
||
94 | * @return mixed |
||
95 | * |
||
96 | * @throws OptionsException |
||
97 | */ |
||
98 | protected function option(string $option) |
||
102 | } |