PHPackages                             mehr-it/levi-assets-linker - 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. mehr-it/levi-assets-linker

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

mehr-it/levi-assets-linker
==========================

Framework independent linker component for mehr-it/levi-assets

1.1.0(4y ago)01.5k1MITPHPPHP &gt;=7.1.0

Since Aug 7Pushed 4y agoCompare

[ Source](https://github.com/mehr-it/levi-assets-linker)[ Packagist](https://packagist.org/packages/mehr-it/levi-assets-linker)[ RSS](/packages/mehr-it-levi-assets-linker/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (3)Used By (1)

Levi assets linker
==================

[](#levi-assets-linker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3b10c9d7ab28951879769b0b19636f744b97c736fbc055cb9b54c9f8ae2594b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6568722d69742f6c6576692d6173736574732d6c696e6b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mehr-it/levi-assets-linker)[![Build Status](https://camo.githubusercontent.com/1bdef5181c357b4edacedcb5c972545722b4c1378ec95c165f71f962a6e37842/68747470733a2f2f7472617669732d63692e6f72672f6d6568722d69742f6c6576692d6173736574732d6c696e6b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mehr-it/levi-assets-linker)

Framework independent linker component for the [mehr-it/levi-assets](https://packagist.org/packages/mehr-it/levi-assets)package. It allows to generate links from passed asset build paths outside of the Laravel framework.

The concept behind this separate linker component allows to generate all necessary page data using the laravel application and store it for a separate request processor app. This app can be very lightweight without any framework overhead. It can use the linker component only, to resolve asset links on the fly.

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

[](#installation)

You can install the package via composer:

```
composer require mehr-it/levi-assets-linker

```

The role of the linker
----------------------

[](#the-role-of-the-linker)

Despite generating links, the job of the linker is to pick the most suitable asset built for the given asset. Therefore it receives a list with the paths to all builds of an asset to pick one for the link. Without any filter, the linker would simply pick the first built to generate a link for. However, link filters may modify (sort, remove, ...) the built list. They can also modify the generated URL after the linker has generated it from the path.

Linker configuration
--------------------

[](#linker-configuration)

The linker can be configured using the static `configure()` method:

```
AssetLinker::configure([

    // configures the path prefix prepended to all asset paths
    'root' => 'my/assets',

    // allows to define a custom implementaion of the AssetLinker
    'class' => MyAssetLinker::class,

    // defines the default link filters to apply when generating links
    'default_filters' => [

        // the first item specifies the filter name, all others are passed as arguments
        ['proto', 'https'],
        ['host', 'cdn.my-page.com'],
    ],

    // allows to register custom filter classes
    'filters' => [
        'myFilter' => MyCustomFilter::class,
    ]
]);

```

Each call to `configure()` will reset any previous configuration.

Linking assets
--------------

[](#linking-assets)

The static `link` method generates links using the previously set configuration:

```
$link = AssetLinker::link($request, $paths, $linkFilters, $query);

```

The first argument is expected to hold a PSR-7 compatible representation of the request. This request object is passed to all link filters to they can pick the most suitable asset build.

The second argument must contain an associative array with all asset builds' paths. The build name is used as array key.

The `$linkFilters` argument allows to apply custom filters for this call. It must be an array of filter definitions. Each filter definition is an array itself and consists of the filter name (as defined in the *filters* option of the config) followed by all the arguments to be passed to the filter. Filters are applied in the oder they are passed. The configured `'default_filters'`are applied before the ones passed as argument.

The last argument allows to add query parameters to the URL. They can be passed as array or as already encoded query string.

Built-in filters
----------------

[](#built-in-filters)

The linker package comes with some predefined filters which can be used out of the box.

### built

[](#built)

The `BuiltNameFilter` allows to specify a which builds of the assets can be used for the link. Following example filters for jpg builds only:

```
$paths = [
    'jpg_small' => 'small/image.jpg',
    'png_small' => 'small/image.png',
    'jpg_large' => 'large/image.jpg',
    'png_large' => 'large/image.png',
];

AssetLinker::link($request, $paths, [['built', 'jpg_small', 'jpg_large']]);

```

### pfx

[](#pfx)

The `BuiltNamePrefixFilter` allows to specify a which builds of the assets can be used by applying a prefix search. Following example filters for jpg builds only:

```
$paths = [
    'jpg_small' => 'small/image.jpg',
    'png_small' => 'small/image.png',
    'jpg_large' => 'large/image.jpg',
    'png_large' => 'large/image.png',
];

AssetLinker::link($request, $paths, [['pfx', 'jpg']]);

```

### host

[](#host)

The `ReplaceAuthorityFilter` allows to overwrite the host (authority) part the generated URL. This is needed, when another host name should be used for assets. Default is to use the same as the request host name.

```
AssetLinker::link($request, $paths, [['host', 'www.example.com']]);

```

### proto

[](#proto)

The `ReplaceSchemeFilter` allows to overwrite the protocol (scheme) part the generated URL. This can be used to force HTTPS. Default is to use the same as the request scheme.

```
AssetLinker::link($request, $paths, [['proto', 'https']]);

```

### replacePath

[](#replacepath)

The `ReplacePathFilter` allows to do a regex replacement for the path component of the generated URL. This might be useful if e.g. you need to a prefix to the path. **Note: the path always starts with "/" if not empty**

```
// prepend prefix "_pfx" to the path
AssetLinker::link($request, $paths, [['replacePath', '%^(/.*$%', '_pfx$1']]);

```

### webp

[](#webp)

The `PreferWebPFilter` allows to prefer webp images over other formats when the browser supports them. The arguments must identify the webp image builds by their name.

```
$paths = [
        'webp_small' => 'small/image.webp',
        'png_small'  => 'small/image.png',
        'webp_large' => 'large/image.webp',
        'png_large'  => 'large/image.png',
    ];

AssetLinker::link($request, $paths, [['webp', 'webp_small', 'webp_large']]);

```

If the browser has included 'image/webp' to the request's accept header, the builts "webp\_small" and "webp\_large" will be sorted first in the builds array.

If the browser does not indicate webp support, webp builds are removed from the list, **if there are others available**.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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 ~367 days

Total

2

Last Release

1737d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44973729?v=4)[mehr.IT GmbH](/maintainers/mehr-it)[@mehr-it](https://github.com/mehr-it)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mehr-it-levi-assets-linker/health.svg)

```
[![Health](https://phpackages.com/badges/mehr-it-levi-assets-linker/health.svg)](https://phpackages.com/packages/mehr-it-levi-assets-linker)
```

###  Alternatives

[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

343121.4M79](/packages/google-cloud-core)[aimeos/aimeos-base

Aimeos base layer for abstracting from host environments

2.1k134.0k1](/packages/aimeos-aimeos-base)[phpgt/dom

Modern DOM API.

12412.2M18](/packages/phpgt-dom)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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