1 | <?php |
||
7 | trait HasUrlTrait |
||
8 | { |
||
9 | /** |
||
10 | * Temporary internal variable for updated URI. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $_uri = false; |
||
15 | |||
16 | /** |
||
17 | * Url object representing the URL which points to this resource. |
||
18 | * |
||
19 | * @return Illuminate\Database\Eloquent\Relations\MorphOne |
||
20 | */ |
||
21 | public function url() |
||
25 | |||
26 | /** |
||
27 | * Overrides Eloquent Model's default attribute getting and gets |
||
28 | * the currently set URI. |
||
29 | * |
||
30 | * @return string|null URI |
||
31 | */ |
||
32 | public function getUriAttribute() |
||
38 | |||
39 | /** |
||
40 | * Overrides Eloquent Model's default attribute setting to store the URI |
||
41 | * in memory only. Override this method if you need to have |
||
42 | * the URI stored as model attribute in the database. |
||
43 | */ |
||
44 | public function setUriAttribute($uri) |
||
48 | |||
49 | /** |
||
50 | * Saves the URI and related URL object for the model. |
||
51 | * |
||
52 | * @return Luminark\Url\Interfaces\HasUrlInterface URL resource object |
||
53 | */ |
||
54 | public function saveUri($uri = null) |
||
90 | |||
91 | /** |
||
92 | * Gets the class for URL object needed to define Eloquent relationship |
||
93 | * between resource and URL models. Override this method if Url class |
||
94 | * is being extended. |
||
95 | * |
||
96 | * @return string Url class |
||
97 | */ |
||
98 | protected function getUrlClass() |
||
102 | |||
103 | /** |
||
104 | * Transforms URI value as required before storing it. |
||
105 | * |
||
106 | * @return string Transformed URI value |
||
107 | */ |
||
108 | protected function prepareUri($uri) |
||
117 | |||
118 | /** |
||
119 | * Validates the URL value and makes sure it is unique. Override this |
||
120 | * method if custom validation is needed. |
||
121 | * |
||
122 | * @return boolean URI validity status |
||
123 | */ |
||
124 | protected function validateUri($uri) |
||
131 | |||
132 | /** |
||
133 | * Modifies the $originalUrl to redirect to $newUrl. |
||
134 | * |
||
135 | * @param Url $originalUrl The URL that will be redirecting |
||
136 | * @param Url $newUrl The URL that will be redirected to |
||
137 | */ |
||
138 | protected function redirectUrl(Url $originalUrl, Url $newUrl) |
||
145 | } |
||
146 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.