All Projects → yiisoft → yii-event

yiisoft / yii-event

Licence: BSD-3-Clause license
Events for Yii applications

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii-event

UnityEventAggregator
Simple event aggregation for Unity3D.
Stars: ✭ 30 (+150%)
Mutual labels:  events
tardis
Event sourcing toolkit
Stars: ✭ 35 (+191.67%)
Mutual labels:  events
data-response
www.yiiframework.com/
Stars: ✭ 12 (+0%)
Mutual labels:  yii3
ng2-events
Supercharge your Angular2+ event handling
Stars: ✭ 17 (+41.67%)
Mutual labels:  events
2020.djangocon.eu
🚃 The DjangoCon EU 2020 conference website
Stars: ✭ 16 (+33.33%)
Mutual labels:  events
data
Data providers
Stars: ✭ 31 (+158.33%)
Mutual labels:  yii3
yii-debug
Yii debug panel extension
Stars: ✭ 23 (+91.67%)
Mutual labels:  yii3
db-elasticsearch
Yii Framework Elasticsearch Query and ActiveRecord
Stars: ✭ 12 (+0%)
Mutual labels:  yii3
go-graphql-subscription-example
☝️ go-graphql subscription over Kafka/Redis/NSQ example
Stars: ✭ 34 (+183.33%)
Mutual labels:  events
trainmanjs
TrainmanJS - Cross-Origin Communication Library
Stars: ✭ 16 (+33.33%)
Mutual labels:  events
EasyEventEditor
Drop in replacement for the default Unity event editor drawer that allows listener reordering
Stars: ✭ 103 (+758.33%)
Mutual labels:  events
db-redis
Yii DBAL Redis connection
Stars: ✭ 14 (+16.67%)
Mutual labels:  yii3
Timespace
A jQuery plugin to handle displaying of time events
Stars: ✭ 27 (+125%)
Mutual labels:  events
evon
Fast and versatile event dispatcher code generator for Golang
Stars: ✭ 15 (+25%)
Mutual labels:  events
html
Handy library to generate HTML
Stars: ✭ 42 (+250%)
Mutual labels:  yii3
event-horizon
Custom global event firing/subscribing in GameMaker: Studio 2
Stars: ✭ 16 (+33.33%)
Mutual labels:  events
EventEmitter
Simple EventEmitter with multiple listeners
Stars: ✭ 19 (+58.33%)
Mutual labels:  events
pholiday
a persian calendar holidays library for javascript
Stars: ✭ 38 (+216.67%)
Mutual labels:  events
router-fastroute
Yii Router FastRoute adapter
Stars: ✭ 36 (+200%)
Mutual labels:  yii3
vip-git
💊 Automated "hey" · ·👋 · · of the day. Every day a unique historic event is generated based on the given day.
Stars: ✭ 4 (-66.67%)
Mutual labels:  events

Yii Event


Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

This package is a configuration wrapper for the yiisoft/event-dispatcher package. It is intended to make event listener declaration simpler than you could ever imagine. All you need is to use any PSR-11 compatible DI container.

Requirements

  • PHP 7.4 or higher.

Installation

The package could be installed with composer:

composer require yiisoft/yii-event --prefer-dist

General usage

DI configuration

You can see a config example in the config directory:

All these configs will be used automatically in projects with the yiisoft/config.

Event configuration example

The configuration is an array where keys are event names and values are array of handlers:

return [
    EventName::class => [
        // Just a regular closure, it will be called from the Dispatcher "as is".
        static fn (EventName $event) => someStuff($event),
        
        // A regular closure with additional dependency. All the parameters after the first one (the event itself)
        // will be resolved from your DI container within `yiisoft/injector`.
        static fn (EventName $event, DependencyClass $dependency) => someStuff($event),
        
        // An example with a regular callable. If the `staticMethodName` method contains some dependencies,
        // they will be resolved the same way as in the previous example.
        [SomeClass::class, 'staticMethodName'],
        
        // Non-static methods are allowed too. In this case `SomeClass` will be instantiated by your DI container.
        [SomeClass::class, 'methodName'],
        
        // An object of a class with the `__invoke` method implemented
        new InvokableClass(),
        
        // In this case the `InvokableClass` with the `__invoke` method will be instantiated by your DI container
        InvokableClass::class,
        
        // Any definition of an invokable class may be here while your `$container->has('the definition)` 
        'di-alias'
    ],
];

The dependency resolving is done in a lazy way: dependencies will not be resolved before the corresponding event will happen.

Configuration checker

To help you with event listener configuration validation there is the ListenerConfigurationChecker. It is converting your whole listener config to actual callables at once to validate it. It is intended to be used in development environment or in tests since it is a resource greedy operation in large projects. An InvalidEventConfigurationFormatException will be thrown if your configuration contains an invalid listener.

Usage example:

$checker->check($configuration->get('events-web'));

Testing

Unit testing

The package is tested with PHPUnit. To run tests:

./vendor/bin/phpunit

Mutation testing

The package tests are checked with Infection mutation framework with Infection Static Analysis Plugin. To run it:

./vendor/bin/roave-infection-static-analysis-plugin

Static analysis

The code is statically analyzed with Psalm. To run static analysis:

./vendor/bin/psalm

License

The Yii Event is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].