PHPackages                             themehybrid/hybrid-assets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. themehybrid/hybrid-assets

ActiveLibrary

themehybrid/hybrid-assets
=========================

Assets helper package for the Hybrid Core framework.

1.0.0-alpha.5(1mo ago)034↓75%[1 issues](https://github.com/themehybrid/hybrid-assets/issues)GPL-2.0-or-laterPHPPHP &gt;=8.2

Since Oct 4Pushed 4w ago1 watchersCompare

[ Source](https://github.com/themehybrid/hybrid-assets)[ Packagist](https://packagist.org/packages/themehybrid/hybrid-assets)[ Docs](https://github.com/themehybrid/hybrid-assets)[ RSS](/packages/themehybrid-hybrid-assets/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

Hybrid Assets
=============

[](#hybrid-assets)

Asset (CSS/JS etc.) resolution for [Hybrid Core](https://github.com/themehybrid/hybrid-core).

Hybrid Assets gives themes and plugins a single, consistent API for resolving asset **URLs**, **filesystem paths**, **dependencies**, and **cache-busting versions** — with automatic support for child-theme overrides, wp-scripts `.asset.php` metadata, and Laravel Mix manifests.

Why
---

[](#why)

WordPress asset registration usually means hardcoding URLs, manually tracking `filemtime()` for cache busting, and writing bespoke logic every time a child theme needs to override a parent theme or plugin asset. Hybrid Assets handles all of that:

- **One API** for themes and plugins alike (`path()`, `url()`, `assetUrl()`, `assetPath()`, `asset()`)
- **Automatic inheritance** (when the `inherit` param is `true`) — child theme → parent theme → plugin fallback chain
- **Automatic versioning** — reads `wp-scripts` `.asset.php` files or Laravel Mix `mix-manifest.json`, falling back to a content hash
- **Dependency resolution** — reads `wp_enqueue_script`/`style` dependency arrays straight out of `.asset.php`

Requirements
------------

[](#requirements)

- PHP 8.2+
- [Hybrid Core](https://github.com/themehybrid/hybrid-core) framework ^7.0
- [Hybrid Tools](https://github.com/themehybrid/hybrid-tools) ^2.0
- WordPress 7.0+

Installation
------------

[](#installation)

```
composer require themehybrid/hybrid-assets
```

Register the service provider on your container:

```
$app->register( \Hybrid\Assets\AssetsServiceProvider::class );
```

This binds `ParentTheme` and `ChildTheme` as singletons, and `Plugin` as a fresh (non-shared) binding — each plugin carries its own config (plugin file, override directory, manifest settings), so instances can't be shared between consumers.

Setting up a resolver
---------------------

[](#setting-up-a-resolver)

`AssetsServiceProvider` registers the underlying `ParentTheme` / `ChildTheme` / `Plugin` classes, but you still bind your **own** named instance — configured for your theme or plugin's specific asset directory — in your provider's `register()` method.

### In a theme

[](#in-a-theme)

```
use Hybrid\Assets\ParentTheme;

$this->app->singleton( 'my-theme/assets', static function ( $app ) {
    /** @var ParentTheme $theme */
    $theme = $app->make( ParentTheme::class );
    $theme->setAssetsDirectory( '/assets' );
    $theme->setManifestDirectory( '/assets' );

    return $theme;
} );
```

### In a plugin

[](#in-a-plugin)

```
use Hybrid\Assets\Plugin as AssetsPlugin;

$this->app->singleton( 'my-plugin/assets', static function ( $app ) {
    /** @var AssetsPlugin $plugin */
    $plugin = $app->make( AssetsPlugin::class );
    $plugin->setPluginFile( MY_PLUGIN_FILE );

    // By default, plugin asset overrides are expected under `{theme}/public/my-plugin/...`.
    // Themes can override this slug to match their own asset structure, such as `dist/`,
    // `assets/`, or any other custom directory.
    $plugin->setOverrideAssetsDirectory(
        apply_filters( 'my-plugin/assets/override/path', '/public/my-plugin' )
    );

    return $plugin;
} );
```

Binding key names (`my-theme/assets`, `my-plugin/assets`) are your choice — just keep them unique across the container and reuse the same string in your Facade accessor (see below).

Usage
-----

[](#usage)

### Direct container access

[](#direct-container-access)

```
$theme = app( 'my-theme/assets' );

$theme->url( '/js/app.js' );
$theme->path( '/js/app.js' );
```

### Via a Facade (recommended)

[](#via-a-facade-recommended)

Wrapping your bound instance in a `Facade` gives you a clean, static-style call site without losing testability. Define one per theme/plugin:

```
