| 1 | <?php |
||
| 5 | trait CanPublishConfiguration |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Publish the given configuration file name (without extension) and the given module |
||
| 9 | * @param string $module |
||
| 10 | * @param string $fileName |
||
| 11 | */ |
||
| 12 | public function publishConfig($module, $fileName) |
||
| 13 | { |
||
| 14 | if (app()->environment() === 'testing') { |
||
| 15 | return; |
||
| 16 | } |
||
| 17 | $this->mergeConfigFrom($this->getModuleConfigFilePath($module, $fileName), strtolower("asgard.$module.$fileName")); |
||
|
|
|||
| 18 | $this->publishes([ |
||
| 19 | $this->getModuleConfigFilePath($module, $fileName) => config_path(strtolower("asgard.$module.$fileName")), |
||
| 20 | ], 'config'); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get path of the give file name in the given module |
||
| 25 | * @param string $module |
||
| 26 | * @param string $file |
||
| 27 | * @return string |
||
| 28 | */ |
||
| 29 | private function getModuleConfigFilePath($module, $file) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $module |
||
| 36 | * @return string |
||
| 37 | */ |
||
| 38 | private function getModulePath($module) |
||
| 42 | } |
||
| 43 |
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.