Exemplo n.º 1
0
 /**
  * @param DomainEvent $event
  */
 public function validateDefaultLocale(DomainEvent $event)
 {
     $data = $event->getData();
     if ($data !== $this->localeProvider->getDefaultLocale()) {
         return;
     }
     $resource = $event->getResource();
     $event->setStopped(true);
     $event->setStatusCode(409);
     $event->setMessageType('error');
     $event->setMessage($this->translator->trans('lug.' . $resource->getName() . '.' . $event->getAction() . '.default', ['%' . $resource->getName() . '%' => $this->propertyAccessor->getValue($data, $resource->getLabelPropertyPath())], 'flashes'));
 }
Exemplo n.º 2
0
 /**
  * @param DomainEvent $event
  */
 public function addMessage(DomainEvent $event)
 {
     $messageType = $event->getMessageType();
     $message = $event->getMessage();
     if (empty($messageType)) {
         $messageType = $event->isStopped() ? 'error' : 'success';
     }
     if (empty($message)) {
         $object = $event->getObject();
         $resource = $event->getResource();
         $name = $resource->getName();
         $labelPropertyPath = $resource->getLabelPropertyPath();
         $property = $labelPropertyPath !== null ? $this->propertyAccessor->getValue($object, $labelPropertyPath) : (string) $object;
         $message = $this->translator->trans('lug.' . $name . '.' . $event->getAction() . '.' . $messageType, ['%' . $name . '%' => $property], 'flashes');
     }
     $event->setMessageType($messageType);
     $event->setMessage($message);
 }
Exemplo n.º 3
0
 /**
  * @param DomainEvent $event
  */
 public function addMessage(DomainEvent $event)
 {
     if ($this->parameterResolver->resolveApi()) {
         return;
     }
     $messageType = $event->getMessageType();
     $message = $event->getMessage();
     if (empty($messageType)) {
         $messageType = $event->isStopped() ? 'error' : 'success';
     }
     if (empty($message)) {
         $data = $event->getData();
         $resource = $event->getResource();
         $name = $resource->getName();
         $labelPropertyPath = $resource->getLabelPropertyPath();
         $property = $labelPropertyPath !== null ? $this->propertyAccessor->getValue($data, $labelPropertyPath) : (string) $data;
         $message = $this->translator->trans('lug.' . $name . '.' . $event->getAction() . '.' . $messageType, ['%' . $name . '%' => $property], 'flashes');
     }
     $event->setMessageType($messageType);
     $event->setMessage($message);
 }
Exemplo n.º 4
0
 public function testStopped()
 {
     $this->domainEvent->setStopped(true);
     $this->assertTrue($this->domainEvent->isStopped());
 }
Exemplo n.º 5
0
 /**
  * @param DomainEvent $event
  */
 public function addFlash(DomainEvent $event)
 {
     if (!$this->parameterResolver->resolveApi()) {
         $this->session->getFlashBag()->add($event->getMessageType(), $event->getMessage());
     }
 }
Exemplo n.º 6
0
 /**
  * @param DomainEvent     $event
  * @param string          $action
  * @param string          $state
  * @param \Exception|null $exception
  */
 private function dispatchEvent(DomainEvent $event, $action, $state, \Exception $exception = null)
 {
     if ($state === self::STATE_ERROR) {
         $event->setStopped(true);
     }
     $this->eventDispatcher->dispatch('lug.' . $this->resource->getName() . '.' . $state . '_' . $action, $event);
     if ($event->isStopped()) {
         throw new DomainException($event->getStatusCode(), $event->getMessage(), 0, $exception);
     }
 }