Skip to content

Commit

Permalink
Update events to use new methods.
Browse files Browse the repository at this point in the history
The attach()/detach() methods are deprecated and the internals should use the new methods.
  • Loading branch information
markstory committed Feb 5, 2015
1 parent c9109bb commit 95fe338
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Component/AuthComponent.php
Expand Up @@ -782,7 +782,7 @@ public function constructAuthenticate()
}
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ComponentRegistry.php
Expand Up @@ -106,7 +106,7 @@ protected function _create($class, $alias, $config)
$instance = new $class($this, $config);
$enable = isset($config['enabled']) ? $config['enabled'] : true;
if ($enable) {
$this->eventManager()->attach($instance);
$this->eventManager()->on($instance);
}
return $instance;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -287,7 +287,7 @@ public function __construct(Request $request = null, Response $response = null,

$this->_mergeControllerVars();
$this->_loadComponents();
$this->eventManager()->attach($this);
$this->eventManager()->on($this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/ErrorController.php
Expand Up @@ -40,10 +40,10 @@ public function __construct($request = null, $response = null)
}
$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';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/ObjectRegistry.php
Expand Up @@ -301,7 +301,7 @@ public function unload($objectName)
}
$object = $this->_loaded[$objectName];
if (isset($this->_eventManager)) {
$this->eventManager()->detach($object);
$this->eventManager()->off($object);
}
unset($this->_loaded[$objectName]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Event/EventManager.php
Expand Up @@ -311,13 +311,13 @@ protected function _detachSubscriber(EventListenerInterface $subscriber, $eventK
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]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Event/README.md
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/BehaviorRegistry.php
Expand Up @@ -117,7 +117,7 @@ protected function _create($class, $alias, $config)
$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'];
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Table.php
Expand Up @@ -248,7 +248,7 @@ public function __construct(array $config = [])
$this->_associations = $associations ?: new AssociationCollection();

$this->initialize($config);
$this->_eventManager->attach($this);
$this->_eventManager->on($this);
$this->dispatchEvent('Model.initialize');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Routing/Dispatcher.php
Expand Up @@ -143,7 +143,7 @@ protected function _invoke(Controller $controller)
public function addFilter(EventListenerInterface $filter)
{
$this->_filters[] = $filter;
$this->eventManager()->attach($filter);
$this->eventManager()->on($filter);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -267,10 +267,10 @@ protected function _sendRequest($url, $method, $data = [])
$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);
Expand All @@ -296,12 +296,12 @@ public function controllerSpy($event)
}
$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');
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/HelperRegistry.php
Expand Up @@ -146,7 +146,7 @@ protected function _create($class, $alias, $settings)
}
$enable = isset($settings['enabled']) ? $settings['enabled'] : true;
if ($enable) {
$this->eventManager()->attach($instance);
$this->eventManager()->on($instance);
}
return $instance;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/ComponentTest.php
Expand Up @@ -85,7 +85,7 @@ public function testInnerComponentsAreNotEnabled()
$controller->eventManager($mock);

$mock->expects($this->once())
->method('attach')
->method('on')
->with($this->isInstanceOf('TestApp\Controller\Component\AppleComponent'));

$Collection = new ComponentRegistry($controller);
Expand Down

0 comments on commit 95fe338

Please sign in to comment.