| 1 | <?php |
||
| 12 | trait HasViews |
||
| 13 | { |
||
| 14 | /* ----------------------------------------------------------------- |
||
| 15 | | Main Methods |
||
| 16 | | ----------------------------------------------------------------- |
||
| 17 | */ |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Get the base views path. |
||
| 21 | * |
||
| 22 | * @return string |
||
| 23 | */ |
||
| 24 | protected function getViewsPath(): string |
||
| 25 | { |
||
| 26 | return $this->getBasePath().DIRECTORY_SEPARATOR.'views'; |
||
|
|
|||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get the destination views path. |
||
| 31 | * |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | protected function getViewsDestinationPath(): string |
||
| 35 | { |
||
| 36 | return $this->app['config']['view.paths'][0].DIRECTORY_SEPARATOR.'vendor'.DIRECTORY_SEPARATOR.$this->getPackageName(); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Publish the views. |
||
| 41 | * |
||
| 42 | * @param string|null $path |
||
| 43 | */ |
||
| 44 | protected function publishViews(?string $path = null): void |
||
| 45 | { |
||
| 46 | $this->publishes([ |
||
| 47 | $this->getViewsPath() => $path ?: $this->getViewsDestinationPath(), |
||
| 48 | ], $this->getPublishedTags('views')); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Load the views files. |
||
| 53 | */ |
||
| 54 | protected function loadViews(): void |
||
| 58 | } |
||
| 59 |
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.