PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.16
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.16
1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 All 180 releases
disco / vendor / inpsyde / assets / src / Util / AssetHookResolver.php

AssetHookResolver.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.16, at vendor/inpsyde/assets/src/Util/AssetHookResolver.php

93 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Assets package.
5 *
6 * (c) Inpsyde GmbH
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 declare(strict_types=1);
13
14 namespace Inpsyde\Assets\Util;
15
16 use Inpsyde\WpContext;
17 use Inpsyde\Assets\Asset;
18
19 class AssetHookResolver
20 {
21 /**
22 * @var WpContext
23 */
24 protected $context;
25
26 /**
27 * @param WpContext|null $context
28 */
29 public function __construct(?WpContext $context = null)
30 {
31 $this->context = $context ?? WpContext::determine();
32 }
33
34 /**
35 * Resolving to the current location/page in WordPress all current hooks.
36 *
37 * @return string[]
38 */
39 public function resolve(): array
40 {
41 $isLogin = $this->context->isLogin();
42 $isFront = $this->context->isFrontoffice();
43 $isActivate = $this->context->isWpActivate();
44
45 if (!$isActivate && !$isLogin && !$isFront && !$this->context->isBackoffice()) {
46 return [];
47 }
48
49 if ($isLogin) {
50 return [Asset::HOOK_LOGIN];
51 }
52
53 if ($isActivate) {
54 return [Asset::HOOK_ACTIVATE];
55 }
56
57 // These hooks might be fired in both front and back office.
58 $assets = [Asset::HOOK_BLOCK_ASSETS];
59
60 if ($isFront) {
61 $assets[] = Asset::HOOK_FRONTEND;
62 $assets[] = Asset::HOOK_CUSTOMIZER_PREVIEW;
63
64 return $assets;
65 }
66
67 $assets[] = Asset::HOOK_BLOCK_EDITOR_ASSETS;
68 $assets[] = Asset::HOOK_CUSTOMIZER;
69 $assets[] = Asset::HOOK_BACKEND;
70
71 return $assets;
72 }
73
74 /**
75 * @return string|null
76 */
77 public function lastHook(): ?string
78 {
79 switch (true) {
80 case $this->context->isLogin():
81 return Asset::HOOK_LOGIN;
82 case $this->context->isFrontoffice():
83 return Asset::HOOK_FRONTEND;
84 case $this->context->isBackoffice():
85 return Asset::HOOK_BACKEND;
86 case $this->context->isWpActivate():
87 return Asset::HOOK_ACTIVATE;
88 }
89
90 return null;
91 }
92 }
93