Reader.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\Paypal\Model\Config\Rules;
  7. use Magento\Framework\Config\FileResolverInterface;
  8. use Magento\Framework\Config\SchemaLocatorInterface;
  9. use Magento\Framework\Config\ValidationStateInterface;
  10. use Magento\Framework\DataObject;
  11. use Magento\Framework\Config\Reader\Filesystem;
  12. use Magento\Paypal\Helper\Backend;
  13. /**
  14. * Class Reader
  15. */
  16. class Reader extends Filesystem
  17. {
  18. /**
  19. * List of identifier attributes for merging
  20. *
  21. * @var array
  22. */
  23. protected $_idAttributes = [
  24. '/rules/payment' => 'id',
  25. '/rules/payment(/relation)+' => 'target'
  26. ];
  27. /**
  28. * Constructor
  29. *
  30. * @param FileResolverInterface $fileResolver
  31. * @param Converter $converter
  32. * @param SchemaLocatorInterface $schemaLocator
  33. * @param ValidationStateInterface $validationState
  34. * @param Backend $helper
  35. * @param string $fileName
  36. * @param array $idAttributes
  37. * @param string $domDocumentClass
  38. * @param string $defaultScope
  39. */
  40. public function __construct(
  41. FileResolverInterface $fileResolver,
  42. Converter $converter,
  43. SchemaLocatorInterface $schemaLocator,
  44. ValidationStateInterface $validationState,
  45. Backend $helper,
  46. $fileName = 'adminhtml/rules/payment_{country}.xml',
  47. $idAttributes = [],
  48. $domDocumentClass = \Magento\Framework\Config\Dom::class,
  49. $defaultScope = 'primary'
  50. ) {
  51. $fileName = str_replace('{country}', strtolower($helper->getConfigurationCountryCode()), $fileName);
  52. parent::__construct(
  53. $fileResolver,
  54. $converter,
  55. $schemaLocator,
  56. $validationState,
  57. $fileName,
  58. $idAttributes,
  59. $domDocumentClass,
  60. $defaultScope
  61. );
  62. }
  63. /**
  64. * Load configuration scope
  65. *
  66. * @param string|null $scope
  67. * @return array
  68. */
  69. public function read($scope = null)
  70. {
  71. $scope = $scope ?: $this->_defaultScope;
  72. $fileList = $this->_fileResolver->get($this->_fileName, $scope);
  73. if (!count($fileList)) {
  74. return $this->_readFiles($this->_fileResolver->get('adminhtml/rules/payment_other.xml', $scope));
  75. }
  76. return $this->_readFiles($fileList);
  77. }
  78. }