ZF-6694: Patch to load plugins with priority in Zend_Application_Resource_FrontController

Description

Currently there is no option to configure the priority of front controller plugins loaded via Zend_Application_Resource_FrontController

The suppied patch, or a similar piece of code would allow the following config file options

resources.frontController.plugins.foo = "My_Plugin_Foo"
resources.frontController.plugins.foo.class = "My_Plugin_Foo"
resources.frontController.plugins.foo.priority = 99

diff --git a/ZendFramework/library/Zend/Application/Resource/Frontcontroller.php b/ZendFramework/library/Zend/Application/Resource/Frontcontroller.php
index 68ab8c1..5c237d3 100644
--- a/ZendFramework/library/Zend/Application/Resource/Frontcontroller.php
+++ b/ZendFramework/library/Zend/Application/Resource/Frontcontroller.php
@@ -87,8 +87,7 @@ class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resourc
                     
                 case 'plugins':
                     foreach ((array) $value as $pluginClass) {
-                        $plugin = new $pluginClass();
-                        $front->registerPlugin($plugin);
+                        $this->_loadPlugin($pluginClass);
                     }
                     break;
 
@@ -129,4 +128,26 @@ class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resourc
         }
         return $this->_front;
     }
+
+    /**
+     * Try to load a plugin
+     *
+     * @param array|string $pluginParams
+     * @return void
+     * @throws Zend_Application_Resource_Exception on invalid plugin options
+     */
+    protected function _loadPlugin($pluginParams)
+    {
+        if (is_string($pluginParams)) {
+            $plugin = new $pluginParams();
+            $this->getFrontController()->registerPlugin($plugin);
+        } elseif (is_array($pluginParams) && 
+                  array_key_exists('class', $pluginParams) &&
+                  array_key_exists('priority', $pluginParams)) {
+            $plugin = new $pluginParams['class']();
+            $this->getFrontController()->registerPlugin($plugin, $pluginParams['priority']);
+        } else {
+            throw new Zend_Application_Resource_Exception('The supplied plugin options are not valid');
+        }
+    }
 }

Comments

closing as dupe of ZF-6704