| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace ModulesGarden\Servers\ZimbraEmail\Core\DependencyInjection;
- use ModulesGarden\Servers\ZimbraEmail\Core\ModuleConstants;
- use ModulesGarden\Servers\ZimbraEmail\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')
- ];
- }
- }
|