continue refactoring dispatching event on model modification
This commit is contained in:
@@ -116,8 +116,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
|
||||
$customer = CustomerQuery::create()->findPk(1);
|
||||
|
||||
$customerEvent = new CustomerEvent($customer);
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent);
|
||||
|
||||
|
||||
$data = $form->getData();
|
||||
|
||||
@@ -134,8 +133,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
|
||||
$data["country"]
|
||||
);
|
||||
|
||||
$customerEvent->customer = $customer;
|
||||
$event->getDispatcher()->dispatch(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent);
|
||||
|
||||
|
||||
// Update the logged-in user, and redirect to the success URL (exits)
|
||||
// We don-t send the login event, as the customer si already logged.
|
||||
|
||||
@@ -109,9 +109,7 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
$this->setRef($this->generateRef());
|
||||
$customerEvent = new CustomerEvent($this);
|
||||
|
||||
if (!is_null($this->dispatcher)) {
|
||||
$this->dispatcher->dispatch(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent);
|
||||
}
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CREATECUSTOMER, $customerEvent);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -119,10 +117,30 @@ class Customer extends BaseCustomer implements UserInterface
|
||||
public function postInsert(ConnectionInterface $con = null)
|
||||
{
|
||||
$customerEvent = new CustomerEvent($this);
|
||||
if (!is_null($this->dispatcher)) {
|
||||
$this->dispatcher->dispatch(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent);
|
||||
}
|
||||
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CREATECUSTOMER, $customerEvent);
|
||||
|
||||
}
|
||||
|
||||
public function preUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$customerEvent = new CustomerEvent($this);
|
||||
$this->dispatchEvent(TheliaEvents::BEFORE_CHANGECUSTOMER, $customerEvent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function postUpdate(ConnectionInterface $con = null)
|
||||
{
|
||||
$customerEvent = new CustomerEvent($this);
|
||||
$this->dispatchEvent(TheliaEvents::AFTER_CHANGECUSTOMER, $customerEvent);
|
||||
}
|
||||
|
||||
protected function dispatchEvent($eventName, CustomerEvent $customerEvent)
|
||||
{
|
||||
if (!is_null($this->dispatcher)) {
|
||||
$this->dispatcher->dispatch($eventName, $customerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
protected function generateRef()
|
||||
|
||||
Reference in New Issue
Block a user