Procházet zdrojové kódy

ZF-6471: Pass bootstrap to constructor of resources

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15454 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew před 16 roky
rodič
revize
ac9fb39da1

+ 2 - 1
library/Zend/Application/Bootstrap/BootstrapAbstract.php

@@ -317,7 +317,8 @@ abstract class Zend_Application_Bootstrap_BootstrapAbstract
         }
 
         if (!$this->_pluginResources[$resource] instanceof Zend_Application_Resource_Resource) {
-            $options   = $this->_pluginResources[$resource];
+            $options   = (array) $this->_pluginResources[$resource];
+            $options['bootstrap'] = $this;
             $className = $this->getPluginLoader()->load($resource);
             $this->_pluginResources[$resource] = new $className($options);
         }

+ 24 - 0
tests/Zend/Application/Bootstrap/BootstrapAbstractTest.php

@@ -582,6 +582,21 @@ class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework
         $this->assertTrue($resource1 instanceof Zend_Application_Bootstrap_BootstrapAbstractTest_Layout, var_export(array_keys($bootstrap->getPluginResources()), 1));
         $this->assertTrue($resource2 instanceof Zend_Layout);
     }
+
+    public function testBootstrapShouldPassItselfToResourcePluginConstructor()
+    {
+        $this->application->setOptions(array(
+            'pluginPaths' => array(
+                'Zend_Application_Bootstrap_BootstrapAbstractTest' => dirname(__FILE__),
+            ),
+            'resources' => array(
+                'Layout' => array(),
+            ),
+        ));
+        $bootstrap = new Zend_Application_Bootstrap_Bootstrap($this->application);
+        $resource = $bootstrap->getPluginResource('layout');
+        $this->assertTrue($resource->bootstrapSetInConstructor, var_export(get_object_vars($resource), 1));
+    }
 }
 
 class Zend_Application_Bootstrap_BootstrapAbstractTest_View
@@ -597,6 +612,15 @@ class Zend_Application_Bootstrap_BootstrapAbstractTest_Layout
     extends Zend_Application_Resource_ResourceAbstract
 {
     public $_explicitType = 'BootstrapAbstractTestLayout';
+    public $bootstrapSetInConstructor = false;
+
+    public function __construct($options = null)
+    {
+        parent::__construct($options);
+        if (null !== $this->getBootstrap()) {
+            $this->bootstrapSetInConstructor = true;
+        }
+    }
 
     public function init()
     {