Selaa lähdekoodia

ZF-7200 : adding magic functions to BootstrapAbstract

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16555 44c647ce-9c0f-0410-b52a-842ac1e357ba
doctorrock83 16 vuotta sitten
vanhempi
commit
e500773fb0

+ 24 - 0
library/Zend/Application/Bootstrap/BootstrapAbstract.php

@@ -535,6 +535,30 @@ abstract class Zend_Application_Bootstrap_BootstrapAbstract
     }
 
     /**
+     * Implement PHP's magic to retrieve a ressource
+     * in the bootstrap
+     *
+     * @param string $prop
+     * @return null|mixed
+     */
+    public function __get($prop)
+    {
+        return $this->getResource($prop);
+    }
+
+    /**
+     * Implement PHP's magic to ask for the
+     * existence of a ressource in the bootstrap
+     * 
+     * @param string $prop
+     * @return bool
+     */
+    public function __isset($prop)
+    {
+        return $this->hasResource($prop);
+    }
+
+    /**
      * Bootstrap individual, all, or multiple resources
      *
      * Marked as final to prevent issues when subclassing and naming the

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

@@ -503,6 +503,19 @@ class Zend_Application_Bootstrap_BootstrapAbstractTest extends PHPUnit_Framework
         $resource = $bootstrap->getResource('baz');
         $this->assertEquals('Baz', $resource->baz);
     }
+    
+    public function testMagicMethodsForPluginResources()
+    {
+        require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php';
+        $bootstrap = new ZfAppBootstrap($this->application);
+        $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources');
+        $bootstrap->registerPluginResource('baz');
+        $bootstrap->bootstrap('baz');
+
+        $this->assertTrue(isset($bootstrap->baz));
+        $resource = $bootstrap->baz;
+        $this->assertEquals('Baz', $resource->baz);
+    }
 
     /**
      * @group ZF-6543