PHPackages                             heimrichhannot/contao-encore-contracts - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. heimrichhannot/contao-encore-contracts

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

heimrichhannot/contao-encore-contracts
======================================

A set of abstractions needed for encore bundle preparation.

1.5.0(3w ago)030.4k↓24.7%20LGPL-3.0-or-laterPHPPHP ^8.0CI passing

Since Oct 4Pushed 3d ago5 watchersCompare

[ Source](https://github.com/heimrichhannot/contao-encore-contracts)[ Packagist](https://packagist.org/packages/heimrichhannot/contao-encore-contracts)[ Docs](https://github.com/heimrichhannot/contao-encore-contracts)[ RSS](/packages/heimrichhannot-contao-encore-contracts/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (20)

Contao Encore Contracts
=======================

[](#contao-encore-contracts)

This package contains abstractions to add loose [Encore bundle](https://github.com/heimrichhannot/contao-encore-bundle) support.

Usage
-----

[](#usage)

### Register entrypoints

[](#register-entrypoints)

To register encore entrypoints create an EncoreExtension class implementing `EncoreExtensionInterface`.

```
namespace HeimrichHannot\ExampleBundle\Asset;

use HeimrichHannot\EncoreContracts\EncoreEntry;
use HeimrichHannot\EncoreContracts\EncoreExtensionInterface;
use HeimrichHannot\ExampleBundle\HeimrichHannotExampleBundle;

class EncoreExtension implements EncoreExtensionInterface
{
    public function getBundle(): string
    {
        // Return the bundle class
        return HeimrichHannotExampleBundle::class;
    }

    public function getEntries(): array
    {
        // Return the bundle entries
        return [
            EncoreEntry::create('main-theme', 'assets/main/js/main-theme.js')
                ->setRequiresCss(true)
                ->setIsHeadScript(false),
            EncoreEntry::create('one-pager', 'assets/one-pager/js/one-pager.js')
                ->setRequiresCss(true),
            EncoreEntry::create('custom-head-js', 'assets/main/js/head.js')
                ->setIsHeadScript(true)
                // Define entries that will be removed from the global asset array
                ->addJsEntryToRemoveFromGlobals('colorbox')
                ->addCssEntryToRemoveFromGlobals('css-to-replace'),
                ->setDefer(true)
        ];
    }
}
```

### Add entrypoints for current page

[](#add-entrypoints-for-current-page)

To add entrypoints (must be registered beforehand) from your code, you can use the `PageAssetsTrait`. It checks if encore bundle is installed and add the entry, if this is the case. Otherwise, it adds the fallback assets to the contao global asset array.

Make your class implement `ServiceSubscriberInterface` and use `PageAssetsTrait` (it already implements the needed methods for the ServiceSubscriberInterface). Afterwards just call `$this->addPageEntrypoint(string $name, array $fallbackAssets = [])`.

```
use HeimrichHannot\EncoreContracts\PageAssetsTrait;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

class FrontendController implements ServiceSubscriberInterface
{
    use PageAssetsTrait;

    public function __invoke()
    {
        $this->addPageEntrypoint(
            // Encore entry point name
            'contao-example-bundle',
             // Optional: define fallback assets to use if encore bundle is not installed
            [
                'TL_CSS' => ['main-theme' => 'assets/main/dist/main-theme.min.css|static'],
                'TL_JAVASCRIPT' => [
                    'main-theme' => 'assets/main/dist/main-theme.min.js|static',
                    'some-dependency' => 'assets/some-dependency/some-dependency.min.js|static',
                ],
            ]
        );
    }
}
```

If implementing the `ServiceSubscriberInterface` is not possible, you can use the `AddPageEntrypointTrait`, which also provides the `addPageEntrypoint` method, but requires you to implement the `getFrontendAsset` method, which should return the `FrontendAsset` service object.

```
use HeimrichHannot\EncoreBundle\Asset\FrontendAsset;
use HeimrichHannot\EncoreContracts\AddPageEntrypointTrait;

class MyService
{
    use AddPageEntrypointTrait;

    public function __construct(private readonly FrontendAsset $frontendAsset) {}

    protected function getFrontendAsset(): FrontendAsset
    {
        return $this->frontendAsset;
    }

    public function myAction()
    {
        $this->addPageEntrypoint(
            // Encore entry point name
            'contao-example-bundle'
        );
    }
}
```

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance97

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 51.4% 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 ~134 days

Recently: every ~13 days

Total

11

Last Release

25d ago

PHP version history (2 changes)1.0.0PHP ^7.4 || ^8.0

1.2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/28ad3224d8727b622ebd229840eea6b9dbcb83eb0bd609e6ce65b614830ff538?d=identicon)[digitales@heimrich-hannot.de](/maintainers/digitales@heimrich-hannot.de)

---

Top Contributors

[![koertho](https://avatars.githubusercontent.com/u/12064642?v=4)](https://github.com/koertho "koertho (19 commits)")[![ericges](https://avatars.githubusercontent.com/u/25957923?v=4)](https://github.com/ericges "ericges (17 commits)")[![heimrich-hannot](https://avatars.githubusercontent.com/u/37208441?v=4)](https://github.com/heimrich-hannot "heimrich-hannot (1 commits)")

### Embed Badge

![Health badge](/badges/heimrichhannot-contao-encore-contracts/health.svg)

```
[![Health](https://phpackages.com/badges/heimrichhannot-contao-encore-contracts/health.svg)](https://phpackages.com/packages/heimrichhannot-contao-encore-contracts)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B13.9k](/packages/symfony-console)[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k373.5M3.3k](/packages/symfony-cache)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k177.2M382](/packages/symfony-security-http)[symfony/doctrine-bridge

Provides integration for Doctrine with various Symfony components

3.2k200.7M873](/packages/symfony-doctrine-bridge)

PHPackages © 2026

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