Hello,
in order to make my code reusable and decouple application into modules I decided to use events.
For example I have a controller:
class InvoiceController extends Controller {
public function actionAddinvoice() {
$InvoiceEvent = new InvoiceEvent();
//here I generate new invoice number
$InvoiceEvent->trigger(InvoiceEvent::EVENT_NEW_INVOICE_NUMBER);
$invoiceNumber = $InvoiceEvent->getInvoiceNumber();
}
}
and my InvoiceEvent class:
class InvoiceEvent extends Component {
private $invoiceNumber;
///....///
public function getInvoiceNumber(){
////.....////
$this->$invoiceNumber = ....
}
}
Suppose that the function getInvoiceNumber() has a lot to do (check db, prepare number etc.), so I remove it from controller to keep it thin. Should I use events this way? Is that correct and has sense?