ConfigChangeDetector.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Model\Plugin;
  7. use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
  8. use Magento\Framework\App\FrontControllerInterface;
  9. use Magento\Framework\App\RequestInterface;
  10. use Magento\Framework\Exception\LocalizedException;
  11. /**
  12. * This is plugin for Magento\Framework\App\FrontController class.
  13. *
  14. * Detects that the configuration data from the deployment configuration files has been changed.
  15. * If config data was changed throws LocalizedException because we should stop work of Magento and then import
  16. * config data from shared configuration files into appropriate application sources.
  17. */
  18. class ConfigChangeDetector
  19. {
  20. /**
  21. * Configuration data changes detector.
  22. *
  23. * @var ChangeDetector
  24. */
  25. private $changeDetector;
  26. /**
  27. * @param ChangeDetector $changeDetector configuration data changes detector
  28. */
  29. public function __construct(ChangeDetector $changeDetector)
  30. {
  31. $this->changeDetector = $changeDetector;
  32. }
  33. /**
  34. * Performs detects that config data from deployment configuration files been changed.
  35. *
  36. * @param FrontControllerInterface $subject the interface of frontend controller is wrapped by this plugin
  37. * @param RequestInterface $request the object that contains request params
  38. * @return void
  39. * @throws LocalizedException is thrown if config data from deployment configuration files is not valid
  40. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  41. */
  42. public function beforeDispatch(FrontControllerInterface $subject, RequestInterface $request)
  43. {
  44. if ($this->changeDetector->hasChanges()) {
  45. throw new LocalizedException(
  46. __(
  47. 'The configuration file has changed.'
  48. . ' Run the "app:config:import" or the "setup:upgrade" command to synchronize the configuration.'
  49. )
  50. );
  51. }
  52. }
  53. }