1 | <?php |
||
16 | trait Metable |
||
17 | { |
||
18 | /** |
||
19 | * Boot the trait. |
||
20 | * |
||
21 | * @return void |
||
22 | */ |
||
23 | public static function bootMetable() |
||
29 | |||
30 | /** |
||
31 | * Get the primary key for the model. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract function getKeyName(); |
||
36 | |||
37 | /** |
||
38 | * Meta item relationship. |
||
39 | * |
||
40 | * @return \BoxedCode\Eloquent\Meta\HasMeta |
||
41 | */ |
||
42 | public function meta() |
||
46 | |||
47 | /** |
||
48 | * Determine if the model or given attribute(s) have been modified. |
||
49 | * |
||
50 | * @param array|string|null $attributes |
||
51 | * @return bool |
||
52 | */ |
||
53 | public function isDirty($attributes = null) |
||
69 | |||
70 | /** |
||
71 | * Get the class name of meta relationship items. |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | public function getMetaItemClassName() |
||
85 | |||
86 | /** |
||
87 | * Get an instance of the meta relationship item class. |
||
88 | * |
||
89 | * @param array $attr |
||
90 | * @return MetaItem |
||
91 | */ |
||
92 | public function getMetaItemInstance($attr = []) |
||
98 | |||
99 | /** |
||
100 | * Get the polymorphic relationship columns. |
||
101 | * |
||
102 | * @param string $name |
||
103 | * @param string $type |
||
104 | * @param string $id |
||
105 | * @return array |
||
106 | */ |
||
107 | abstract function getMorphs($name, $type, $id); |
||
108 | |||
109 | /** |
||
110 | * Define the polymorphic one-to-many relationship with the meta data. |
||
111 | * |
||
112 | * @param string $related |
||
113 | * @param string $name |
||
114 | * @param string $type |
||
115 | * @param string $id |
||
116 | * @param string $localKey |
||
117 | * @return \BoxedCode\Eloquent\Meta\HasMeta |
||
118 | */ |
||
119 | public function hasMeta($related, $name, $type = null, $id = null, $localKey = null) |
||
134 | |||
135 | /** |
||
136 | * Observes the model and saves dirty meta data on save. |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | public static function observeSaveAndCascade() |
||
172 | |||
173 | /** |
||
174 | * Observes the model and deletes meta entries on delete. |
||
175 | * |
||
176 | * @return void |
||
177 | */ |
||
178 | public static function observeDeleteAndCascade() |
||
188 | |||
189 | } |
||
190 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: