Note that there are some explanatory texts on larger screens.

plurals
  1. POZF Autoloader to load ancestor and requested class
    text
    copied!<p>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 <code>include()</code> statements.</p> <p>I have a specific requirement for the autoloading mechanism, though. Allow me to elaborate.</p> <p>The existing application uses a core library (independent from ZF), for example:</p> <pre><code>/Core/Library/authentication.php /Core/Library/translation.php /Core/Library/messages.php </code></pre> <p>this core library is to remain untouched at all times and serves a number of applications. The library contains classes like</p> <pre><code>class ancestor_authentication { ... } class ancestor_translation { ... } class ancestor_messages { ... } </code></pre> <p>in the <em>application</em>, there is also a Library directory:</p> <pre><code>/App/Library/authentication.php /App/Library/translation.php /App/Library/messages.php </code></pre> <p>these includes extend the ancestor classes and are the ones that actually get instantiated in the application.</p> <pre><code>class authentication extends ancestor_authentication { } class translation extends ancestor_translation { } class messages extends ancestor_messages { } </code></pre> <p>usually, these class definitions are empty. They simply extend their ancestors and provide the class name to instantiate.</p> <pre><code>$authentication = new authentication(); </code></pre> <p>The purpose of this solution is to be able to easily customize aspects of the application without having to patch the core libraries.</p> <p>Now, the autoloader I need would have to be aware of this structure. When an object of the class <code>authentication</code> is requested, the autoloader would have to:</p> <pre><code>1. load /Core/Library/authentication.php 2. load /App/Library/authentication.php </code></pre> <p>My current approach would be creating a custom function, and binding that to <code>Zend_Loader_Autoloader</code> for a specific namespace prefix.</p> <ul> <li><p>Is there already a way to do this in Zend that I am overlooking? The accepted answer in <a href="https://stackoverflow.com/questions/304323/integrating-external-scripts-with-zend-framework">this question</a> kind of implies there is, but that may be just a bad choice of wording.</p></li> <li><p>Are there extensions to the Zend Autoloader that do this? </p></li> <li><p>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 <code>xyz</code> method that you would call like this...) would already be enough.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload