1 | <?php |
||
13 | trait AttributesTrait |
||
14 | { |
||
15 | /** |
||
16 | * All attribute fields assigned to this metadata object. |
||
17 | * An attribute is a "standard" field, such as a string, integer, array, etc. |
||
18 | * |
||
19 | * @var AttributeMetadata[] |
||
20 | */ |
||
21 | public $attributes = []; |
||
22 | |||
23 | /** |
||
24 | * Adds an attribute field. |
||
25 | * |
||
26 | * @param AttributeMetadata $attribute |
||
27 | * @return self |
||
28 | */ |
||
29 | public function addAttribute(AttributeMetadata $attribute) |
||
36 | |||
37 | /** |
||
38 | * Determines if an attribute supports autocomplete functionality. |
||
39 | * |
||
40 | * @param string $key The attribute key. |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function attrSupportsAutocomplete($key) |
||
47 | |||
48 | /** |
||
49 | * Gets an attribute field. |
||
50 | * Returns null if the attribute does not exist. |
||
51 | * |
||
52 | * @param string $key |
||
53 | * @return AttributeMetadata|null |
||
54 | */ |
||
55 | public function getAttribute($key) |
||
62 | |||
63 | /** |
||
64 | * Gets all attribute fields. |
||
65 | * |
||
66 | * @return AttributeMetadata[] |
||
67 | */ |
||
68 | public function getAttributes() |
||
72 | |||
73 | /** |
||
74 | * Gets all properties that are flagged for autocomplete in search. |
||
75 | * |
||
76 | * @return AttributeMetadata[] |
||
77 | */ |
||
78 | public function getAutocompleteAttributes() |
||
94 | |||
95 | /** |
||
96 | * Determines if an attribute field exists. |
||
97 | * |
||
98 | * @param string $key |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function hasAttribute($key) |
||
105 | |||
106 | /** |
||
107 | * Determines any attribute fields exist. |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function hasAttributes() |
||
115 | |||
116 | /** |
||
117 | * Validates that the attribute can be added. |
||
118 | * |
||
119 | * @param AttributeMetadata $attribute |
||
120 | * @return self |
||
121 | * @throws MetadataException |
||
122 | */ |
||
123 | abstract protected function validateAttribute(AttributeMetadata $attribute); |
||
124 | } |
||
125 |