Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\SenderBundle;
- use app\SenderBundle\Dto\Message;
- use app\SenderBundle\Protocol\ProtocolInterface;
- use app\SenderBundle\Validation\ValidatorResolverInterface;
- use UnderflowException;
- final class QueueGateway implements QueueGatewayInterface
- {
- /**
- * @var ProtocolInterface
- */
- private $protocol;
- /**
- * @var ValidatorResolverInterface
- */
- private $validatorResolver;
- /**
- * @param ProtocolInterface $protocol
- * @param ValidatorResolverInterface $validatorResolver
- */
- public function __construct(ProtocolInterface $protocol, ValidatorResolverInterface $validatorResolver)
- {
- $this->protocol = $protocol;
- $this->validatorResolver = $validatorResolver;
- }
- /**
- * @inheritdoc
- */
- public function push(Message $message): bool
- {
- $validationStrategy = $this->validatorResolver->resolve($message->getType());
- if (!$validationStrategy->validate($message->getData())) {
- throw new UnderflowException();
- }
- return $this->protocol->send($message);
- }
- }
- namespace app\SenderBundle\Validation;
- final class ValidatorResolver implements ValidatorResolverInterface
- {
- /**
- * @inheritdoc
- */
- public function resolve(string $type): ValidatorInterface
- {
- // TODO: Implement resolve() method.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement