IntegrationConfig.php 2.3 KB

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