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