UserConfig.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Application for managing user configuration
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Backend\App;
  9. use Magento\Config\Model\Config\Factory;
  10. use Magento\Framework\App\Bootstrap;
  11. use Magento\Framework\App\Console\Response;
  12. use Magento\Framework\AppInterface;
  13. /**
  14. * @api
  15. * @since 100.0.2
  16. */
  17. class UserConfig implements AppInterface
  18. {
  19. /**
  20. * Console response
  21. *
  22. * @var Response
  23. */
  24. private $response;
  25. /**
  26. * Requested changes
  27. *
  28. * @var array
  29. */
  30. private $request;
  31. /**
  32. * Factory for config models
  33. *
  34. * @var Factory
  35. */
  36. private $configFactory;
  37. /**
  38. * Constructor
  39. *
  40. * @param Factory $configFactory
  41. * @param Response $response
  42. * @param array $request
  43. */
  44. public function __construct(
  45. Factory $configFactory,
  46. Response $response,
  47. array $request
  48. ) {
  49. $this->response = $response;
  50. $this->request = $request;
  51. $this->configFactory = $configFactory;
  52. }
  53. /**
  54. * Run application
  55. *
  56. * @return \Magento\Framework\App\ResponseInterface
  57. */
  58. public function launch()
  59. {
  60. $this->response->terminateOnSend(false);
  61. $this->updateUserConfigData();
  62. return $this->response;
  63. }
  64. /**
  65. * Inserts provided user configuration data into database
  66. *
  67. * @return void
  68. */
  69. private function updateUserConfigData()
  70. {
  71. foreach ($this->request as $key => $val) {
  72. $configModel = $this->configFactory->create();
  73. $configModel->setDataByPath($key, $val);
  74. $configModel->save();
  75. }
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function catchException(Bootstrap $bootstrap, \Exception $exception)
  81. {
  82. return false;
  83. }
  84. }