|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan (support@magefan.com). All rights reserved. |
| 4 | + * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). |
| 5 | + * |
| 6 | + * Glory to Ukraine! Glory to the heroes! |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace Magefan\RocketJavaScript\Model; |
| 12 | + |
| 13 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 14 | +use Magento\Store\Model\ScopeInterface; |
| 15 | + |
| 16 | +class Config |
| 17 | +{ |
| 18 | + /** |
| 19 | + * General config |
| 20 | + */ |
| 21 | + public const XML_PATH_EXTENSION_ENABLED = 'mfrocketjavascript/general/enabled'; |
| 22 | + public const XML_PATH_MERGE_FILES = 'mfrocketjavascript/general/merge_files'; |
| 23 | + public const XML_PATH_MINIFY_FILES = 'mfrocketjavascript/general/minify_files'; |
| 24 | + |
| 25 | + /** |
| 26 | + * Deferred JavaScript config |
| 27 | + */ |
| 28 | + public const XML_PATH_DEFERRED_ENABLED = 'mfrocketjavascript/deferred_javascript/enabled'; |
| 29 | + public const XML_PATH_DEFERRED_DISALLOWED_PAGES = 'mfrocketjavascript/deferred_javascript/disallowed_pages_for_deferred_js'; |
| 30 | + public const XML_PATH_DEFERRED_IGNORE_JAVASCRIPT = 'mfrocketjavascript/deferred_javascript/ignore_deferred_javascript_with'; |
| 31 | + |
| 32 | + /** |
| 33 | + * JavaScript Bundling config |
| 34 | + */ |
| 35 | + public const XML_PATH_JAVASCRIPT_BUNDLING_ENABLED = 'mfrocketjavascript/javascript_bundling/enabled'; |
| 36 | + public const XML_PATH_JAVASCRIPT_BUNDLING_OPTIMIZATION_ENABLED = 'mfrocketjavascript/javascript_bundling/enable_js_bundling_optimization'; |
| 37 | + public const XML_PATH_JAVASCRIPT_BUNDLING_INCLUDED_IN_BUNDLING = 'mfrocketjavascript/javascript_bundling/included_in_bundling'; |
| 38 | + |
| 39 | + /** |
| 40 | + * Plumrocket AMP config |
| 41 | + */ |
| 42 | + public const XML_PATH_PLUMROCKET_AMP_ENABLED = 'pramp/general/enabled'; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var ScopeConfigInterface |
| 46 | + */ |
| 47 | + private $scopeConfig; |
| 48 | + |
| 49 | + /** |
| 50 | + * Config constructor. |
| 51 | + * |
| 52 | + * @param ScopeConfigInterface $scopeConfig |
| 53 | + */ |
| 54 | + public function __construct( |
| 55 | + ScopeConfigInterface $scopeConfig |
| 56 | + ) { |
| 57 | + $this->scopeConfig = $scopeConfig; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Retrieve true if module is enabled |
| 62 | + * |
| 63 | + * @param string|null $storeId |
| 64 | + * @return bool |
| 65 | + */ |
| 66 | + public function isEnabled(string $storeId = null): bool |
| 67 | + { |
| 68 | + return (bool)$this->getConfig(self::XML_PATH_EXTENSION_ENABLED, $storeId); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Retrieve true if js files merged |
| 73 | + * |
| 74 | + * @param string|null $storeId |
| 75 | + * @return bool |
| 76 | + */ |
| 77 | + public function isMergeFiles(string $storeId = null): bool |
| 78 | + { |
| 79 | + return (bool)$this->getConfig(self::XML_PATH_MERGE_FILES, $storeId); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Retrieve true if js files minified |
| 84 | + * |
| 85 | + * @param string|null $storeId |
| 86 | + * @return bool |
| 87 | + */ |
| 88 | + public function isMinifyFiles(string $storeId = null): bool |
| 89 | + { |
| 90 | + return (bool)$this->getConfig(self::XML_PATH_MINIFY_FILES, $storeId); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Retrieve true if deferred is enabled |
| 95 | + * |
| 96 | + * @param string|null $storeId |
| 97 | + * @return bool |
| 98 | + */ |
| 99 | + public function isDeferredEnabled(string $storeId = null): bool |
| 100 | + { |
| 101 | + return (bool)$this->getConfig(self::XML_PATH_DEFERRED_ENABLED, $storeId); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Retrieve Disallowed Pages |
| 106 | + * |
| 107 | + * @param string|null $storeId |
| 108 | + * @return string |
| 109 | + */ |
| 110 | + public function getDisallowedPages(string $storeId = null): string |
| 111 | + { |
| 112 | + return (string)$this->getConfig(self::XML_PATH_DEFERRED_DISALLOWED_PAGES, $storeId); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * Retrieve Ignore JS |
| 117 | + * |
| 118 | + * @param string|null $storeId |
| 119 | + * @return string |
| 120 | + */ |
| 121 | + public function getIgnoreJavaScript(string $storeId = null): string |
| 122 | + { |
| 123 | + return (string)$this->getConfig(self::XML_PATH_DEFERRED_IGNORE_JAVASCRIPT, $storeId); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Retrieve true if JS bundling is enabled |
| 128 | + * |
| 129 | + * @param string|null $storeId |
| 130 | + * @return bool |
| 131 | + */ |
| 132 | + public function isBundlingEnabled(string $storeId = null): bool |
| 133 | + { |
| 134 | + return (bool)$this->getConfig(self::XML_PATH_JAVASCRIPT_BUNDLING_ENABLED, $storeId); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * Retrieve true if bundling optimization is enabled |
| 139 | + * |
| 140 | + * @param string|null $storeId |
| 141 | + * @return bool |
| 142 | + */ |
| 143 | + public function isBundlingOptimizationEnabled(string $storeId = null): bool |
| 144 | + { |
| 145 | + return (bool)$this->getConfig(self::XML_PATH_JAVASCRIPT_BUNDLING_OPTIMIZATION_ENABLED, $storeId); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Retrieve included in bundling JS |
| 150 | + * |
| 151 | + * @param string|null $storeId |
| 152 | + * @return string |
| 153 | + */ |
| 154 | + public function getIncludedInBundling(string $storeId = null): string |
| 155 | + { |
| 156 | + return (string)$this->getConfig(self::XML_PATH_JAVASCRIPT_BUNDLING_INCLUDED_IN_BUNDLING, $storeId); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Retrieve true if amp enabled |
| 161 | + * |
| 162 | + * @param string|null $storeId |
| 163 | + * @return bool |
| 164 | + */ |
| 165 | + public function isAmpRequest(string $storeId = null): bool |
| 166 | + { |
| 167 | + return (bool)$this->getConfig(self::XML_PATH_PLUMROCKET_AMP_ENABLED, $storeId); |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Retrieve store config value |
| 172 | + * |
| 173 | + * @param string $path |
| 174 | + * @param string|null $storeId |
| 175 | + * @return mixed |
| 176 | + */ |
| 177 | + public function getConfig(string $path, string $storeId = null) |
| 178 | + { |
| 179 | + return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); |
| 180 | + } |
| 181 | +} |
0 commit comments