PHPackages                             packaged/dispatch - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. packaged/dispatch

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

packaged/dispatch
=================

Asset Management Middleware for Stack PHP

2.21.0(1y ago)5124.8k↓33.1%3[1 issues](https://github.com/packaged/dispatch/issues)6MITPHPCI failing

Since Mar 6Pushed 1y ago3 watchersCompare

[ Source](https://github.com/packaged/dispatch)[ Packagist](https://packagist.org/packages/packaged/dispatch)[ RSS](/packages/packaged-dispatch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (97)Used By (6)

Dispatch
========

[](#dispatch)

[![Latest Stable Version](https://camo.githubusercontent.com/b7cdecb8d7d60144bcb56ad9aceab379cbf3de928d9efc3e7f4e13cb5d187aed/68747470733a2f2f706f7365722e707567782e6f72672f7061636b616765642f64697370617463682f76657273696f6e2e706e67)](https://packagist.org/packages/packaged/dispatch)[![Total Downloads](https://camo.githubusercontent.com/ac720868364428685308500f45e7b73125563ee75d6b6ca913bdbb352e2c2799/68747470733a2f2f706f7365722e707567782e6f72672f7061636b616765642f64697370617463682f642f746f74616c2e706e67)](https://packagist.org/packages/packaged/dispatch)

Resource Management for PHP

Basic Installation
------------------

[](#basic-installation)

The following should be included in your public/index.php file

```
$dispatchConfig = new \Packaged\Config\Provider\ConfigSection('dispatch');
$dispatchConfig->addItem('run_on', 'path');
$dispatchConfig->addItem('run_match', 'assets');
$dispatchConfig->addItem('aliases', ['ali' => 'src/res']);
$dispatchConfig->addItem('css_config', ['minify' => 'false']);
$dispatchConfig->addItem('ext_config', [/*Config Options*/]);

$dispatcher = new \Packaged\Dispatch\Dispatch($app, $dispatchConfig);
$dispatcher->setBaseDirectory(dirname(__DIR__));

//By md5 hashing the files based on the project root, runtime hashes are
//not required, and will perform much faster
$dispatcher->setFileHashTable(
  [
    'src/res/css/base.css' => 'd5364e0d4c0174e4a30cea9a03af036d',
    'assets/003.JPG'       => '8c0d1206f71976e45cd138ed30645519'
  ]
);

```

You can then add into the request through either

Stack PHP Method

```
$app = (new \Stack\Builder())
  ->push([$dispatcher, 'prepare'])
  ->resolve($app);

```

Raw Call

```
$app = $dispatch->handle($request)

```

### Using Dispatch

[](#using-dispatch)

There are a few types of asset manager you can use to generate static resource uris. An asset manager defines a route path by which processing should start when searching for your specified resources.

#### Config Options

[](#config-options)

##### run\_on / run\_match

[](#run_on--run_match)

These options determine how asset paths are generated.

run\_on Optionrun\_match DefaultDescriptionpathres//domain.tld/ **res** /*resource\_url*subdomainstatic.// **static.** domain.tld/*resource\_url*domain(current domain)// **domain.tld** /*resource\_url*#### Asset Type

[](#asset-type)

```
$am = \Packaged\Dispatch\AssetManager::assetType();

```

By default, this type will search in /assets, assuming you want to store your assets within that folder in the base of your project. If you want to change the default assets path, you can use the 'assets\_dir' config item, relative to your project base.

#### Alias Type

[](#alias-type)

```
$am = \Packaged\Dispatch\AssetManager::aliasType('alias');

```

Alias types are used for common paths, which you may want to group assets, which could be a deep path within your source or vendor directories. Aliases can be configured in the config as a keyed array within the 'aliases' config item

#### Source Type

[](#source-type)

```
$am = \Packaged\Dispatch\AssetManager::sourceType();

```

Source type will load data from your source folder. By default this is 'src' however, if you store your source files in another directory, this can be changed using the 'source\_dir' config item.

#### Vendor Type

[](#vendor-type)

```
$am = \Packaged\Dispatch\AssetManager::vendorType('vendor','package');

```

Vendor type will set the base to a vendors folder specified by composer, this will usually be /vendor/{vendor}/{package}

#### Automatic Detection

[](#automatic-detection)

```
$am = new \Packaged\Dispatch\AssetManager(new Class());

```

By passing through a class into the constructor for the asset manager, dispatch will automatically detect to see if the class is within your source directory or created by a vendor package. This will give you either a vendor type or source type.

### Generating Resource Uris

[](#generating-resource-uris)

Now you have your asset manager object, you can generate resource uris to use within your project. All you need to do is pass the relative path (from the asset manager base), to the method 'getResourceUri', and a full uri will be returned.

```

```

### CSS &amp; JS Global Store

[](#css--js-global-store)

For simplicity within your code, you are also able to add css and js files to a store for the render, which can be pulled out on demand. This allows you to include relevant css or js files based on sub classes, controllers views etc and in a global layout, simply include any that have been built up.

To include your css files, you just need to call requireCss on your assetManager

```
$am->requireCss(
  [
    'stylesheets/bootstrap',
    'stylesheets/theme',
    'stylesheets/widgets',
  ]
);

```

You can also include css files with options for things like delayed js or print

```
$am->requireCss('stylesheets/print',['media' => 'print']);

```

To then render the urls out to the page, you have two options.

Option 1. Let dispatch do it all for you

```

```

Option 2. Get the uris yourself, with their options, and render them

```
$uris = AssetManager::getUrisByType('css');
//Options is a key value array or options sent through by requireCss
foreach($uris as $uri => $options)
{
  echo '';
}

```

The same functionality is also available for javascript, by replacing css with js in method names and parameters.

We recommed using AssetManager::TYPE\_CSS and AssetManager::TYPE\_JS within your code, however, for shorter examples, the string version is also valid.

Custom Asset Types
------------------

[](#custom-asset-types)

Custom assets are used if you need an asset to be dispatched with a specific mime type, or your asset must be rendered or compiled before being dispatched. Simply create a class implementing IAsset (you can extend AbstractAsset) and register it with AssetResponse.

The following example will cause all requested files with the extension 'ext' to be served with the 'application/x-my-asset' content type, and return an MD5 hash of the file contents.

```
class MyAsset extends AbstractAsset
{
  public function getExtension()
  {
    return 'ext';
  }

  public function getContentType()
  {
    return "application/x-my-asset";
  }

  public function getContent()
  {
    return md5(parent::getContent());
  }
}

AssetResponse::addAssetType('ext', '\MyAsset');

```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~318 days

Total

95

Last Release

517d ago

Major Versions

0.4.2 → 1.0.02015-01-23

1.6.7 → 2.0.0-alpha2018-12-13

1.6.8 → 2.0.0-alpha.52018-12-19

PHP version history (3 changes)0.0.1PHP &gt;=5.4.0

1.6.0PHP &gt;=7.0

2.0.0-alphaPHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a2dc779402c4fa879b9f63159900da2a4c766661286182c4cecd66a7d4fc71ed?d=identicon)[bajbnet](/maintainers/bajbnet)

---

Top Contributors

[![bajb](https://avatars.githubusercontent.com/u/2241334?v=4)](https://github.com/bajb "bajb (144 commits)")[![TomK](https://avatars.githubusercontent.com/u/299656?v=4)](https://github.com/TomK "TomK (25 commits)")[![daveblake](https://avatars.githubusercontent.com/u/283275?v=4)](https://github.com/daveblake "daveblake (8 commits)")[![aktorou](https://avatars.githubusercontent.com/u/3628213?v=4)](https://github.com/aktorou "aktorou (1 commits)")[![Jleagle](https://avatars.githubusercontent.com/u/381099?v=4)](https://github.com/Jleagle "Jleagle (1 commits)")[![MrEssex](https://avatars.githubusercontent.com/u/5024348?v=4)](https://github.com/MrEssex "MrEssex (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/packaged-dispatch/health.svg)

```
[![Health](https://phpackages.com/badges/packaged-dispatch/health.svg)](https://phpackages.com/packages/packaged-dispatch)
```

###  Alternatives

[devfactory/minify

A package for minifying styles and javascript for laravel 5

87363.5k14](/packages/devfactory-minify)[joseki/webloader-filters

This is an extension of janmarek/webloader. This extension contains filters to minify js and css.

12229.1k8](/packages/joseki-webloader-filters)[trentrichardson/cakephp-shrink

Compiles, combines, and minifies javascript, coffee, less, scss, and css

1619.3k](/packages/trentrichardson-cakephp-shrink)[nlac/nlsclientscript

Yii ClientScript extension for prevent reloading javascript and merging/minfying resources

208.2k](/packages/nlac-nlsclientscript)[fisharebest/laravel-assets

Asset management for Laravel

208.1k](/packages/fisharebest-laravel-assets)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
