1 | <?php |
||
23 | trait EntityViewMethods |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * Add a warning flash message |
||
28 | * |
||
29 | * @param string $message |
||
30 | * @return self |
||
31 | */ |
||
32 | abstract public function addWarningMessage($message); |
||
33 | |||
34 | /** |
||
35 | * Get missing entity warning message |
||
36 | * |
||
37 | * @param mixed $entityId |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | 2 | protected function getMissingEntityMessage($entityId) |
|
47 | |||
48 | /** |
||
49 | * Redirect callback after missing entity detection |
||
50 | * |
||
51 | * @return $this|\Slick\Mvc\ControllerInterface|static |
||
52 | */ |
||
53 | 2 | protected function redirectFromMissingEntity() |
|
57 | |||
58 | /** |
||
59 | * Handles the request to view an entity |
||
60 | * |
||
61 | * @param int $entityId |
||
62 | * |
||
63 | * @return null|EntityInterface |
||
64 | */ |
||
65 | 4 | public function show($entityId = 0) |
|
81 | |||
82 | /** |
||
83 | * Gets entity with provided primary key |
||
84 | * |
||
85 | * @param mixed $entityId |
||
86 | * |
||
87 | * @return EntityInterface |
||
88 | * |
||
89 | * @throws EntityNotFoundException If no entity was found with |
||
90 | * provided primary key |
||
91 | */ |
||
92 | abstract protected function getEntity($entityId); |
||
93 | |||
94 | /** |
||
95 | * Get entity singular name used on controller actions |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | abstract protected function getEntityNameSingular(); |
||
100 | |||
101 | /** |
||
102 | * Returns the translation for the provided message |
||
103 | * |
||
104 | * @param string $message |
||
105 | * @param string $domain |
||
106 | * @param string $locale |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | abstract public function translate( |
||
113 | } |
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.