| 1 | <?php |
||
| 16 | trait TRenderable |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Name of view template. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $template; |
||
| 24 | |||
| 25 | /** @var bool */ |
||
| 26 | protected $is_rendered = false; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Renders object. |
||
| 30 | * |
||
| 31 | * @return string |
||
| 32 | */ |
||
| 33 | public function render() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Returns name of view template. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public function getTemplate() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Allows to specify view template. |
||
| 54 | * |
||
| 55 | * @param string $template |
||
| 56 | * @return $this |
||
| 57 | */ |
||
| 58 | public function setTemplate($template) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Returns true if object already was rendered. |
||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | public function isRendered() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Renders object when it is treated like a string. |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function __toString() |
||
| 83 | } |
||
| 84 |
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.