1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. |
4
|
|
|
* @author: <mailto:[email protected]> |
5
|
|
|
* @github: <https://github.com/hryvinskyi> |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Hryvinskyi\DeferJs\Helper; |
11
|
|
|
|
12
|
|
|
use Magento\Framework\App\Helper\AbstractHelper; |
13
|
|
|
use Magento\Store\Model\ScopeInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Config |
17
|
|
|
*/ |
18
|
|
|
class Config extends AbstractHelper |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Configuration paths |
22
|
|
|
*/ |
23
|
|
|
const XML_HRYVINSKYI_DEFER_JS_GENERAL_ENABLED = 'hryvinskyi_defer_js/general/enabled'; |
24
|
|
|
const XML_HRYVINSKYI_DEFER_JS_DISABLE_ATTRIBUTE = 'hryvinskyi_defer_js/general/disable_attribute'; |
25
|
|
|
const XML_HRYVINSKYI_DEFER_JS_MINIFY_BODY_SCRIPTS = 'hryvinskyi_defer_js/general/minify_body_scripts'; |
26
|
|
|
const XML_HRYVINSKYI_DEFER_JS_OPTIMIZE_X_MAGENTO_INIT_SCRIPTS |
27
|
|
|
= 'hryvinskyi_defer_js/general/optimize_x_magento_init_scripts'; |
28
|
|
|
const XML_HRYVINSKYI_DEFER_JS_EXCLUDE_CONTROLLERS = 'hryvinskyi_defer_js/general/exclude_controllers'; |
29
|
|
|
const XML_HRYVINSKYI_DEFER_JS_EXCLUDE_PATHS = 'hryvinskyi_defer_js/general/exclude_paths'; |
30
|
|
|
const XML_HRYVINSKYI_DEFER_JS_EXCLUDE_URL_PATTERN = 'hryvinskyi_defer_js/general/exclude_url_pattern'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $scopeType |
34
|
|
|
* @param null|string $scopeCode |
35
|
|
|
* |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
public function isEnabled( |
39
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
40
|
|
|
$scopeCode = null |
41
|
|
|
): bool { |
42
|
|
|
return $this->scopeConfig->isSetFlag( |
43
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_GENERAL_ENABLED, |
44
|
|
|
$scopeType, |
45
|
|
|
$scopeCode |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $scopeType |
51
|
|
|
* @param null|string $scopeCode |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public function getDisableAttribute( |
56
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
57
|
|
|
$scopeCode = null |
58
|
|
|
): string { |
59
|
|
|
return (string)$this->scopeConfig->getValue( |
60
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_DISABLE_ATTRIBUTE, |
61
|
|
|
$scopeType, |
62
|
|
|
$scopeCode |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $scopeType |
68
|
|
|
* @param null|string $scopeCode |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function isMinifyBodyScript( |
73
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
74
|
|
|
$scopeCode = null |
75
|
|
|
): bool { |
76
|
|
|
return $this->scopeConfig->isSetFlag( |
77
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_MINIFY_BODY_SCRIPTS, |
78
|
|
|
$scopeType, |
79
|
|
|
$scopeCode |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $scopeType |
85
|
|
|
* @param null|string $scopeCode |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isOptimizeXMagentoInitScripts( |
90
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
91
|
|
|
$scopeCode = null |
92
|
|
|
): bool { |
93
|
|
|
return $this->scopeConfig->isSetFlag( |
94
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_OPTIMIZE_X_MAGENTO_INIT_SCRIPTS, |
95
|
|
|
$scopeType, |
96
|
|
|
$scopeCode |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Return Excluded Controllers |
102
|
|
|
* |
103
|
|
|
* @param string $scopeType |
104
|
|
|
* @param null|string $scopeCode |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getExcludeControllers( |
109
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
110
|
|
|
$scopeCode = null |
111
|
|
|
): string { |
112
|
|
|
return (string)$this->scopeConfig->getValue( |
113
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_EXCLUDE_CONTROLLERS, |
114
|
|
|
$scopeType, |
115
|
|
|
$scopeCode |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return Excluded Paths |
121
|
|
|
* |
122
|
|
|
* @param string $scopeType |
123
|
|
|
* @param null|string $scopeCode |
124
|
|
|
* |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getExcludePaths( |
128
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
129
|
|
|
$scopeCode = null |
130
|
|
|
): string { |
131
|
|
|
return (string)$this->scopeConfig->getValue( |
132
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_EXCLUDE_PATHS, |
133
|
|
|
$scopeType, |
134
|
|
|
$scopeCode |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Return Excluded URL pattern |
140
|
|
|
* |
141
|
|
|
* @param string $scopeType |
142
|
|
|
* @param null|string $scopeCode |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getExcludeUrlPattern( |
147
|
|
|
string $scopeType = ScopeInterface::SCOPE_STORE, |
148
|
|
|
$scopeCode = null |
149
|
|
|
): string { |
150
|
|
|
return (string)$this->scopeConfig->getValue( |
151
|
|
|
self::XML_HRYVINSKYI_DEFER_JS_EXCLUDE_URL_PATTERN, |
152
|
|
|
$scopeType, |
153
|
|
|
$scopeCode |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|