PSR-14 (Event manager)

379 views
Skip to first unread message

Barney Hanlon

unread,
Aug 15, 2017, 5:12:48 PM8/15/17
to PHP Framework Interoperability Group
Hello all,

and in my first post in this group, I thought I might query where we are at with event managers (PSR-14).

Recently, forgetting to check the FIG site, I hadn't realised there was already work on this and had started work on my own implementation of an Event-based standard, so that all listeners/events/dispatchers/emitters can play nicely. Obviously, far happier to go with an existing trend than try and reinvent a wheel. However, I'm not sure how to contribute in any way as a newbie to the mailing list.

I was inspired to sign up because I thought it would be good to debate further was the setParam() in the proposal - should events be mutable after instantiation, as part of the spec?

Hoping to hear back and would love to assist in this proposal.

--
Barney

Xedin Unknown

unread,
Mar 13, 2018, 5:04:44 AM3/13/18
to PHP Framework Interoperability Group
IMHO, looks like we are nowhere with the event manager standard. There are a handful of implementations, most very recent. Not aware of any consumers, besides my code.

I believe there are many things wrong with that standard. Right now, I'm working on a proposal of how it can be changed. Meanwhile, I am maintaining the interfaces in dhii/psr-14. Currently super tied down with time. So much so, in fact, that I have not had any chance to work on the standard, which I am a part of the workgroup for.

If any body is interested, here are my suggestions on PSR-14:

EventInterface
  • Add `setParam()`. It is super common that parameters are set one at a time, by name. Right now, they must be set altogether, which is extremely inconvenient.
  • Add `hasParam()`. This can allow the consumer to determine whether something is indeed set.
  • Document what happens with `getParam()` if the param is not set.
  • Remove `setName()` and `setTarget()`. After an even is created with a particular name and target, nothing should be able to change this. Just imagine that the name is changed after the event has been dispatched. This is nonsensical.
  • (Optional) Remove `setParams()` and `getParams()`. The event should probably allow operations on one parameter at a time, similarly to `ContainerInterface`. Allowing *all* params to be retrieved is not practical, as it would in many cases require the map to be iterable. This is a burden on the implementation. If there needs to be an iterable list of something, it can be passed safely as one of the parameters.
  • (Optional) Remove `getTarget()`. Why does there need to be a target? Or maybe, a more appropriate name for it is "source", as this is the context that the event comes *from*. If it needs to be passed, and is optional, why not just have it be one of the parameters?
EventManagerInterface
  • `trigger()` to accept only `EventInterface`, and not `string`. Why is it the concern of the event manager to normalize strings into events? This will make the logic simpler.
  • Remove `$argv` parameter from `trigger()`. If only `EventInterface` instances can be passed, this becomes redundant. Also, currently it is not documented what to pass in this parameter.
  • (Optional) Remove `$priority` parameter from `attach()`. With events, it is never clear what context this has. Priority as compared to what? How can it be possible to know what the other events' priorities are, so that I can put my event between them? This is a job for a module standard, which I happen to be working on.
@Barney, get in touch if you wanna help make a draft.

Barney Hanlon

unread,
Mar 13, 2018, 5:58:13 AM3/13/18
to php...@googlegroups.com
I would recommend that setParam or indeed any setting of properties be out of the spec. In my opinion, Events and Commands should both be immutable, but people are open to implement configuration post-construction if they wish. But if the spec defines these, then the spec is defining the payload of them as mutable. That doesn’t strike me as a good idea.

-- 
Barney Hanlon
--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/EwCZ9ritJcA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/9f44f49e-9f55-42e5-b8df-aee93c874007%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niels Braczek

unread,
Mar 13, 2018, 9:38:58 AM3/13/18
to php...@googlegroups.com
Am 13.03.2018 um 10:58 schrieb Barney Hanlon:

> I would recommend that setParam or indeed any setting of properties be out
> of the spec. In my opinion, Events and Commands should both be immutable,
> but people are open to implement configuration post-construction if they
> wish. But if the spec defines these, then the spec is defining the payload
> of them as mutable. That doesn’t strike me as a good idea.

+1

Regards,
Niels

--
| New Stars on the Horizon: GreenCape · nibralab · laJoom |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------

Benjamin Mack

unread,
Mar 13, 2018, 10:08:52 AM3/13/18
to php...@googlegroups.com
Hey folks,

