ZF Autoloader to load ancestor and requested class

Posted by Pekka on Stack Overflow See other posts from Stack Overflow or by Pekka
Published on 2010-03-16T11:40:42Z Indexed on 2010/03/16 11:56 UTC
Read the original article Hit count: 230

Filed under:
|
|

I am integrating Zend Framework into an existing application. I want to switch the application over to Zend's autoloading mechanism to replace dozens of include() statements.

I have a specific requirement for the autoloading mechanism, though. Allow me to elaborate.

The existing application uses a core library (independent from ZF), for example:

/Core/Library/authentication.php
/Core/Library/translation.php
/Core/Library/messages.php

this core library is to remain untouched at all times and serves a number of applications. The library contains classes like

class ancestor_authentication { ... }
class ancestor_translation { ... }
class ancestor_messages { ... }

in the application, there is also a Library directory:

/App/Library/authentication.php
/App/Library/translation.php
/App/Library/messages.php

these includes extend the ancestor classes and are the ones that actually get instantiated in the application.

class authentication extends ancestor_authentication { }
class translation extends ancestor_translation { }
class messages extends ancestor_messages { }

usually, these class definitions are empty. They simply extend their ancestors and provide the class name to instantiate.

$authentication = new authentication();

The purpose of this solution is to be able to easily customize aspects of the application without having to patch the core libraries.

Now, the autoloader I need would have to be aware of this structure. When an object of the class authentication is requested, the autoloader would have to:

1. load  /Core/Library/authentication.php
2. load  /App/Library/authentication.php

My current approach would be creating a custom function, and binding that to Zend_Loader_Autoloader for a specific namespace prefix.

  • Is there already a way to do this in Zend that I am overlooking? The accepted answer in this question kind of implies there is, but that may be just a bad choice of wording.

  • Are there extensions to the Zend Autoloader that do this?

  • Can you - I am new to ZF - think of an elegant way, conforming with the spirit of the framework, of extending the Autoloader with this functionality? I'm not necessary looking for a ready-made implementation, some pointers (This should be an extension to the xyz method that you would call like this...) would already be enough.

© Stack Overflow or respective owner

Related posts about php

Related posts about php5