PHPackages                             whsv26/mediator - 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. whsv26/mediator

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

whsv26/mediator
===============

2.0.1(4y ago)437PHP

Since Dec 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/whsv26/mediator)[ Packagist](https://packagist.org/packages/whsv26/mediator)[ RSS](/packages/whsv26-mediator/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (9)Versions (7)Used By (0)

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

[](#installation)

```
$ composer require whsv26/mediator
```

Bundle configuration
--------------------

[](#bundle-configuration)

```
// config/packages/mediator.php

return static function (MediatorConfig $config) {
    $config->bus()
        ->query('query.bus') // query bus service id
        ->command('command.bus') // command bus service id
        ->event('event.bus'); // event bus service id
};
```

### Enable psalm plugin (optional)

[](#enable-psalm-plugin-optional)

To check command and query return type compatibility with corresponding handler return type

```
$ vendor/bin/psalm-plugin enable Whsv26\\Mediator\\Psalm\\Plugin
```

Commands
--------

[](#commands)

```
/**
 * @implements CommandInterface
 */
class CreateUserCommand implements CommandInterface
{
    public function __construct(
        public readonly string $email,
        public readonly string $password,
    ) { }
}

class CreateUserCommandHandler implements MessageHandlerInterface
{
    public function __construct(
        private readonly UserRepository $users,
        private readonly HasherInterface $hasher,
        private readonly ClockInterface $clock,
        private readonly MediatorInterface $mediator,
    ) { }

    public function __invoke(CreateUserCommand $command): UserId
    {
        $user = new User(
            UserId::next(),
            new Email($command->email),
            new PlainPassword($command->password),
            $this->hasher,
            $this->clock
        );

        $this->users->save($user);

        // Publish domain events to subscribers
        $this->mediator->publish($user->pullDomainEvents());

        return $user->getId();
    }
}

class CreateUserAction
{
    public function __construct(
        private readonly MediatorInterface $mediator
    ) { }

    #[Route(path: '/users', name: self::class, methods: ['POST'])]
    public function __invoke(CreateUserCommand $createUser): string
    {
        // $createUser deserialized from request body
        // via custom controller argument value resolver

        return $this->mediator
            ->sendCommand($createUser)
            ->value;
    }
}
```

Queries
-------

[](#queries)

```
/**
 * @implements QueryInterface
 */
class FindUserQuery implements QueryInterface
{
    public function __construct(
        public readonly ?string $id = null,
        public readonly ?string $email = null,
    ) { }
}

class FindUserQueryHandler implements MessageHandlerInterface
{
    public function __construct(
        private readonly UserRepository $users,
    ) { }

    /**
     * @param FindUserQuery $query
     * @return Option
     */
    public function __invoke(FindUserQuery $query): Option
    {
        return Option::fromNullable($query->id)
            ->map(fn(string $id) => new UserId($id))
            ->flatMap(fn(UserId $id) => $this->users->findById($id))
            ->orElse(fn() => Option::fromNullable($query->email)
                ->map(fn(string $email) => new Email($email))
                ->flatMap(fn(Email $email) => $this->users->findByEmail($email))
            );
    }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

5

Last Release

1588d ago

Major Versions

v0.1.0 → 1.0.0-RC12021-12-27

1.0.0 → 2.0.02022-01-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/81545cf6f2a087daa73d7d05a8b419fb5af1fdea6d9645682e5c38006666f684?d=identicon)[whsv26](/maintainers/whsv26)

---

Top Contributors

[![whsv26](https://avatars.githubusercontent.com/u/11776521?v=4)](https://github.com/whsv26 "whsv26 (69 commits)")

---

Tags

cqrsdddmediator-patternsymfonysymfony-bundlesymfony-messenger

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/whsv26-mediator/health.svg)

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

PHPackages © 2026

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