As Michiel said you should use an event in your method
function charge(){
//Perform charge related actions
$this->onCharge(new CEvent($this));
//... maybe some code over here after raising the event
}
public function onCharge($event){
$this->raiseEvent('onCharge', $event);
}
Now you have to catch the raised event. So in this component you'll declare which class and which mehod need to catch it (for example in the init
method)
//OtherClass need to catch the the charge event
$callback = array(new OtherClass,'afterCharge')
$component->onCharge = $callback;
So the method afterCharge
of OtherClass
will be called when charge()
is executed.
By the way, the method afterCharge must have the following signature
function afterCharge($event) {
}
Sources: