PHPackages                             bizley/mercure-behavior - 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. bizley/mercure-behavior

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

bizley/mercure-behavior
=======================

Yii 2 Mercure behavior.

1.0.1(6y ago)4192[1 PRs](https://github.com/bizley/mercure-behavior/pulls)Apache-2.0PHPPHP &gt;=7.2.0

Since Sep 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bizley/mercure-behavior)[ Packagist](https://packagist.org/packages/bizley/mercure-behavior)[ RSS](/packages/bizley-mercure-behavior/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

mercure-behavior
================

[](#mercure-behavior)

[![Latest Stable Version](https://camo.githubusercontent.com/5aed62ad436a20404d4310abd9ce49ccb598c186362e4d9e600375bd180a3aac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62697a6c65792f6d6572637572652d6265686176696f72)](https://camo.githubusercontent.com/5aed62ad436a20404d4310abd9ce49ccb598c186362e4d9e600375bd180a3aac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62697a6c65792f6d6572637572652d6265686176696f72)[![Total Downloads](https://camo.githubusercontent.com/a973f296b380df9febd96da792e2df8726541d1bfe88c3494f0739854f6c20fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62697a6c65792f6d6572637572652d6265686176696f72)](https://packagist.org/packages/bizley/mercure-behavior)[![License](https://camo.githubusercontent.com/7b0ca874bc2578750d2bb4586ffd7452ceb799ba6f9ab465deea0072e60cb305/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62697a6c65792f6d6572637572652d6265686176696f72)](https://camo.githubusercontent.com/7b0ca874bc2578750d2bb4586ffd7452ceb799ba6f9ab465deea0072e60cb305/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62697a6c65792f6d6572637572652d6265686176696f72)

Yii 2 Mercure behavior
----------------------

[](#yii-2-mercure-behavior)

This package provides Yii 2 behavior to automatically publish updates to the Mercure hub when resource is being modified.
The purpose of this behavior is to equip Yii application with the same Mercure functionality as given by [API Platform](https://api-platform.com/docs/core/mercure/).

What is Mercure?
----------------

[](#what-is-mercure)

Quoting [dunglas/mercure](https://github.com/dunglas/mercure):

> Mercure is a protocol allowing to push data updates to web browsers and other HTTP clients in a convenient, fast, reliable and battery-efficient way. It is especially useful to publish real-time updates of resources served through web APIs, to reactive web and mobile apps.

See the linked repository to find out more about Mercure. There are also instructions how to set up the server and the client to establish connection using Mercure protocol.

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

[](#installation)

Add the package to your `composer.json`:

```
{
    "require": {
        "bizley/mercure-behavior": "^1.0"
    }
}

```

and run `composer update` or alternatively run `composer require bizley/mercure-behavior:^1.0`

You will of course need Mercure Hub as well. Refer to [dunglas/mercure](https://github.com/dunglas/mercure) for the instructions how to get one (I recommend using Docker image).

Usage
-----

[](#usage)

Add this [behavior](https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors) to the resource object you want to be subject of Mercure updates (usually it's an Active Record instance).

```
use \bizley\yii2\behaviors\mercure\MercureBehavior;

public function behaviors()
{
    return [
        MercureBehavior::class,
    ];
}
```

Resource object must implement `\bizley\yii2\behaviors\mercure\MercureableInterface`.
By default MercureBehavior will dispatch update to Mercure Hub in JSON format after the resource has been successfully created, updated, or deleted, using the Mercure publisher component registered under the 'publisher' name.

You can customize the configuration according to your needs, for example:

```
public function behaviors()
{
    return [
        [
            'class' => MercureBehavior::class,
            'publisher' => \bizley\yii2\mercure\Publisher::class,
            'format' => \yii\web\Response::FORMAT_XML
        ]
    ];
}
```

Publishing the updates
----------------------

[](#publishing-the-updates)

The behavior is using [yii2-mercure](https://github.com/bizley/yii2-mercure) package for publishing the updates.
Please follow the repository link to learn how to configure it properly.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~0 days

Total

2

Last Release

2470d ago

### Community

Maintainers

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

---

Top Contributors

[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

behaviorhacktoberfestmercureyii2mercureyii2BehaviorBroadcast

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bizley-mercure-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/bizley-mercure-behavior/health.svg)](https://phpackages.com/packages/bizley-mercure-behavior)
```

###  Alternatives

[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1831.2k](/packages/mdmsoft-yii2-autonumber)[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1175.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)[asinfotrack/yii2-audittrail

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

1627.3k](/packages/asinfotrack-yii2-audittrail)[valentinek/yii2-closure-table-behavior

This extension allows you to get functional for closure table trees.

1615.4k](/packages/valentinek-yii2-closure-table-behavior)[v0lume/yii2-meta-tags

DB based model meta data for SEO

194.1k](/packages/v0lume-yii2-meta-tags)

PHPackages © 2026

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