# ZF1 Controller Factories

**URL:** <https://discourse.laminas.dev/t/zf1-controller-factories/605>\
**Category:** Components & MVC\
**Tags:** zf1\
**Created:** [June 8, 2018, 4:23am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605 "2018-06-08T04:23:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![RalfEggert](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ralfeggert/32/76_2.png) [@RalfEggert](https://discourse.laminas.dev/u/RalfEggert)\
**Post date:** [June 8, 2018, 4:23am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/1 "2018-06-08T04:23:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xerkus](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/xerkus/32/22_2.png) [@xerkus](https://discourse.laminas.dev/u/xerkus)\
**Post date:** [June 8, 2018, 5:55am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/2 "2018-06-08T05:55:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ocramius](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ocramius/32/23_2.png) [@ocramius](https://discourse.laminas.dev/u/ocramius)\
**Post date:** [June 8, 2018, 7:03am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/3 "2018-06-08T07:03:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RalfEggert](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ralfeggert/32/76_2.png) [@RalfEggert](https://discourse.laminas.dev/u/RalfEggert)\
**Post date:** [June 8, 2018, 7:22am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/4 "2018-06-08T07:22:24Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![RalfEggert](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ralfeggert/32/76_2.png) [@RalfEggert](https://discourse.laminas.dev/u/RalfEggert)\
**Post date:** [June 8, 2018, 7:23am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/5 "2018-06-08T07:23:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xerkus](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/xerkus/32/22_2.png) [@xerkus](https://discourse.laminas.dev/u/xerkus)\
**Post date:** [June 11, 2018, 8:41pm UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/6 "2018-06-11T20:41:12Z")

</div>

@RalfEggert I started repo for some zf1 overrides for easier migration: [https://github.com/Roave/zf1-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 🙂

---

<div class="post-metadata">

**Author:** ![RalfEggert](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ralfeggert/32/76_2.png) [@RalfEggert](https://discourse.laminas.dev/u/RalfEggert)\
**Post date:** [June 12, 2018, 8:04am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/7 "2018-06-12T08:04:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tdutrion](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/tdutrion/32/44_2.png) [@tdutrion](https://discourse.laminas.dev/u/tdutrion)\
**Post date:** [June 14, 2018, 10:15pm UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/8 "2018-06-14T22:15:59Z")

</div>

You can also have a look at [PHP-DI and its integration](https://github.com/PHP-DI/ZF1-Bridge), that’s the way I usually go for progressive enhancement (it’s also overriding the dispatcher).

---

<div class="post-metadata">

**Author:** ![RalfEggert](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ralfeggert/32/76_2.png) [@RalfEggert](https://discourse.laminas.dev/u/RalfEggert)\
**Post date:** [June 15, 2018, 4:08am UTC](https://discourse.laminas.dev/t/zf1-controller-factories/605/9 "2018-06-15T04:08:11Z")

</div>

@tdutrion

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