ZF1 Controller Factories

First of all. Yes, I know ZF1 is not supported any more, and yes, this question seems to be pointless. Nonetheless I want to ask this question. Maybe some one has done it and remembers.

We are currently refactoring a big old legacy ZF1 application. It has lots of really, really big controllers. We want to refactor it step by step to Zend\Expressive 3. One of the first steps is to add dependency injection in the old controllers to make the dependencies visible. So the question came up if it is possible to add controller factories to a ZF1 application. Me as the ZF1 expert says no and its pointless but the team asked me to clarify.

So, has anyone of you every managed to add controller factories to a ZF1 application? Is this even possible? I guess the only chance would be to build some kind of plugin or something.

I am really curious but I’m afraid it is not possible nor it makes sense even as a refactoring step.

I did that for zf1-> zf2 gradual refactoring. iirc i had to override dispatcher with my own version. I don’t remember all the details, but if you will find me working zf1 sample app I can try to recreate it over the weekend

If you are moving to a completely new framework, I highly endorse using the strangler pattern: quicker, more isolated and not-so-hacky migration to a new tool.

@ocramius Well, I already have installed Zend\Expressive 3 and let the legacy ZF1 application be processed by a middleware in the pipeline. If that MW cannot find any route, then the ZF1 application is run. We will move all stuff to ZE3 sooner or later. But the idea was to do a little tidy up in the ZF1 code base.

@xerkus Thanks for the idea of overwritten the dispatcher. I will look into it.

@RalfEggert I started repo for some zf1 overrides for easier migration: https://github.com/Roave/zf1-migration
I started with container, Bootstrap preferring container to fetch resources, initial dispatcher and controller manager.

It was quite a while since i did migrations last time and I don’t have real life applications to verify it works as intended, but may be it will have some useful pointers for your own usage :slight_smile:

1 Like

@xerkus thanks. That looks interesting. I will give it a try when I get the time.

You can also have a look at PHP-DI and its integration, that’s the way I usually go for progressive enhancement (it’s also overriding the dispatcher).

2 Likes

@tdutrion

Thanks for that tip. Looks really promising. I really like the approach as well. Maybe I will give it a try.