Sorry, I use descending sort on priority it looks like which is what I've seen in the other event systems I looked at as well. Think the first one I noticed it in was the one in Synfony. Here's the method I use for converting to int priority of my library.
https://github.com/Dragonrun1/event-mediator/blob/master/src/Mediator.php#L237 and where I sort by priority before calling them https://github.com/Dragonrun1/event-mediator/blob/master/src/Mediator.php#L303 Also if anyone is interested in seeing how I extend and use it in one of my other projects take a look at https://github.com/Yapeal/yapeal-ng/tree/master/lib/Event I wasn't aware of this PSR at the time and wanted something lighter weight and without the dependence hell than Synfony's event system has become so I made my own. If this PSR does move forward again I'll look at either change my code to be compatible or at least try to add an adapter to my library for people to use. My hope is that at least some of my suggestions from above make sense to everyone and become part of the PSR and are implemented by others as well but only time will tell on that. You are right adding 'first' and 'last' does mean you do end up with mixed type parameter which is why I didn't put it in my proposed changes above but it would be easy to add a method in any implementation or even the PSR for using them. Something like attachFirst(), attachLast() or attachWithPriorityString() would work. IMHO if added to the PSR the first two attach*() probably would be best if it's decided the methods should all allow PHP 7 strong typing. I almost made that change to my library once PHP7 came out but decided to wait a little longer. On Monday, September 12, 2016 at 11:00:37 AM UTC-7, Benni Mack wrote: > > Hey Michael, > > thanks for the reply. OK. so just to understand - the intention of the > "priority" is > "1" = first one > "2" = after that one > > and not the listeners with the highest (e.g. 100) priority comes first? I > think this should be clarified then. > > I like the "first" and "last" idea, however, that makes the PHP code of > the interface kind of "mixed" (allowing string and ints). > > Should I add some remarks / examples of the priority topic to the proposal > as PR? > > All the best, > Benni. > > > On 12.09.2016, at 19:18, Michael Cummings <[email protected] > <javascript:>> wrote: > > Most of the implementations I've seen call listeners in the order they are > added when priorities are the same which is how I've also done it in my > projects. The additional feature I've found useful is allowing 'first' and > 'last' keywords for the priority when adding listeners but I'm not sure if > that should really be in the PSR or not. I can see where depending on > implementation figuring out and possibly having to reorder the listeners > could be hard to do but if everyone likes the idea it might be useful. Just > to make it clear the way I implemented it 'first' and 'last' are based on > the state at the time the listener is being added and not when the event is > called. > > For example say there are already a couple of listeners with priorities of > 10 and 20 and you use 'last' for another listener it will be given a > priority of 21 and if you added another listener with 'last' it would end > up with priority of 22 etc. If you then added one with 'first' it would be > assigned 9. I use this to add default listeners for events while allowing > users to add other listeners to override the defaults by adding them > beforehand or using 'first' and choose to handle or not. By doing this the > actual priority becomes mostly an implementation detail and I only need to > worry about order things are added and not some random magic number 😋. The > main thing is the PSR should allow as much flexibility it can while still > being detailed enough to allow make sure implementations can be > interchanged which is why I thought int was best as it should not cause any > real limits for anyone. > > > > > > On Mon, Sep 12, 2016 at 8:09 AM, Benni Mack <[email protected] > <javascript:>> wrote: > >> Hey Brian, >> >> we're from TYPO3 (CMS) are currently overhauling our event system and are >> following the PSR quite closely, almost implementing it 1:1 for our CMS - >> however the stagnation of the PSR doesn't bring some confidence that this >> PSR is ever going to happen. However, we'd love to contribute in order to >> actually make it possible to have our Event system interchangeable with >> other systems. >> >> Some remarks on the proposal: >> * Should we give a range for the "priority" (0-100 ?) otherwise it feels >> like the HTML/CSS "z-index" which I just set to 4000 and will be higher >> than all the others - until another framework thinks the same ;) - This is >> a bit different approach than Michael's remarks, however it'd be useful >> have that cleared up. >> * What happens if a listener adds itself to an event but an existing >> listener has the same priority? Is there an exception going to be thrown? >> Graceful "upping" or "downing" the priorities? First come / first serve? We >> should probably just have that cleared up and written down. >> >> All the best, >> Benni. >> >> -- >> 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/-EJOStgxAwY/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/php-fig/c4ccbc90-7358-42a3-905b-097b0da7d0a7%40googlegroups.com >> >> <https://groups.google.com/d/msgid/php-fig/c4ccbc90-7358-42a3-905b-097b0da7d0a7%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > 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 [email protected] <javascript:>. > To post to this group, send email to [email protected] <javascript:> > . > To view this discussion on the web visit > https://groups.google.com/d/msgid/php-fig/CAP9GSfWYk0zabs9GOKUGpMWb3_vNvaGnDO8NxPp_0kyATqOYVw%40mail.gmail.com > > <https://groups.google.com/d/msgid/php-fig/CAP9GSfWYk0zabs9GOKUGpMWb3_vNvaGnDO8NxPp_0kyATqOYVw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/787fc3de-b099-450d-8e2f-652466f5b8e0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
