Config.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model;
  7. use Magento\Framework\App\ObjectManager;
  8. use Magento\Framework\Serialize\SerializerInterface;
  9. use Magento\Integration\Model\Cache\Type;
  10. /**
  11. * Integration Config Model.
  12. *
  13. * This is a parent class for storing information about Integrations.
  14. * @deprecated 100.1.0
  15. */
  16. class Config
  17. {
  18. const CACHE_ID = 'integration';
  19. /**
  20. * @var \Magento\Framework\App\Cache\Type\Config
  21. */
  22. protected $_configCacheType;
  23. /**
  24. * @var \Magento\Integration\Model\Config\Reader
  25. */
  26. protected $_configReader;
  27. /**
  28. * Array of integrations
  29. *
  30. * @var array
  31. */
  32. protected $_integrations;
  33. /**
  34. * @var SerializerInterface
  35. */
  36. private $serializer;
  37. /**
  38. * @param Cache\Type $configCacheType
  39. * @param Config\Reader $configReader
  40. * @param SerializerInterface $serializer
  41. */
  42. public function __construct(
  43. Cache\Type $configCacheType,
  44. Config\Reader $configReader,
  45. SerializerInterface $serializer = null
  46. ) {
  47. $this->_configCacheType = $configCacheType;
  48. $this->_configReader = $configReader;
  49. $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
  50. }
  51. /**
  52. * Return integrations loaded from cache if enabled or from files merged previously
  53. *
  54. * @return array
  55. * @api
  56. */
  57. public function getIntegrations()
  58. {
  59. if (null === $this->_integrations) {
  60. $integrations = $this->_configCacheType->load(self::CACHE_ID);
  61. if ($integrations && is_string($integrations)) {
  62. $this->_integrations = $this->serializer->unserialize($integrations);
  63. } else {
  64. $this->_integrations = $this->_configReader->read();
  65. $this->_configCacheType->save(
  66. $this->serializer->serialize($this->_integrations),
  67. self::CACHE_ID,
  68. [Type::CACHE_TAG]
  69. );
  70. }
  71. }
  72. return $this->_integrations;
  73. }
  74. }