Home » Php » php – Use Zend Framework components without the actual framework?

php – Use Zend Framework components without the actual framework?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I was wondering if anyone knew how to use some components of the Zend Framework without having to actually use the framework. For example, I would like to use their Zend_Validate components, but don’t want the overhead of the framework as it’s a small one-page script.

Can this be easily done, and if so, are there guides/tutorials on how to accomplish it?

How to&Answers:

Zend framework components are intentionally designed to be loosely couple from the framework itself.

The component structure of Zend
Framework is somewhat unique; each
component is designed with few
dependencies on other components. This
loosely coupled architecture allows
developers to use components
individually. We often call this a
“use-at-will” design. [from here]

Here’s a tool for pulling out specific components and their dependencies to use in your application.

Answer:

I’ve just grabbed the whole Zend package, and used pieces of it. It always seems I end up using more of it as time goes on, so I keep it up to date even if I’m not using some of the MVC stuff in one project or another. Holding on to the whole thing makes you not have to worry about the dependencies (and how they might change down the road).

Answer:

Zend framework components while being loosely couple are still coupled. If you would to use Zend_Mail component for example – that would actually also require:

  1. Zend_Mime
  2. Zend_Exception
  3. Zend_Validation

Zend_Validation will be loaded for the mere reason of validating email address domain.

So – best bet would be to include entire Zend library. By pulling only several components – you’ll soon end up in “dependency hell” especially as API changes (though that doesn’t happen too often).

Also – starting from version 2.0 you must use some auto-loader to load Zend components as all require calls will be removed from PHP classes.