10
10
11
11
/**
12
12
* Asset loader.
13
- *
14
- * @method static self add_bundle( XWP_Asset_Bundle $bundle ) Add a bundle.
15
- * @method static self load_bundle( XWP_Asset_Bundle|array $bundle ) Load a bundle.
16
- * @method static XWP_Asset_Bundle make_bundle( array $args ) Create a bundle.
17
- * @method static ?XWP_Asset_Bundle get_bundle(string $id) Get a bundle by ID.
18
13
*/
19
14
final class XWP_Asset_Loader {
20
15
use Singleton;
@@ -27,20 +22,47 @@ final class XWP_Asset_Loader {
27
22
private array $ bundles = array ();
28
23
29
24
/**
30
- * Call a static method on the instance .
25
+ * Load a bundle .
31
26
*
32
- * @param string $name The name of the method to call.
33
- * @param array<mixed> $args The arguments to pass to the method.
34
- * @return mixed
27
+ * @param XWP_Asset_Bundle $bundle The bundle to load.
28
+ * @return self
29
+ */
30
+ public static function add_bundle ( XWP_Asset_Bundle $ bundle ): self {
31
+ return self ::instance ()->add ( $ bundle );
32
+ }
33
+
34
+ /**
35
+ * Load a bundle, or create a bundle from arguments and load it.
35
36
*
36
- * @throws \BadMethodCallException If the method does not exist.
37
+ * @param array<string,mixed>|XWP_Asset_Bundle $bundle Bundle instance or bundle arguments.
38
+ * @return self
37
39
*/
38
- public static function __callStatic ( string $ name , array $ args = array () ): mixed {
39
- if ( ! method_exists ( self ::class, " call_ $ name " ) ) {
40
- throw new \ BadMethodCallException ( esc_html ( " Method $ name does not exist " ) );
40
+ public static function load_bundle ( array | XWP_Asset_Bundle $ bundle ): self {
41
+ if ( ! ( $ bundle instanceof XWP_Asset_Bundle ) ) {
42
+ $ bundle = self :: make_bundle ( $ bundle );
41
43
}
42
44
43
- return self ::instance ()->{"call_ $ name " }( ...$ args );
45
+ return self ::add_bundle ( $ bundle );
46
+ }
47
+
48
+ /**
49
+ * Make a bundle from arguments.
50
+ *
51
+ * @param array<string,mixed> $args Bundle arguments.
52
+ * @return XWP_Asset_Bundle
53
+ */
54
+ public static function make_bundle ( array $ args ): XWP_Asset_Bundle {
55
+ return new XWP_Asset_Bundle ( ...$ args );
56
+ }
57
+
58
+ /**
59
+ * Get a bundle by ID.
60
+ *
61
+ * @param string $id Bundle ID.
62
+ * @return XWP_Asset_Bundle|null
63
+ */
64
+ public static function get_bundle ( string $ id ): ?XWP_Asset_Bundle {
65
+ return self ::instance ()->get ( $ id );
44
66
}
45
67
46
68
/**
@@ -107,43 +129,19 @@ static function () use ( $bundle, $context ) {
107
129
* @param XWP_Asset_Bundle $bundle The bundle to load.
108
130
* @return self
109
131
*/
110
- private function call_add_bundle ( XWP_Asset_Bundle $ bundle ): self {
132
+ private function add ( XWP_Asset_Bundle $ bundle ): self {
111
133
$ this ->bundles [ $ bundle ->id () ] = $ bundle ;
112
134
113
135
return $ this ;
114
136
}
115
137
116
- /**
117
- * Load a bundle, or create a bundle from arguments and load it.
118
- *
119
- * @param array<string,mixed>|XWP_Asset_Bundle $bundle Bundle instance or bundle arguments.
120
- * @return self
121
- */
122
- private function call_load_bundle ( array |XWP_Asset_Bundle $ bundle ): self {
123
- if ( ! ( $ bundle instanceof XWP_Asset_Bundle ) ) {
124
- $ bundle = self ::make_bundle ( $ bundle );
125
- }
126
-
127
- return self ::add_bundle ( $ bundle );
128
- }
129
-
130
- /**
131
- * Make a bundle from arguments.
132
- *
133
- * @param array<string,mixed> $args Bundle arguments.
134
- * @return XWP_Asset_Bundle
135
- */
136
- private function call_make_bundle ( array $ args ): XWP_Asset_Bundle {
137
- return new XWP_Asset_Bundle ( ...$ args );
138
- }
139
-
140
138
/**
141
139
* Get a bundle by ID.
142
140
*
143
141
* @param string $id Bundle ID.
144
142
* @return XWP_Asset_Bundle|null
145
143
*/
146
- private function call_get_bundle ( string $ id ): ?XWP_Asset_Bundle {
144
+ private function get ( string $ id ): ?XWP_Asset_Bundle {
147
145
return $ this ->bundles [ $ id ] ?? null ;
148
146
}
149
147
}
0 commit comments