Comments (4)
What sort of action would you want to be fired on every db event? I can see the usefulness of this, but I was wondering what real-world problem you are having now and if a workaround may be more appropriate.
from event.
Hey,
The database example is just one possible use case.
The real world use case that I have is for application monitoring metrics. ie. In an API library, we want to track how many times an event was triggered or how long the event took.
For instance in an application, we prefix all calls relating to API library as "client.api.". WIth that we want to record when this event was triggered with a record call to StatsD/Graphite as count. We have a separate prefix for timing ie. "client.timing.api.".
The current workaround I have done is to so far use the all wildcard "*" to catch ALL events being handled by the Emitter instance. I then manually decide if that event is part of that prefix and record. This method works so far but I have reservations on the performance of this, hence why I would prefer a support for partial wildcards.
from event.
Well, I threw together a very small patch that adds this functionality. Its on my fork at https://github.com/chrismichaels84/event/tree/chrismichaels84-wildcards. Be sure to use the wildcards branch.
I only added a few lines to src/Emmitter.php inside the emit()
method and then added a helper (getWildcard()
) inside AbstractEvent.
So now, the following works as expected:
$emitter = new League\Event\Emitter();
// Standard listener
$emitter->addListener('app.action.db.standard', function($event, $param) {
echo "this is the listener for app.action.db.standard";
});
$emitter->emit('app.action.db.standard', 1);
// Wildcards
$emitter->addListener('app.action.db.*', function($event, $param) {
echo "This will fire everytime any app.action.db event is fired."
echo "This event wildcard was: " . $event->getWildcard();
});
$emitter->emit('app.action.db.here', 2);
$emitter->emit('app.action.db.there', 3);
$emitter->emit('app.action.db.everywhere', 4);
I haven't wrote any tests yet, but this doesn't break any existing tests. Lemme know if you have any feedback.
from event.
This is something I don't have planned for this package, nor see fit in the future. It's very inexpensive to register a listener to multiple events. Since there are already *
listeners it could be handled within the listener anyway.
from event.
Related Issues (20)
- Double invoked events with name same as their classname HOT 5
- How do you remove listeners?
- php 8.4 deprecations
- [docs] Typo in event/2.0/generator/trait.md
- Question: Can the Emitter be made ContainerAware? HOT 3
- Additional Arguments throw exception when using AbstractListener HOT 7
- Upcoming PSR HOT 3
- waitFor method HOT 4
- Ditch EventInterface HOT 5
- What is this repository for? HOT 1
- BufferedEmitter as service HOT 1
- Has this package been abandoned? HOT 2
- Fatal error: Uncaught Error: Class 'League\Event\Emitter' not found HOT 1
- New release? HOT 6
- Add the ability to have wildcard listener to be fired before all other listeners HOT 1
- Upgrade from 2 to 3 documentation is... incomplete... HOT 1
- What would be proper approach to add information to an event? HOT 2
- Stoppable Events HOT 5
- Is it possible to provide a working example? HOT 1
- Documentation issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from event.