ZF-7031: Zend_Loader_Autoloader_ServiceLoader

Issue Type: New Feature Created: 2009-06-16T15:06:00.000+0000 Last Updated: 2009-06-16T18:31:05.000+0000 Status: Resolved Fix version(s): Reporter: Mina R Waheeb (syncer) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Loader

Related issues: Attachments:


Hi, After version 1.8 and the new Autoloader system, I think we need Zend_Loader_Autoloader_ServiceLoader or PluginLoader, It will be more easy to plug and play service between modules for example the below workflow:

Module "admin" create Interface "Admin_Api_Registration"

Module "news" create class "News_Service_Administration" implements interface "Admin_Api_Registration"

Module "admin" creates new Zend_Loader_Autoloader_ServiceLoader("service","Administration");

Now Module admin can use foreach loader->getPlugins()



Posted by Matthew Weier O'Phinney (matthew) on 2009-06-16T17:15:18.000+0000

I fail to see how this differs from the current Zend_Loader_Autoloader_Resource and related Zend_Application_Module_Autoloader, which provide autoloading capabilities for precisely this sort of thing. Plugins may be autoloaded the same way as classes using this paradigm already.

Posted by Mina R Waheeb (syncer) on 2009-06-16T17:56:44.000+0000

The functionality already exist in the new Autoloader system, I'm talking about encapsulate it for loading across modules, maybe the below code explain more than me :)

<pre class="highlight">
$modules = Zend_Controller_Front::getInstance()->getControllerDirectory();
foreach (array_keys($modules) as $module) {
       $class = $this->_formatModuleName($module) . '_' . $this->_namespace . '_' . $this->_type;
        foreach(Zend_Loader_Autoloader::getInstance()->getClassAutoloaders($class) as $loader) {
                $types = $loader->getResourceTypes();
                 if(isset($types[$this->_namespace])) {
                      $path = $types[$this->_namespace]['path'] . '/' . str_replace('_', '/', $this->_type) . '.php';
                      if(is_file($path)) {
                          require_once $path;
                          if(!class_exists($class)) {
                              require_once 'Zend/Loader/Exception.php';
                              throw new Zend_Loader_Exception("Unable to find class: " . $class);
                          $this->_plugins[$module] = new $class();

Posted by Matthew Weier O'Phinney (matthew) on 2009-06-16T18:31:05.000+0000

Zend_Application_Module_Autoloader already fulfills this purpose.

If you use Zend_Application_Module_Bootstrap, it will create an instance of the above class that sets up a resource autoloader for that module; alternately, you can instantiate it yourself. Regardless, if used, you can then autoload that module's resources from anwywhere. As an example, if you have modules/foo/models/Bar.php with class 'Foo_Model_Bar', you can then simply instantiate the class: $bar = new Foo_Model_Bar(). This is easier and more intuitive than any other approach, and works cross-modules.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.