Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to customize ExecutionLoop Listeners #565

Open
IonBazan opened this issue Jul 24, 2019 · 3 comments
Open

Enable to customize ExecutionLoop Listeners #565

IonBazan opened this issue Jul 24, 2019 · 3 comments

Comments

@IonBazan
Copy link

Currently it is no easy way to customize the execution loop listeners.
I managed to do that by extending Psy\Shell and overriding getDefaultLoopListeners() method:

namespace App\Console\Shell;

use Psy\Shell;

class MyShell extends Shell
{
    protected function getDefaultLoopListeners()
    {
        $listeners = [new MyLoopListener()];

        return array_merge($listeners, parent::getDefaultLoopListeners());
    }
}

but that doesn't seem like a clean solution. I think we should enable users to customize them via constructor or addLoopListener()/setLoopListeners() methods following addMatchers() and addTabCompletionMatchers() methods convention so the code would become:

$shell = new Shell();
$shell->addLoopListener(new MyLoopListener());

@bobthecow WDYT?

@bobthecow
Copy link
Owner

I understand what you want, but can you share a bit more about why? 🙂

@IonBazan
Copy link
Author

I was trying to log every beforeRun, onExecute and afterRun event. I ended up creating a class inheriting the Shell and overriding these methods to add such behavior but it is not that flexible (composition over inheritance).

@bobthecow
Copy link
Owner

Right, but why? I still don’t understand your use case. I’m not opposed to opening up more extension points, but there is a maintenance and support cost associated, and this one hasn’t happened because I haven’t seen a good reason for it yet.

As a ___________ I want to ___________ so that ___________

🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants