GenericSchemaLocator.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Config;
  7. use Magento\Framework\Module\Dir;
  8. use Magento\Framework\Module\Dir\Reader as ModuleDirReader;
  9. /**
  10. * Class GenericSchemaLocator
  11. */
  12. class GenericSchemaLocator implements SchemaLocatorInterface
  13. {
  14. /**
  15. * @var ModuleDirReader
  16. */
  17. private $moduleDirReader;
  18. /**
  19. * @var string
  20. */
  21. private $moduleName;
  22. /**
  23. * @var string
  24. */
  25. private $perFileSchema;
  26. /**
  27. * @var string|null
  28. */
  29. private $schema;
  30. /**
  31. * @param ModuleDirReader $reader
  32. * @param string $moduleName
  33. * @param string $schema
  34. * @param string|null $perFileSchema
  35. */
  36. public function __construct(ModuleDirReader $reader, $moduleName, $schema, $perFileSchema = null)
  37. {
  38. $this->moduleDirReader = $reader;
  39. $this->moduleName = $moduleName;
  40. $this->schema = $schema;
  41. $this->perFileSchema = $perFileSchema;
  42. }
  43. /**
  44. * Get path to merged config schema
  45. *
  46. * @return string|null
  47. */
  48. public function getSchema()
  49. {
  50. return $this->moduleDirReader->getModuleDir(Dir::MODULE_ETC_DIR, $this->moduleName) . '/' . $this->schema;
  51. }
  52. /**
  53. * Get path to per file validation schema
  54. *
  55. * @return string|null
  56. */
  57. public function getPerFileSchema()
  58. {
  59. if ($this->perFileSchema !== null) {
  60. return $this->moduleDirReader->getModuleDir(Dir::MODULE_ETC_DIR, $this->moduleName)
  61. . '/' . $this->perFileSchema;
  62. }
  63. }
  64. }