|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Setup\Model\ConfigOptionsList; |
| 9 | + |
| 10 | +use Magento\Framework\App\DeploymentConfig; |
| 11 | +use Magento\Framework\Config\Data\ConfigData; |
| 12 | +use Magento\Framework\Config\File\ConfigFilePool; |
| 13 | +use Magento\Framework\Setup\ConfigOptionsListInterface; |
| 14 | +use Magento\Framework\Setup\Option\SelectConfigOption; |
| 15 | + |
| 16 | +/** |
| 17 | + * Deployment configuration options for the folders. |
| 18 | + */ |
| 19 | +class Directory implements ConfigOptionsListInterface |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Input ket for config command. |
| 23 | + */ |
| 24 | + const INPUT_KEY_DOCUMENT_ROOT_IS_PUB = 'document-root-is-pub'; |
| 25 | + |
| 26 | + /** |
| 27 | + * Path in in configuration. |
| 28 | + */ |
| 29 | + const CONFIG_PATH_DOCUMENT_ROOT_IS_PUB = 'directories/document_root_is_pub'; |
| 30 | + |
| 31 | + /** |
| 32 | + * The available configuration values. |
| 33 | + * |
| 34 | + * @var array |
| 35 | + */ |
| 36 | + private $selectOptions = [true, false]; |
| 37 | + |
| 38 | + /** |
| 39 | + * @param array $options |
| 40 | + * @param DeploymentConfig $deploymentConfig |
| 41 | + * @return ConfigData|ConfigData[] |
| 42 | + */ |
| 43 | + public function createConfig(array $options, DeploymentConfig $deploymentConfig) |
| 44 | + { |
| 45 | + $configData = new ConfigData(ConfigFilePool::APP_ENV); |
| 46 | + if (isset($options[self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB])) { |
| 47 | + $configData->set( |
| 48 | + self::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, |
| 49 | + \filter_var($options[self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB], FILTER_VALIDATE_BOOLEAN) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + return $configData; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Return options from Directory configuration. |
| 58 | + * |
| 59 | + * @return \Magento\Framework\Setup\Option\AbstractConfigOption[]|SelectConfigOption[] |
| 60 | + */ |
| 61 | + public function getOptions() |
| 62 | + { |
| 63 | + return [ |
| 64 | + new SelectConfigOption( |
| 65 | + self::INPUT_KEY_DOCUMENT_ROOT_IS_PUB, |
| 66 | + SelectConfigOption::FRONTEND_WIZARD_SELECT, |
| 67 | + $this->selectOptions, |
| 68 | + self::CONFIG_PATH_DOCUMENT_ROOT_IS_PUB, |
| 69 | + 'Flag to show is Pub is on root, can be true or false only', |
| 70 | + false |
| 71 | + ), |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Validate options. |
| 77 | + * |
| 78 | + * @param array $options |
| 79 | + * @param DeploymentConfig $deploymentConfig |
| 80 | + * @return array|string[] |
| 81 | + */ |
| 82 | + public function validate(array $options, DeploymentConfig $deploymentConfig) |
| 83 | + { |
| 84 | + return []; |
| 85 | + } |
| 86 | +} |
0 commit comments