Comment.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config\Export;
  7. use Magento\Config\App\Config\Source\DumpConfigSourceInterface;
  8. use Magento\Config\Model\Config\TypePool;
  9. use Magento\Config\Model\Placeholder\PlaceholderFactory;
  10. use Magento\Config\Model\Placeholder\PlaceholderInterface;
  11. use Magento\Framework\App\Config\CommentInterface;
  12. use Magento\Framework\App\ObjectManager;
  13. /**
  14. * Class Comment. Is used to retrieve comment for config dump file
  15. * @api
  16. * @since 100.1.2
  17. */
  18. class Comment implements CommentInterface
  19. {
  20. /**
  21. * @var PlaceholderInterface
  22. */
  23. private $placeholder;
  24. /**
  25. * @var DumpConfigSourceInterface
  26. */
  27. private $source;
  28. /**
  29. * Checker for config type.
  30. *
  31. * @var TypePool
  32. */
  33. private $typePool;
  34. /**
  35. * @param PlaceholderFactory $placeholderFactory
  36. * @param DumpConfigSourceInterface $source
  37. * @param TypePool|null $typePool The checker for config type
  38. */
  39. public function __construct(
  40. PlaceholderFactory $placeholderFactory,
  41. DumpConfigSourceInterface $source,
  42. TypePool $typePool = null
  43. ) {
  44. $this->placeholder = $placeholderFactory->create(PlaceholderFactory::TYPE_ENVIRONMENT);
  45. $this->source = $source;
  46. $this->typePool = $typePool ?: ObjectManager::getInstance()->get(TypePool::class);
  47. }
  48. /**
  49. * Retrieves comments for the configuration export file.
  50. *
  51. * If there are sensitive fields in the configuration fields,
  52. * a list with descriptions of these fields will be added to the comments.
  53. *
  54. * @return string
  55. * @since 100.1.2
  56. */
  57. public function get()
  58. {
  59. $comments = [];
  60. foreach ($this->source->getExcludedFields() as $path) {
  61. if ($this->typePool->isPresent($path, TypePool::TYPE_SENSITIVE)) {
  62. $comments[] = $this->placeholder->generate($path) . ' for ' . $path;
  63. }
  64. }
  65. if (!empty($comments)) {
  66. $comments = array_merge([
  67. 'Shared configuration was written to config.php and system-specific configuration to env.php.',
  68. 'Shared configuration file (config.php) doesn\'t contain sensitive data for security reasons.',
  69. 'Sensitive data can be stored in the following environment variables:'
  70. ], $comments);
  71. }
  72. return implode(PHP_EOL, $comments);
  73. }
  74. }