| 1 | <?php |
||
| 15 | trait ConfigsLoaderTrait |
||
| 16 | { |
||
| 17 | |||
| 18 | protected $portConfigsDirectories = [ |
||
| 19 | 'Config/Configs', |
||
| 20 | 'Queue/Configs', |
||
| 21 | ]; |
||
| 22 | |||
| 23 | public function runConfigsAutoLoader() |
||
| 24 | { |
||
| 25 | $this->loadConfigsFromPort(); |
||
| 26 | $this->loadConfigsFromContainers(); |
||
| 27 | } |
||
| 28 | |||
| 29 | private function loadConfigsFromContainers() |
||
| 30 | { |
||
| 31 | foreach ($this->portConfigsDirectories as $portConfigsDirectory) { |
||
| 32 | $this->loadConfigs(base_path('app/Port/') . $portConfigsDirectory); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | private function loadConfigsFromPort() |
||
| 37 | { |
||
| 38 | foreach (PortButler::getContainersNames() as $containerName) { |
||
| 39 | $this->loadConfigs(base_path('app/Containers/' . $containerName . '/Configs')); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | private function loadConfigs($directory) |
||
| 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.