Skip to content

Commit

Permalink
fix(Bundle): API fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Nov 4, 2024
1 parent 6861a61 commit f4a445e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": ">=8.0",
"automattic/jetpack-constants": "^2.0",
"x-wp/helper-functions": "^1.9",
"x-wp/helper-functions": "^1.18",
"x-wp/helper-traits": "^1.9"
},
"require-dev": {
Expand Down
20 changes: 11 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/Core/Asset_Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function find( string $ext ): array {
* @param class-string<T> $type The type of asset to get.
* @return array<string,T>
*/
public function get( string $type ): array {
public function collect( string $type ): array {
$found = array();

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

return $found;
}

/**
* Get an asset by field.
*
* @param string $id The ID of the asset to get.
* @param string $field The field to search by.
* @return Style|Script|Image|Font|null
*/
public function get( string $id, string $field = 'handle' ): Style|Script|Image|Font|null {
foreach ( array_keys( $this->manifest ) as $src ) {
if ( $id === $this[ $src ]->{"{$field}"}() ) {
return $this[ $src ];
}
}

return null;
}
}
16 changes: 8 additions & 8 deletions src/Resources/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ public function __construct(
}

/**
* Get the bundle instance.
* Get the WP_Filesystem instance.
*
* @return XWP_Asset_Bundle
* @return \WP_Filesystem_Direct|null
*/
public function bundle(): XWP_Asset_Bundle {
return $this->bundle;
protected function wpfs(): ?\WP_Filesystem_Direct {
return \xwp_wpfs() ?: null;
}

/**
* Get the WP_Filesystem instance.
* Get the bundle instance.
*
* @return \WP_Filesystem_Base|null
* @return XWP_Asset_Bundle
*/
protected function wpfs(): ?\WP_Filesystem_Base {
return \wp_load_filesystem() ?: null;
public function bundle(): XWP_Asset_Bundle {
return $this->bundle;
}

/**
Expand Down

0 comments on commit f4a445e

Please sign in to comment.