Subscribe to PHP Freaks RSS

Tomáš Votruba: The Bulletproof Event Naming For Symfony Event Dispatcher

syndicated from www.phpdeveloper.org on July 21, 2017

In a recent post to his site Tomáš Votruba shares what he sees as a "bulletproof" event naming scheme for use with the Symfony event dispatcher component.

I wrote intro to SymfonyEventDispatcher and how to use it with simple event.

But when it comes to dispatching events, you can choose from 4 different ways. Which one to choose and why? Today I will show you pros and cons of them to make it easier for you.

He then breaks up the remainder of the post into the four suggestions, each with code examples and brief descriptions:

    1. Start with Stringly
    1. Group File with Events Names as Constants
    1. ...Constant Names in Particular Event Classes
    1. Class-based Event Naming

For each he also includes some "pros" and "cons" to help you select which one might work best for your usage. He ends by taking things "a step further" and sharing integrating a suggestion to remove an argument and simplify the code.