I've been meaning to share my feedback for quite some time on that.

We've looked into different implementations a lot and we (TYPO3 dev) would only consider Event Manager if we're talking about immutable events. And event is triggered, could have parameters, but the event itself should not allow to alter parameters.

A classic example in our project is to change/modify values before storing them in a RDMS - this is not an event. Modifying a request object is not the job of an event listener. Of course, if you hand over objects as parameters, it's hard to enforce that they are kept as they are.
Events to modifying parameters is a different pattern, and we should aim to differentiate between them.

Once this is in the mind-set, an event (and event system) is actually very simple - also ordering is not _as_ important anymore (for our use-cases). However, it showed that an event system is only half of the business, and that it should be accompanied by a hooking system.

Basically we consider three different use cases:
- Events (Immutable) - "Hey, I just persisted something" then we could flush Caches
- Filters / Pipelines - "Here is some data, go and enrich it" - then we could have plugins of a framework modify or add metadata to the records, based on the current request.
- Filters / Interceptors - If one of the "listeners" actually says" no, you can't do that", the following action should not be called - like a permission system.

I'm happy to join the WG to make the PSR-14 as event manager ready, however, I do believe that we should start thinking more.

All the best,
Benni.
> --
> You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
> To post to this group, send email to php...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/9af851fb-a53b-8a3d-6b0c-f7b8012c98cf%40bsds.de.

Barney Hanlon

unread,
Mar 13, 2018, 10:26:47 AM3/13/18
to php...@googlegroups.com
Is this the right forum for putting forward examples of our own work as potential candidates? I’ve been working on one under the name event interop (much as PSR-11 was born from) but it seems we all have similar ideas. Shall we start showing some code examples?

-- 
Barney Hanlon
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/EwCZ9ritJcA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.

Larry Garfield

unread,
Mar 13, 2018, 5:58:35 PM3/13/18
to php...@googlegroups.com
Well, I've been talking about stepping forward to take over as PSR-14 Editor
for a few weeks now. I should probably go ahead and do it since there seems
to be interest.

Before we start showing code, I'd prefer to step back and define the specific
use cases we want to target. Benni's list below is a good starting point for
that discussion. That would probably be some discussion in Slack or similar
within the WG first. I would prefer to not use a separate GitHub group but we
can coordinate that with the secretaries.

Those who are interested in being part of an event dispatcher PSR-14 working
group (I suggest we change the name since "manager" is so pointlessly
generic), please ping me by email or Slack.

We also would then need another CC member to sponsor before we can formally
open a vote to reactivate the WG. Who's up for it?

Note: My time will be a bit scarce for the next week as I'm working for a
political campaign, but the election is next Tuesday so win or lose I should
have more time available at that point. :-)

--Larry Garfield

On Tuesday, March 13, 2018 9:26:40 AM CDT Barney Hanlon wrote:
> Is this the right forum for putting forward examples of our own work as
> potential candidates? I’ve been working on one under the name event interop
> (much as PSR-11 was born from) but it seems we all have similar ideas.
> Shall we start showing some code examples?
>
signature.asc

Stéphane Hulard

unread,
Mar 14, 2018, 12:49:14 PM3/14/18
to PHP Framework Interoperability Group
Hi Larry,

It'll be a first for me but I'll be glad to be part of the Event Dispatcher working group.

Kind regards
Stéphane

Barney Hanlon

unread,
Apr 25, 2018, 6:00:31 AM4/25/18
to php...@googlegroups.com
I cannot remember if I said I wanted to be part of this or not. The answer is yes, I definitely do, if I can help.

Kind regards,

Barney

--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/EwCZ9ritJcA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+unsubscribe@googlegroups.com.

To post to this group, send email to php...@googlegroups.com.

desig...@gmail.com

unread,
May 30, 2018, 7:18:00 AM5/30/18
to PHP Framework Interoperability Group
Hi Larry, 

I would like to be a part of this spec if it's still open for membership. I recently created BitFrame microframework which has an event manager based on the early/draft spec. I think I may be able to add some value to the project or be able to provide some insightful feedback.

Thanks!

Daniel Plainview

unread,
Jun 19, 2018, 8:23:41 PM6/19/18
to PHP Framework Interoperability Group
Reply all
Reply to author
Forward
0 new messages