|
| 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 | +use Magento\Framework\View\Asset\Config as MagentoConfig; |
| 16 | + |
| 17 | +class Config |
| 18 | +{ |
| 19 | + /** |
| 20 | + * General config |
| 21 | + */ |
| 22 | + public const XML_PATH_EXTENSION_ENABLED = 'mfrocketjavascript/general/enabled'; |
| 23 | + public const XML_PATH_MERGE_FILES = 'mfrocketjavascript/general/merge_files'; |
| 24 | + public const XML_PATH_MINIFY_FILES = 'mfrocketjavascript/general/minify_files'; |
| 25 | + |
| 26 | + /** |
| 27 | + * Deferred JavaScript config |
| 28 | + */ |
| 29 | + public const XML_PATH_DEFERRED_ENABLED = 'mfrocketjavascript/deferred_javascript/enabled'; |
| 30 | + public const XML_PATH_DEFERRED_DISALLOWED_PAGES = 'mfrocketjavascript/deferred_javascript/disallowed_pages_for_deferred_js'; |
| 31 | + public const XML_PATH_DEFERRED_IGNORE_JAVASCRIPT = 'mfrocketjavascript/deferred_javascript/ignore_deferred_javascript_with'; |
| 32 | + |
| 33 | + /** |
| 34 | + * JavaScript Bundling config |
| 35 | + */ |
| 36 | + public const XML_PATH_JAVASCRIPT_BUNDLING_ENABLED = 'mfrocketjavascript/javascript_bundling/enabled'; |
| 37 | + public const XML_PATH_JAVASCRIPT_BUNDLING_OPTIMIZATION_ENABLED = 'mfrocketjavascript/javascript_bundling/enable_js_bundling_optimization'; |
| 38 | + public const XML_PATH_JAVASCRIPT_BUNDLING_INCLUDED_IN_BUNDLING = 'mfrocketjavascript/javascript_bundling/included_in_bundling'; |
| 39 | + |
| 40 | + /** |
| 41 | + * Plumrocket AMP config |
| 42 | + */ |
| 43 | + public const XML_PATH_PLUMROCKET_AMP_ENABLED = 'pramp/general/enabled'; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var ScopeConfigInterface |
| 47 | + */ |
| 48 | + private $scopeConfig; |
| 49 | + |
| 50 | + /** |
| 51 | + * Config constructor. |
| 52 | + * |
| 53 | + * @param ScopeConfigInterface $scopeConfig |
| 54 | + */ |
| 55 | + public function __construct( |
| 56 | + ScopeConfigInterface $scopeConfig |
| 57 | + ) { |
| 58 | + $this->scopeConfig = $scopeConfig; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Retrieve true if module is enabled |
| 63 | + * |
| 64 | + * @param string|null $storeId |
| 65 | + * @return bool |
| 66 | + */ |
| 67 | + public function isEnabled(string $storeId = null): bool |
| 68 | + { |
| 69 | + return (bool)$this->getConfig(self::XML_PATH_EXTENSION_ENABLED, $storeId); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Retrieve true if deferred is enabled |
| 74 | + * |
| 75 | + * @param string|null $storeId |
| 76 | + * @return bool |
| 77 | + */ |
| 78 | + public function isDeferredEnabled(string $storeId = null): bool |
| 79 | + { |
| 80 | + return (bool)$this->getConfig(self::XML_PATH_DEFERRED_ENABLED, $storeId); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Retrieve Disallowed Pages |
| 85 | + * |
| 86 | + * @param string|null $storeId |
| 87 | + * @return string |
| 88 | + */ |
| 89 | + public function getDisallowedPages(string $storeId = null): string |
| 90 | + { |
| 91 | + return (string)$this->getConfig(self::XML_PATH_DEFERRED_DISALLOWED_PAGES, $storeId); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Retrieve Ignore JS |
| 96 | + * |
| 97 | + * @param string|null $storeId |
| 98 | + * @return string |
| 99 | + */ |
| 100 | + public function getIgnoreJavaScript(string $storeId = null): string |
| 101 | + { |
| 102 | + return (string)$this->getConfig(self::XML_PATH_DEFERRED_IGNORE_JAVASCRIPT, $storeId); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Retrieve true if JS bundling is enabled |
| 107 | + * |
| 108 | + * @param string|null $storeId |
| 109 | + * @return bool |
| 110 | + */ |
| 111 | + public function isBundlingEnabled(string $storeId = null): bool |
| 112 | + { |
| 113 | + return (bool)$this->getConfig(MagentoConfig::XML_PATH_JS_BUNDLING, $storeId); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Retrieve true if bundling optimization is enabled |
| 118 | + * |
| 119 | + * @param string|null $storeId |
| 120 | + * @return bool |
| 121 | + */ |
| 122 | + public function isBundlingOptimizationEnabled(string $storeId = null): bool |
| 123 | + { |
| 124 | + return (bool)$this->getConfig(self::XML_PATH_JAVASCRIPT_BUNDLING_OPTIMIZATION_ENABLED, $storeId); |
| 125 | + } |
| 126 | + |
| 127 | + /** |
| 128 | + * Retrieve included in bundling JS |
| 129 | + * |
| 130 | + * @param string|null $storeId |
| 131 | + * @return string |
| 132 | + */ |
| 133 | + public function getIncludedInBundling(string $storeId = null): string |
| 134 | + { |
| 135 | + return (string)$this->getConfig(self::XML_PATH_JAVASCRIPT_BUNDLING_INCLUDED_IN_BUNDLING, $storeId); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Retrieve true if amp enabled |
| 140 | + * |
| 141 | + * @param string|null $storeId |
| 142 | + * @return bool |
| 143 | + */ |
| 144 | + public function isAmpRequest(string $storeId = null): bool |
| 145 | + { |
| 146 | + return (bool)$this->getConfig(self::XML_PATH_PLUMROCKET_AMP_ENABLED, $storeId); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Retrieve store config value |
| 151 | + * |
| 152 | + * @param string $path |
| 153 | + * @param string|null $storeId |
| 154 | + * @return mixed |
| 155 | + */ |
| 156 | + public function getConfig(string $path, string $storeId = null) |
| 157 | + { |
| 158 | + return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $storeId); |
| 159 | + } |
| 160 | +} |
0 commit comments