| 1 | <?php |
||
| 9 | trait HasRendererTrait |
||
| 10 | { |
||
| 11 | protected $_isRendered = false; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param boolean $isRendered |
||
| 15 | * @return $this |
||
| 16 | */ |
||
| 17 | 5 | public function setRendered($isRendered) |
|
| 18 | { |
||
| 19 | 5 | $this->_isRendered = (bool)$isRendered; |
|
| 20 | |||
| 21 | 5 | return $this; |
|
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @return bool |
||
| 26 | */ |
||
| 27 | public function isRendered() |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return bool |
||
| 34 | */ |
||
| 35 | public function hasCustomRenderer() |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @return mixed |
||
| 42 | */ |
||
| 43 | 4 | public function render() |
|
| 44 | { |
||
| 45 | 4 | return $this->getRenderer()->render($this); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return mixed |
||
| 50 | */ |
||
| 51 | 4 | public function getRenderer() |
|
| 52 | { |
||
| 53 | 4 | return $this->getForm()->getRenderer()->getElementRenderer($this); |
|
|
|
|||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return mixed |
||
| 58 | */ |
||
| 59 | public function renderElement() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return mixed |
||
| 66 | */ |
||
| 67 | public function renderErrors() |
||
| 71 | } |
||
| 72 |
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
Idableprovides a methodequalsIdthat 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.