1 | <?php |
||
7 | class Meta |
||
8 | { |
||
9 | /** |
||
10 | * Meta type |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $type; |
||
14 | |||
15 | /** |
||
16 | * The object ID this metadata is for |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $object_id; |
||
20 | |||
21 | /** |
||
22 | * The key the metadata is for |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $key; |
||
26 | |||
27 | /** |
||
28 | * Meta Constructor. |
||
29 | * |
||
30 | * @param string $type Meta type |
||
31 | * @param int|string $object_id ID of the object metadata is for |
||
32 | * @param string $key Meta key |
||
33 | */ |
||
34 | public function __construct($type, $object_id, $key) |
||
40 | |||
41 | /** |
||
42 | * Get the single meta data. |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function get() |
||
50 | |||
51 | /** |
||
52 | * Get all meta data as a Collection. |
||
53 | * |
||
54 | * @return Collection |
||
55 | */ |
||
56 | public function collect() |
||
60 | |||
61 | /** |
||
62 | * Get all meta data as an array. |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function all() |
||
70 | |||
71 | /** |
||
72 | * Set the new value. |
||
73 | * |
||
74 | * @param mixed $value |
||
75 | * @param string $prev_value |
||
76 | * |
||
77 | * @return $this |
||
78 | */ |
||
79 | public function set($value, $prev_value = '') |
||
85 | |||
86 | /** |
||
87 | * Replace a single value. |
||
88 | * |
||
89 | * @param mixed $old Previous value to update |
||
90 | * @param mixed $new New value to set the previous value to |
||
91 | * |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function replace($old, $new) |
||
98 | |||
99 | /** |
||
100 | * Add metadata for the specified object. |
||
101 | * |
||
102 | * @param mixed $value The value to add |
||
103 | * @param bool $unique Whether the specified metadata key should be unique |
||
104 | * for the object. If true, and the object already has |
||
105 | * a value for the specified metadata key, no change will be made. |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function add($value, $unique = false) |
||
115 | |||
116 | /** |
||
117 | * Delete the meta data |
||
118 | * |
||
119 | * Deletes all meta data for the key, if provided, optionally filtered by |
||
120 | * a previous value. |
||
121 | * If no key was provided, all meta data for the object is deleted. |
||
122 | * |
||
123 | * @param string $value The old value to delete. |
||
124 | * This is only necessary when deleting a specific value |
||
125 | * from an object which has multiple values for the key. |
||
126 | * |
||
127 | * @return $this |
||
128 | */ |
||
129 | public function delete($value = '') |
||
135 | |||
136 | /** |
||
137 | * Determine if a meta key is set for a given object. |
||
138 | * |
||
139 | * @return bool True of the key is set, false if not. |
||
140 | */ |
||
141 | public function exists() |
||
145 | |||
146 | /** |
||
147 | * Get the meta data as a string. |
||
148 | * |
||
149 | * @return string The meta value |
||
150 | */ |
||
151 | public function __toString() |
||
155 | } |
||
156 |