Пример #1
0
 public function testInitialState()
 {
     $this->assertSame($this->resource, $this->domainEvent->getResource());
     $this->assertSame($this->object, $this->domainEvent->getObject());
     $this->assertSame($this->action, $this->domainEvent->getAction());
     $this->assertNull($this->domainEvent->getStatusCode());
     $this->assertNull($this->domainEvent->getMessageType());
     $this->assertNull($this->domainEvent->getMessage());
     $this->assertFalse($this->domainEvent->isStopped());
 }
Пример #2
0
 public function testInitialState()
 {
     $this->domainEvent = new DomainEvent($this->resource, $this->action, $data = new \stdClass());
     $this->assertSame($this->resource, $this->domainEvent->getResource());
     $this->assertSame($this->action, $this->domainEvent->getAction());
     $this->assertSame($data, $this->domainEvent->getData());
     $this->assertNull($this->domainEvent->getStatusCode());
     $this->assertNull($this->domainEvent->getMessageType());
     $this->assertNull($this->domainEvent->getMessage());
     $this->assertFalse($this->domainEvent->isStopped());
 }
Пример #3
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'));
 }
Пример #4
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);
 }
Пример #5
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);
 }