Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\SenderBundle;
  4.  
  5. use app\SenderBundle\Dto\Message;
  6. use app\SenderBundle\Protocol\ProtocolInterface;
  7. use app\SenderBundle\Validation\ValidatorResolverInterface;
  8. use UnderflowException;
  9.  
  10. final class QueueGateway implements QueueGatewayInterface
  11. {
  12.     /**
  13.      * @var ProtocolInterface
  14.      */
  15.     private $protocol;
  16.  
  17.     /**
  18.      * @var ValidatorResolverInterface
  19.      */
  20.     private $validatorResolver;
  21.  
  22.     /**
  23.      * @param ProtocolInterface $protocol
  24.      * @param ValidatorResolverInterface $validatorResolver
  25.      */
  26.     public function __construct(ProtocolInterface $protocol, ValidatorResolverInterface $validatorResolver)
  27.     {
  28.         $this->protocol = $protocol;
  29.         $this->validatorResolver = $validatorResolver;
  30.     }
  31.  
  32.     /**
  33.      * @inheritdoc
  34.      */
  35.     public function push(Message $message): bool
  36.     {
  37.         $validationStrategy = $this->validatorResolver->resolve($message->getType());
  38.        
  39.         if (!$validationStrategy->validate($message->getData())) {
  40.             throw new UnderflowException();
  41.         }
  42.        
  43.         return $this->protocol->send($message);
  44.     }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. namespace app\SenderBundle\Validation;
  51.  
  52. final class ValidatorResolver implements ValidatorResolverInterface
  53. {
  54.     /**
  55.      * @inheritdoc
  56.      */
  57.     public function resolve(string $type): ValidatorInterface
  58.     {
  59.         // TODO: Implement resolve() method.
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement