Skip to content

Commit f4a445e

Browse files
committed
fix(Bundle): API fixes
1 parent 6861a61 commit f4a445e

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"require": {
1212
"php": ">=8.0",
1313
"automattic/jetpack-constants": "^2.0",
14-
"x-wp/helper-functions": "^1.9",
14+
"x-wp/helper-functions": "^1.18",
1515
"x-wp/helper-traits": "^1.9"
1616
},
1717
"require-dev": {

composer.lock

+11-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Core/Asset_Bundle.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public function find( string $ext ): array {
359359
* @param class-string<T> $type The type of asset to get.
360360
* @return array<string,T>
361361
*/
362-
public function get( string $type ): array {
362+
public function collect( string $type ): array {
363363
$found = array();
364364

365365
foreach ( array_keys( $this->manifest ) as $src ) {
@@ -372,4 +372,21 @@ public function get( string $type ): array {
372372

373373
return $found;
374374
}
375+
376+
/**
377+
* Get an asset by field.
378+
*
379+
* @param string $id The ID of the asset to get.
380+
* @param string $field The field to search by.
381+
* @return Style|Script|Image|Font|null
382+
*/
383+
public function get( string $id, string $field = 'handle' ): Style|Script|Image|Font|null {
384+
foreach ( array_keys( $this->manifest ) as $src ) {
385+
if ( $id === $this[ $src ]->{"{$field}"}() ) {
386+
return $this[ $src ];
387+
}
388+
}
389+
390+
return null;
391+
}
375392
}

src/Resources/File.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ public function __construct(
5555
}
5656

5757
/**
58-
* Get the bundle instance.
58+
* Get the WP_Filesystem instance.
5959
*
60-
* @return XWP_Asset_Bundle
60+
* @return \WP_Filesystem_Direct|null
6161
*/
62-
public function bundle(): XWP_Asset_Bundle {
63-
return $this->bundle;
62+
protected function wpfs(): ?\WP_Filesystem_Direct {
63+
return \xwp_wpfs() ?: null;
6464
}
6565

6666
/**
67-
* Get the WP_Filesystem instance.
67+
* Get the bundle instance.
6868
*
69-
* @return \WP_Filesystem_Base|null
69+
* @return XWP_Asset_Bundle
7070
*/
71-
protected function wpfs(): ?\WP_Filesystem_Base {
72-
return \wp_load_filesystem() ?: null;
71+
public function bundle(): XWP_Asset_Bundle {
72+
return $this->bundle;
7373
}
7474

7575
/**

0 commit comments

Comments
 (0)