elisei /
input-masking
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Copyright © O2TI. All rights reserved. |
||
| 4 | * |
||
| 5 | * @author Bruno Elisei <[email protected]> |
||
| 6 | * See COPYING.txt for license details. |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace O2TI\InputMasking\Helper; |
||
| 10 | |||
| 11 | use Magento\Framework\App\Config\ScopeConfigInterface; |
||
| 12 | use Magento\Framework\App\Helper\AbstractHelper; |
||
| 13 | use Magento\Store\Model\ScopeInterface; |
||
| 14 | use Magento\Store\Model\StoreManagerInterface; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class Config - Helper configuration. |
||
| 18 | */ |
||
| 19 | class Config extends AbstractHelper |
||
| 20 | { |
||
| 21 | public const CONFIG_PATH_GENERAL = 'input_masking/general/%s'; |
||
| 22 | |||
| 23 | public const CONFIG_PATH_ADDRESS_INPUT = 'input_masking/general/address/%s/%s'; |
||
| 24 | |||
| 25 | public const CONFIG_PATH_CUSTOMER_INPUT = 'input_masking/general/customer/%s/%s'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var ScopeConfigInterface |
||
| 29 | */ |
||
| 30 | protected $scopeConfig; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var StoreManagerInterface |
||
| 34 | */ |
||
| 35 | protected $storeManagerInterface; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param ScopeConfigInterface $scopeConfig |
||
| 39 | * @param StoreManagerInterface $storeManagerInterface |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 42 | ScopeConfigInterface $scopeConfig, |
||
| 43 | StoreManagerInterface $storeManagerInterface |
||
| 44 | ) { |
||
| 45 | $this->scopeConfig = $scopeConfig; |
||
| 46 | $this->storeManagerInterface = $storeManagerInterface; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Get Configs Module. |
||
| 51 | * |
||
| 52 | * @param string $field |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getConfigModule(string $field): ?string |
||
| 57 | { |
||
| 58 | $storeId = $this->storeManagerInterface->getStore()->getId(); |
||
| 59 | $configPath = sprintf(self::CONFIG_PATH_GENERAL, $field); |
||
| 60 | |||
| 61 | return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get Config Address Input. |
||
| 66 | * |
||
| 67 | * @param string $input |
||
| 68 | * @param string $field |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | public function getConfigAddressInput(string $input, string $field): ?string |
||
| 73 | { |
||
| 74 | $storeId = $this->storeManagerInterface->getStore()->getId(); |
||
| 75 | $configPath = sprintf(self::CONFIG_PATH_ADDRESS_INPUT, $input, $field); |
||
| 76 | |||
| 77 | return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Get Config Customer Input. |
||
| 82 | * |
||
| 83 | * @param string $input |
||
| 84 | * @param string $field |
||
| 85 | * |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public function getConfigCustomerInput(string $input, string $field): ?string |
||
| 89 | { |
||
| 90 | $storeId = $this->storeManagerInterface->getStore()->getId(); |
||
| 91 | $configPath = sprintf(self::CONFIG_PATH_CUSTOMER_INPUT, $input, $field); |
||
| 92 | |||
| 93 | return $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Get If is Enabled Module. |
||
| 98 | * |
||
| 99 | * @return bool |
||
| 100 | */ |
||
| 101 | public function isEnabled(): ?bool |
||
| 102 | { |
||
| 103 | return $this->getConfigModule('enabled'); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 104 | } |
||
| 105 | } |
||
| 106 |