Browse Source

Update events to use new methods.

The attach()/detach() methods are deprecated and the internals should use the new methods.
Mark Story 11 years ago
parent
commit
95fe3381e6

+ 1 - 1
src/Controller/Component/AuthComponent.php

@@ -782,7 +782,7 @@ class AuthComponent extends Component
             }
             $config = array_merge($global, (array)$config);
             $this->_authenticateObjects[$alias] = new $className($this->_registry, $config);
-            $this->eventManager()->attach($this->_authenticateObjects[$alias]);
+            $this->eventManager()->on($this->_authenticateObjects[$alias]);
         }
         return $this->_authenticateObjects;
     }

+ 1 - 1
src/Controller/ComponentRegistry.php

@@ -106,7 +106,7 @@ class ComponentRegistry extends ObjectRegistry
         $instance = new $class($this, $config);
         $enable = isset($config['enabled']) ? $config['enabled'] : true;
         if ($enable) {
-            $this->eventManager()->attach($instance);
+            $this->eventManager()->on($instance);
         }
         return $instance;
     }

+ 1 - 1
src/Controller/Controller.php

@@ -287,7 +287,7 @@ class Controller implements EventListenerInterface
 
         $this->_mergeControllerVars();
         $this->_loadComponents();
-        $this->eventManager()->attach($this);
+        $this->eventManager()->on($this);
     }
 
     /**

+ 2 - 2
src/Controller/ErrorController.php

@@ -40,10 +40,10 @@ class ErrorController extends Controller
         }
         $eventManager = $this->eventManager();
         if (isset($this->Auth)) {
-            $eventManager->detach($this->Auth);
+            $eventManager->off($this->Auth);
         }
         if (isset($this->Security)) {
-            $eventManager->detach($this->Security);
+            $eventManager->off($this->Security);
         }
         $this->viewPath = 'Error';
     }

+ 1 - 1
src/Core/ObjectRegistry.php

@@ -301,7 +301,7 @@ abstract class ObjectRegistry
         }
         $object = $this->_loaded[$objectName];
         if (isset($this->_eventManager)) {
-            $this->eventManager()->detach($object);
+            $this->eventManager()->off($object);
         }
         unset($this->_loaded[$objectName]);
     }

+ 2 - 2
src/Event/EventManager.php

@@ -311,13 +311,13 @@ class EventManager
                 if (is_numeric(key($function))) {
                     foreach ($function as $handler) {
                         $handler = isset($handler['callable']) ? $handler['callable'] : $handler;
-                        $this->detach([$subscriber, $handler], $key);
+                        $this->off($key, [$subscriber, $handler]);
                     }
                     continue;
                 }
                 $function = $function['callable'];
             }
-            $this->detach([$subscriber, $function], $key);
+            $this->off($key, [$subscriber, $function]);
         }
     }
 

+ 1 - 1
src/Event/README.md

@@ -31,7 +31,7 @@ class Orders
 }
 
 $orders = new Orders();
-$orders->eventManager()->attach(function ($event) {
+$orders->eventManager()->on(function ($event) {
 	// Do something after the order was placed
 	...
 }, 'Orders.afterPlace');

+ 1 - 1
src/ORM/BehaviorRegistry.php

@@ -117,7 +117,7 @@ class BehaviorRegistry extends ObjectRegistry
         $instance = new $class($this->_table, $config);
         $enable = isset($config['enabled']) ? $config['enabled'] : true;
         if ($enable) {
-            $this->eventManager()->attach($instance);
+            $this->eventManager()->on($instance);
         }
         $methods = $this->_getMethods($instance, $class, $alias);
         $this->_methodMap += $methods['methods'];

+ 1 - 1
src/ORM/Table.php

@@ -248,7 +248,7 @@ class Table implements RepositoryInterface, EventListenerInterface
         $this->_associations = $associations ?: new AssociationCollection();
 
         $this->initialize($config);
-        $this->_eventManager->attach($this);
+        $this->_eventManager->on($this);
         $this->dispatchEvent('Model.initialize');
     }
 

+ 1 - 1
src/Routing/Dispatcher.php

@@ -143,7 +143,7 @@ class Dispatcher
     public function addFilter(EventListenerInterface $filter)
     {
         $this->_filters[] = $filter;
-        $this->eventManager()->attach($filter);
+        $this->eventManager()->on($filter);
     }
 
     /**

+ 7 - 7
src/TestSuite/IntegrationTestCase.php

@@ -267,10 +267,10 @@ abstract class IntegrationTestCase extends TestCase
         $request = $this->_buildRequest($url, $method, $data);
         $response = new Response();
         $dispatcher = DispatcherFactory::create();
-        $dispatcher->eventManager()->attach(
-            [$this, 'controllerSpy'],
+        $dispatcher->eventManager()->on(
             'Dispatcher.beforeDispatch',
-            ['priority' => 999]
+            ['priority' => 999],
+            [$this, 'controllerSpy']
         );
         try {
             $dispatcher->dispatch($request, $response);
@@ -296,12 +296,12 @@ abstract class IntegrationTestCase extends TestCase
         }
         $this->_controller = $event->data['controller'];
         $events = $this->_controller->eventManager();
-        $events->attach(function ($event, $viewFile) {
+        $events->on('View.beforeRender', function ($event, $viewFile) {
             $this->_viewName = $viewFile;
-        }, 'View.beforeRender');
-        $events->attach(function ($event, $viewFile) {
+        });
+        $events->on('View.beforeLayout', function ($event, $viewFile) {
             $this->_layoutName = $viewFile;
-        }, 'View.beforeLayout');
+        });
     }
 
     /**

+ 1 - 1
src/View/HelperRegistry.php

@@ -146,7 +146,7 @@ class HelperRegistry extends ObjectRegistry
         }
         $enable = isset($settings['enabled']) ? $settings['enabled'] : true;
         if ($enable) {
-            $this->eventManager()->attach($instance);
+            $this->eventManager()->on($instance);
         }
         return $instance;
     }

+ 1 - 1
tests/TestCase/Controller/ComponentTest.php

@@ -85,7 +85,7 @@ class ComponentTest extends TestCase
         $controller->eventManager($mock);
 
         $mock->expects($this->once())
-            ->method('attach')
+            ->method('on')
             ->with($this->isInstanceOf('TestApp\Controller\Component\AppleComponent'));
 
         $Collection = new ComponentRegistry($controller);