| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace ModulesGarden\ProxmoxAddon\Core\DependencyInjection;
- use ModulesGarden\ProxmoxAddon\Core\ModuleConstants;
- use ModulesGarden\ProxmoxAddon\Core\FileReader\Reader;
- /**
- * Load all services from yml file and mark them as shared in DI container
- * @author Mariusz Miodowski <mariusz@modulesgarden.com>
- * @package ModulesGarden\DomainOrdersExtended\Core\Services
- */
- class Services
- {
- /**
- * Services constructor.
- */
- public function __construct()
- {
- $this->load();
- }
- /**
- * Load all needed servies to DI container
- */
- protected function load()
- {
- foreach ($this->getFilesList() as $file)
- {
- $servicesList = Reader::read($file)->get();
- ;
- if (!is_array($servicesList) || empty($servicesList))
- {
- continue;
- }
- $this->registerServices($servicesList);
- }
- }
- /**
- * Register all services in DI container
- * @param $servicesList
- */
- protected function registerServices($servicesList)
- {
- foreach ($servicesList as $service)
- {
- Container::getInstance()->singleton($service);
- }
- }
- /**
- * Get file list with servies configuration
- * @return array
- */
- protected function getFilesList()
- {
- return [
- ModuleConstants::getFullPath('app', 'Config', 'di', 'services.yml'),
- ModuleConstants::getFullPath('core', 'Config', 'di', 'services.yml')
- ];
- }
- }
|