Coming from ZF 1 to ZR 3. Lots of config?

Hi Everyone -

I decided to take a look at the latest ZF as I’ve been using 1.10.7 and it works great. Here’e where I’m confused.

I’m going through the tutorial and there’s so much more config when it comes to Controllers, ServiceManagers, etc… With ZF 1 I just instantiate a class and get my work done.

Anyone know why this is so laborious and why it’s a good idea. Also, is the a default configuration as ZF 1 had? For things such as routers?

Thanks,
Dave

Hi Dave,

Your subject says “ZR 3.”. Did you mean ZF3?

If so, that’s a common beginner question - and one that took me a long time to like the answer to.

Short answer is “testability”. I’m not familiar with ZF1, but I know ZF3 really emphasizes injecting what you need (Dependency Injection / Inversion of Control). This enables you to use mocks when testing. If things are “just instantiated”, unit tests become difficult or impossible.

“Maintainability” is probably another answer, with many things dependent on interfaces rather than implementations, factories become essential.

Not sure if that helps.

Greg

Also, it is a paradigm shift from “convention over configuration” to “configuration over convention”.

In “convention over configuration”, you name things in a certain way, or you drop them in a certain directory, and they “click together” because of that, but you need to know the locations, the rules, etc.

Also, the system falls apart if you try to move things around, even if you don’t change them.

This is very bad for testing and maintainability, because the rules are not enforced statically, but it’s some sort of “meta-language” defined by the framework of choice, and a framework change can break everything.

In “configuration over convention” you map things, and your configuration is authoritative. The configuration is then read from the tooling and used to assemble/run things. This means that you can write different configurations for different contexts (such as testing, as mentioned by Greg).

While more cumbersome, this makes it hard for things to break unless configuration interpretation changes (which should not happen).

Hope that helps :slight_smile: