Services.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\DependencyInjection;
  3. use ThurData\Servers\KerioEmail\Core\ModuleConstants;
  4. use ThurData\Servers\KerioEmail\Core\FileReader\Reader;
  5. /**
  6. * Load all services from yml file and mark them as shared in DI container
  7. * @autor ThurData <info@thrudata.ch>
  8. * @package ThurData\DomainOrdersExtended\Core\Services
  9. */
  10. class Services
  11. {
  12. /**
  13. * Services constructor.
  14. */
  15. public function __construct()
  16. {
  17. $this->load();
  18. }
  19. /**
  20. * Load all needed servies to DI container
  21. */
  22. protected function load()
  23. {
  24. foreach($this->getFilesList() as $file)
  25. {
  26. $servicesList = Reader::read($file)->get();;
  27. if(!is_array($servicesList) || empty($servicesList))
  28. {
  29. continue;
  30. }
  31. $this->registerServices($servicesList);
  32. }
  33. }
  34. /**
  35. * Register all services in DI container
  36. * @param $servicesList
  37. */
  38. protected function registerServices($servicesList)
  39. {
  40. foreach($servicesList as $service)
  41. {
  42. Container::getInstance()->singleton($service);
  43. }
  44. }
  45. /**
  46. * Get file list with servies configuration
  47. * @return array
  48. */
  49. protected function getFilesList()
  50. {
  51. return [
  52. ModuleConstants::getFullPath('app', 'Config', 'di', 'services.yml'),
  53. ModuleConstants::getFullPath('core', 'Config', 'di', 'services.yml')
  54. ];
  55. }
  56. }