Skip to content

Commit 95fe338

Browse files
committed
Update events to use new methods.
The attach()/detach() methods are deprecated and the internals should use the new methods.
1 parent c9109bb commit 95fe338

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

src/Controller/Component/AuthComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ public function constructAuthenticate()
782782
}
783783
$config = array_merge($global, (array)$config);
784784
$this->_authenticateObjects[$alias] = new $className($this->_registry, $config);
785-
$this->eventManager()->attach($this->_authenticateObjects[$alias]);
785+
$this->eventManager()->on($this->_authenticateObjects[$alias]);
786786
}
787787
return $this->_authenticateObjects;
788788
}

src/Controller/ComponentRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function _create($class, $alias, $config)
106106
$instance = new $class($this, $config);
107107
$enable = isset($config['enabled']) ? $config['enabled'] : true;
108108
if ($enable) {
109-
$this->eventManager()->attach($instance);
109+
$this->eventManager()->on($instance);
110110
}
111111
return $instance;
112112
}

src/Controller/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function __construct(Request $request = null, Response $response = null,
287287

288288
$this->_mergeControllerVars();
289289
$this->_loadComponents();
290-
$this->eventManager()->attach($this);
290+
$this->eventManager()->on($this);
291291
}
292292

293293
/**

src/Controller/ErrorController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function __construct($request = null, $response = null)
4040
}
4141
$eventManager = $this->eventManager();
4242
if (isset($this->Auth)) {
43-
$eventManager->detach($this->Auth);
43+
$eventManager->off($this->Auth);
4444
}
4545
if (isset($this->Security)) {
46-
$eventManager->detach($this->Security);
46+
$eventManager->off($this->Security);
4747
}
4848
$this->viewPath = 'Error';
4949
}

src/Core/ObjectRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function unload($objectName)
301301
}
302302
$object = $this->_loaded[$objectName];
303303
if (isset($this->_eventManager)) {
304-
$this->eventManager()->detach($object);
304+
$this->eventManager()->off($object);
305305
}
306306
unset($this->_loaded[$objectName]);
307307
}

src/Event/EventManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,13 @@ protected function _detachSubscriber(EventListenerInterface $subscriber, $eventK
311311
if (is_numeric(key($function))) {
312312
foreach ($function as $handler) {
313313
$handler = isset($handler['callable']) ? $handler['callable'] : $handler;
314-
$this->detach([$subscriber, $handler], $key);
314+
$this->off($key, [$subscriber, $handler]);
315315
}
316316
continue;
317317
}
318318
$function = $function['callable'];
319319
}
320-
$this->detach([$subscriber, $function], $key);
320+
$this->off($key, [$subscriber, $function]);
321321
}
322322
}
323323

src/Event/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Orders
3131
}
3232

3333
$orders = new Orders();
34-
$orders->eventManager()->attach(function ($event) {
34+
$orders->eventManager()->on(function ($event) {
3535
// Do something after the order was placed
3636
...
3737
}, 'Orders.afterPlace');

src/ORM/BehaviorRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function _create($class, $alias, $config)
117117
$instance = new $class($this->_table, $config);
118118
$enable = isset($config['enabled']) ? $config['enabled'] : true;
119119
if ($enable) {
120-
$this->eventManager()->attach($instance);
120+
$this->eventManager()->on($instance);
121121
}
122122
$methods = $this->_getMethods($instance, $class, $alias);
123123
$this->_methodMap += $methods['methods'];

src/ORM/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function __construct(array $config = [])
248248
$this->_associations = $associations ?: new AssociationCollection();
249249

250250
$this->initialize($config);
251-
$this->_eventManager->attach($this);
251+
$this->_eventManager->on($this);
252252
$this->dispatchEvent('Model.initialize');
253253
}
254254

src/Routing/Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function _invoke(Controller $controller)
143143
public function addFilter(EventListenerInterface $filter)
144144
{
145145
$this->_filters[] = $filter;
146-
$this->eventManager()->attach($filter);
146+
$this->eventManager()->on($filter);
147147
}
148148

149149
/**

0 commit comments

Comments
 (0)