Skip to content

Commit ef5d512

Browse files
committed
Fixed for Magento 2.4.4
1 parent 19dca8a commit ef5d512

File tree

6 files changed

+54
-65
lines changed

6 files changed

+54
-65
lines changed

Helper/ThemeHelper.php

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,38 @@ class ThemeHelper
1616
/**
1717
* @var ScriptsManager
1818
*/
19-
private static $scriptManager;
19+
private static $scriptsManager;
20+
2021
/**
2122
* @var StylesManager
2223
*/
2324
private static $stylesManager;
2425

2526
/**
26-
* @return ScriptsManager|mixed
27+
* @return ScriptsManager
2728
*/
2829
public static function getScriptsManager()
2930
{
30-
if (is_null(self::$scriptManager)) {
31+
if (self::$scriptsManager === null) {
3132
/** @var ScriptsManager $scriptManager */
32-
self::$scriptManager = ObjectManagerHelper::get(ScriptsManager::class);
33+
self::$scriptsManager = ObjectManagerHelper::get(
34+
ScriptsManager::class
35+
);
3336
}
3437

35-
return self::$scriptManager;
38+
return self::$scriptsManager;
3639
}
3740

3841
/**
39-
* @return StylesManager|mixed
42+
* @return StylesManager
4043
*/
4144
public static function getStylesManager()
4245
{
43-
if (is_null(self::$stylesManager)) {
46+
if (self::$stylesManager === null) {
4447
/** @var StylesManager $stylesManager */
45-
self::$stylesManager = ObjectManagerHelper::get(StylesManager::class);
48+
self::$stylesManager = ObjectManagerHelper::get(
49+
StylesManager::class
50+
);
4651
}
4752

4853
return self::$stylesManager;
@@ -76,11 +81,11 @@ public static function registerStyle(
7681

7782
/**
7883
* Register a new script.
84+
*
7985
* @param string $handle Name of the script. Should be unique.
8086
* @param string|bool $src Full URL of the script, or path of the script relative to the WordPress root directory.
8187
* If source is set to false, script is an alias of other scripts it depends on.
8288
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
83-
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
8489
* as a query string for cache busting purposes. If version is set to false, a version
8590
* number is automatically added equal to current installed WordPress version.
8691
* If set to null, no version is added.
@@ -89,19 +94,10 @@ public static function registerStyle(
8994
public static function registerScript(
9095
string $handle,
9196
$src,
92-
array $deps = [],
93-
$ver = false,
94-
bool $print = false
97+
array $deps = []
9598
)
9699
{
97-
self::getScriptsManager()->add($handle, $src, $deps, $ver);
98-
// if ($in_footer) {
99-
// @TODO Remove this
100-
self::getScriptsManager()->addData($handle, 'group', 1);
101-
// }
102-
if ($print) {
103-
self::getScriptsManager()->addData($handle, 'print', 1);
104-
}
100+
self::getScriptsManager()->add($handle, $src, $deps);
105101
return true;
106102
}
107103

@@ -140,33 +136,23 @@ public static function enqueueStyle(
140136
* Enqueue a script.
141137
*
142138
* Registers the script if $src provided (does NOT overwrite), and enqueues it.
143-
* @param string $handle Name of the script. Should be unique.
144-
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
139+
* @param string $handle Name of the script. Should be unique.
140+
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
145141
* Default empty.
146-
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
147-
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
148-
* as a query string for cache busting purposes. If version is set to false, a version
149-
* number is automatically added equal to current installed WordPress version.
150-
* If set to null, no version is added.
151-
**/
142+
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
143+
*/
152144
public static function enqueueScript(
153145
string $handle,
154146
string $src = '',
155-
array $deps = [],
156-
$ver = false,
157-
bool $print = false
147+
array $deps = []
158148
)
159149
{
160150
if ($src) {
161-
$_handle = explode('?', $handle);
162-
163-
self::getScriptsManager()->add($_handle[0], $src, $deps, $ver);
164-
165-
if ($print) {
166-
self::getScriptsManager()->addData($_handle[0], 'print', 1);
167-
}
151+
self::registerScript($handle, $src, $deps);
168152
}
169153

154+
self::getScriptsManager()->addData($handle, 'print', 1);
155+
170156
self::getScriptsManager()->enqueue($handle);
171157
}
172158

@@ -218,11 +204,13 @@ public static function inlineStyle(string $handle, string $code): bool
218204
}
219205

220206
/**
207+
* Add dependencies to the target handle
208+
*
221209
* @param string|array $deps
222210
* @param string $handle
223211
* @return ScriptsManager
224212
*/
225-
public static function addDeps($deps, string $handle)
213+
public static function addScriptDeps($deps, string $handle)
226214
{
227215
return self::getScriptsManager()->addDeps($deps, $handle);
228216
}

Model/Hook.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ private function uniqueId(string $tag, $function, $priority)
263263
}
264264

265265
if ($function[0] instanceof \Closure) {
266-
$ref = new ReflectionFunction($function[0]);
266+
$ref = new \ReflectionFunction($function[0]);
267267
$keys['closure'] = $ref->getName();
268-
$keys['namespace'] = $ref->getNamespaceName() ?: 'empty';
268+
$keys['namespace'] = $ref->getNamespaceName();
269269
$keys['start_line'] = $ref->getStartLine();
270270
$keys['end_line'] = $ref->getEndLine();
271271
if ($args = $ref->getParameters()) {
@@ -275,6 +275,7 @@ private function uniqueId(string $tag, $function, $priority)
275275
}
276276
} elseif(is_object($function[0])) {
277277
$keys['class'] = get_class($function[0]);
278+
$keys['hash'] = spl_object_hash($function[0]);
278279
} elseif (is_string($function[0])) {
279280
$keys['class'] = $function[0];
280281
}
@@ -284,11 +285,7 @@ private function uniqueId(string $tag, $function, $priority)
284285
}
285286

286287
if (!empty($keys)) {
287-
$result = '';
288-
foreach ($keys as $key => $value) {
289-
$result .= $key . '::' . $value . '::';
290-
}
291-
return strtoupper($result);
288+
return implode('::', $keys);
292289
}
293290

294291
return null;
@@ -386,7 +383,7 @@ public function currentPriority()
386383
* @return bool True if the offset exists, false otherwise.
387384
*
388385
*/
389-
public function offsetExists($offset)
386+
public function offsetExists($offset) : bool
390387
{
391388
return isset($this->callbacks[$offset]);
392389
}
@@ -401,7 +398,7 @@ public function offsetExists($offset)
401398
* @link https://secure.php.net/manual/en/arrayaccess.offsetget.php
402399
*
403400
*/
404-
public function offsetGet($offset)
401+
public function offsetGet($offset) : mixed
405402
{
406403
return $this->callbacks[$offset] ?? null;
407404
}
@@ -415,7 +412,7 @@ public function offsetGet($offset)
415412
* @link https://secure.php.net/manual/en/arrayaccess.offsetset.php
416413
*
417414
*/
418-
public function offsetSet($offset, $value)
415+
public function offsetSet($offset, $value) : void
419416
{
420417
if (is_null($offset)) {
421418
$this->callbacks[] = $value;
@@ -432,7 +429,7 @@ public function offsetSet($offset, $value)
432429
*
433430
*
434431
*/
435-
public function offsetUnset($offset)
432+
public function offsetUnset($offset) : void
436433
{
437434
unset($this->callbacks[$offset]);
438435
}
@@ -445,22 +442,21 @@ public function offsetUnset($offset)
445442
*
446443
*
447444
*/
448-
public function current()
445+
public function current() : mixed
449446
{
450447
return current($this->callbacks);
451448
}
452449

453450
/**
454451
* Moves forward to the next element.
455452
*
456-
* @return array Of callbacks at next priority.
453+
* @return void Of callbacks at next priority.
457454
* @link https://secure.php.net/manual/en/iterator.next.php
458455
*
459-
*
460456
*/
461-
public function next()
457+
public function next() : void
462458
{
463-
return next($this->callbacks);
459+
next($this->callbacks);
464460
}
465461

466462
/**
@@ -471,7 +467,7 @@ public function next()
471467
*
472468
*
473469
*/
474-
public function key()
470+
public function key() : mixed
475471
{
476472
return key($this->callbacks);
477473
}
@@ -484,7 +480,7 @@ public function key()
484480
*
485481
*
486482
*/
487-
public function valid()
483+
public function valid() : bool
488484
{
489485
return key($this->callbacks) !== null;
490486
}
@@ -495,7 +491,7 @@ public function valid()
495491
*
496492
* @link https://secure.php.net/manual/en/iterator.rewind.php
497493
*/
498-
public function rewind()
494+
public function rewind() : void
499495
{
500496
reset($this->callbacks);
501497
}

Model/ScriptsManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class ScriptsManager extends AssetDependencies
3939
*/
4040
private $defaultResource = [
4141
'jquery',
42+
'underscore',
4243
'jquery/ui'
4344
];
4445

@@ -152,7 +153,7 @@ public function doItem($handle, $group = false): bool
152153
$obj = $this->registered[ $handle ];
153154

154155
if (!$obj['ver']) {
155-
$ver = Configuration::VERSION;
156+
$ver = Configuration::version();
156157
} else {
157158
$ver = $obj['ver'];
158159
}
@@ -162,7 +163,7 @@ public function doItem($handle, $group = false): bool
162163
}
163164

164165
$src = $obj['src'];
165-
$print = (bool)isset($obj['extra']['print']) && $obj['extra']['print'];
166+
$print = (bool) isset($obj['extra']['print']) && $obj['extra']['print'];
166167
$cond_before = '';
167168
$cond_after = '';
168169
$conditional = $obj['extra']['conditional'] ?? '';
@@ -348,8 +349,8 @@ public function allDeps($handles, $recursion = false, $group = false)
348349
*/
349350
public function doHeadItems(): array
350351
{
351-
$this->doItems(false, 0);
352352
$this->printRequireConfig();
353+
$this->doItems(false, 0);
353354
return $this->done;
354355
}
355356

Traits/TraitStaticInstances.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
trait TraitStaticInstances
1414
{
1515
/**
16-
* @param null $type
16+
* @param string|null $type
1717
* @return mixed
1818
*/
19-
private static function getInstance($type = null)
19+
private static function getInstance(?string $type)
2020
{
2121
return self::getObjectManager()->get($type ?? __CLASS__);
2222
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "goomento/module-core",
33
"description": "Magento 2 Goomento Core module",
44
"type": "magento2-module",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"license": [
77
"OSL-3.0"
88
],

etc/module.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10-
<module name="Goomento_Core" setup_version="1.0.1" />
10+
<module name="Goomento_Core">
11+
<sequence>
12+
<module name="Magento_Backend" />
13+
</sequence>
14+
</module>
1115
</config>

0 commit comments

Comments
 (0)