Disconnecting events
Introduction
There are two ways to disconnect an event, either using the same parameters as the one used when connecting the event or using the key returned by the "connect" method.
Disconnecting instance level events is achieved through the method "events->disconnect" while disconnecting static events is achieved through the static method "PorteEventss::disconnect".
You may as well disconnect static events using the "event->disconnect" method by only passing the event key as an argument.
Disconnecting an instance level event
Using the same parameters:
class Listener{
function beforeOnCreateListener(){
print 'Method call';
}
}
$listener = new Listener();
$user = new User();
$user->events->connect(
'record_create_before',
array($listener,'beforeOnCreateListener')
);
$user->save();
$user->events->disconnect(
'record_create_before',
array($listener,'beforeOnCreateListener')
);
Using the returned value:
class Listener{
function beforeOnCreateListener(){
print 'Method call';
}
}
$listener = new Listener();
$user = new User();
$event = $user->events->connect(
'record_create_before',
array($listener,'beforeOnCreateListener')
);
$user->save();
$user->events->disconnect($event);
Complete list of ways to disconnect events
Disconnecting an instance event using the same parameters:
$user->events->connect('action',object,'method');
$user->events->disconnect('action',array(object,'method'));
Disconnecting an instance event using the returned key:
$event = $user->events->connect('action',array(object,'method'));
$user->events->disconnect($event);
Disconnecting a global event using the same parameters:
PorteEvents::connect('action','function');
PorteEvents::disconnect('action','function');
PorteEvents::connect('action',array($object,'method'));
PorteEvents::disconnect('action',array($object,'method'));
Disconnecting a global event using the returned key:
$event = PorteEvents::connect('action','function');
PorteEvents::disconnect($event);
$record->eventDisconnect($event);
$event = PorteEvents::connect('action',array($object,'method'));
PorteEvents::disconnect($event);
$record->eventDisconnect($event);
Disconnecting a records event using the same parameters:
PorteEvents::connect('record_type','action','function');
PorteEvents::disconnect('record_type','action','function');
PorteEvents::connect('record_type','action',array($object,'method'));
PorteEvents::disconnect('record_type','action',array($object,'method'));
Disconnecting a records event using the returned key:
$event = PorteEvents::connect('record_type','action','function');
PorteEvents::disconnect($event);
$record->eventDisconnect($event);
$event = PorteEvents::connect('record_type','action',array($object,'method'));
PorteEvents::disconnect($event);
$record->eventDisconnect($event);