Explorar el Código

Updated to rev e32f1a26 of ZF2 EventManager

Renames for consistency

- s/SharedEventManagerAware/SharedEventCollectionAware/, as the
  interface was typehinting on the latter.
- s/setSharedConnections/setSharedCollections/, as the latter is the
  terminology in the interface
- s/sharedConnections/sharedCollections/, for the same reasons as the
  previous point

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24706 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew hace 13 años
padre
commit
72c940ed83

+ 28 - 18
library/Zend/EventManager/EventManager.php

@@ -21,6 +21,7 @@
 require_once 'Zend/EventManager/Event.php';
 require_once 'Zend/EventManager/EventCollection.php';
 require_once 'Zend/EventManager/ResponseCollection.php';
+require_once 'Zend/EventManager/SharedEventCollectionAware.php';
 require_once 'Zend/EventManager/StaticEventManager.php';
 require_once 'Zend/Stdlib/CallbackHandler.php';
 require_once 'Zend/Stdlib/PriorityQueue.php';
@@ -36,7 +37,7 @@ require_once 'Zend/Stdlib/PriorityQueue.php';
  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_EventManager_EventManager implements Zend_EventManager_EventCollection
+class Zend_EventManager_EventManager implements Zend_EventManager_EventCollection, Zend_EventManager_SharedEventCollectionAware
 {
     /**
      * Subscribed events and their listeners
@@ -56,10 +57,10 @@ class Zend_EventManager_EventManager implements Zend_EventManager_EventCollectio
     protected $identifiers = array();
 
     /**
-     * Static connections
+     * Static collections
      * @var false|null|Zend_EventManager_StaticEventCollection
      */
-    protected $sharedConnections = null;
+    protected $sharedCollections = null;
 
     /**
      * Constructor
@@ -88,32 +89,41 @@ class Zend_EventManager_EventManager implements Zend_EventManager_EventCollectio
     }
 
     /**
-     * Set static connections container
+     * Set static collections container
      *
-     * @param  null|Zend_EventManager_StaticEventCollection $connections
+     * @param  Zend_EventManager_StaticEventCollection $collections
      * @return void
      */
-    public function setSharedConnections(Zend_EventManager_SharedEventCollection $connections = null)
+    public function setSharedCollections(Zend_EventManager_SharedEventCollection $collections)
     {
-        if (null === $connections) {
-            $this->sharedConnections = false;
-        } else {
-            $this->sharedConnections = $connections;
-        }
+        $this->sharedCollections = $collections;
         return $this;
     }
 
     /**
-     * Get static connections container
+     * Remove any shared collections
+     *
+     * Sets {@link $sharedCollections} to boolean false to disable ability
+     * to lazy-load static event manager instance.
+     * 
+     * @return void
+     */
+    public function unsetSharedCollections()
+    {
+        $this->sharedCollections = false;
+    }
+
+    /**
+     * Get static collections container
      *
      * @return false|Zend_EventManager_SharedEventCollection
      */
-    public function getSharedConnections()
+    public function getSharedCollections()
     {
-        if (null === $this->sharedConnections) {
-            $this->setSharedConnections(Zend_EventManager_StaticEventManager::getInstance());
+        if (null === $this->sharedCollections) {
+            $this->setSharedCollections(Zend_EventManager_StaticEventManager::getInstance());
         }
-        return $this->sharedConnections;
+        return $this->sharedCollections;
     }
 
     /**
@@ -484,7 +494,7 @@ class Zend_EventManager_EventManager implements Zend_EventManager_EventCollectio
      */
     protected function getSharedListeners($event)
     {
-        if (!$sharedConnections = $this->getSharedConnections()) {
+        if (!$sharedCollections = $this->getSharedCollections()) {
             return array();
         }
 
@@ -492,7 +502,7 @@ class Zend_EventManager_EventManager implements Zend_EventManager_EventCollectio
         $sharedListeners = array();
 
         foreach ($identifiers as $id) {
-            if (!$listeners = $sharedConnections->getListeners($id, $event)) {
+            if (!$listeners = $sharedCollections->getListeners($id, $event)) {
                 continue;
             }
 

+ 7 - 5
library/Zend/EventManager/SharedEventManagerAware.php → library/Zend/EventManager/SharedEventCollectionAware.php

@@ -19,8 +19,10 @@
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 
+require_once 'Zend/EventManager/SharedEventCollection.php';
+
 /**
- * Interface to automate setter injection for a SharedEventManager instance
+ * Interface to automate setter injection for a SharedEventCollection instance
  *
  * @category   Zend
  * @package    Zend_EventManager
@@ -28,13 +30,13 @@
  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-interface Zend_EventManager_SharedEventManagerAware
+interface Zend_EventManager_SharedEventCollectionAware
 {
     /**
      * Inject an EventManager instance
      * 
-     * @param  Zend_EventManager_SharedEventCollection $sharedEventManager 
-     * @return Zend_EventManager_SharedEventManagerAware
+     * @param  Zend_EventManager_SharedEventCollection $sharedEventCollection 
+     * @return Zend_EventManager_SharedEventCollectionAware
      */
-    public function setSharedConnections(Zend_EventManager_SharedEventCollection $sharedEventManager);
+    public function setSharedCollections(Zend_EventManager_SharedEventCollection $sharedEventCollection);
 }

+ 5 - 5
tests/Zend/EventManager/StaticIntegrationTest.php

@@ -93,7 +93,7 @@ class Zend_EventManager_StaticIntegrationTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(array('local3', 'static', 'local2', 'local'), $this->test->results);
     }
 
-    public function testPassingNullValueToSetSharedConnectionsDisablesSharedConnections()
+    public function testPassingNullValueToSetSharedCollectionsDisablesSharedCollections()
     {
         $this->counter = (object) array('count' => 0);
         Zend_EventManager_StaticEventManager::getInstance()->attach(
@@ -102,12 +102,12 @@ class Zend_EventManager_StaticIntegrationTest extends PHPUnit_Framework_TestCase
             array($this, 'advanceCounter')
         );
         $class = new Zend_EventManager_TestAsset_ClassWithEvents();
-        $class->events()->setSharedConnections(null);
+        $class->events()->unsetSharedCollections();
         $class->foo();
         $this->assertEquals(0, $this->counter->count);
     }
 
-    public function testCanPassAlternateSharedConnectionsHolder()
+    public function testCanPassAlternateSharedCollectionsHolder()
     {
         $this->counter = (object) array('count' => 0);
         Zend_EventManager_StaticEventManager::getInstance()->attach(
@@ -117,8 +117,8 @@ class Zend_EventManager_StaticIntegrationTest extends PHPUnit_Framework_TestCase
         );
         $mockStaticEvents = new Zend_EventManager_TestAsset_StaticEventsMock();
         $class = new Zend_EventManager_TestAsset_ClassWithEvents();
-        $class->events()->setSharedConnections($mockStaticEvents);
-        $this->assertSame($mockStaticEvents, $class->events()->getSharedConnections());
+        $class->events()->setSharedCollections($mockStaticEvents);
+        $this->assertSame($mockStaticEvents, $class->events()->getSharedCollections());
         $class->foo();
         $this->assertEquals(0, $this->counter->count);
     }