InMemoryTransportFactory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Messenger\Transport;
  11. use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
  12. use Symfony\Contracts\Service\ResetInterface;
  13. /**
  14. * @author Gary PEGEOT <garypegeot@gmail.com>
  15. */
  16. class InMemoryTransportFactory implements TransportFactoryInterface, ResetInterface
  17. {
  18. /**
  19. * @var InMemoryTransport[]
  20. */
  21. private $createdTransports = [];
  22. public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
  23. {
  24. return $this->createdTransports[] = new InMemoryTransport();
  25. }
  26. public function supports(string $dsn, array $options): bool
  27. {
  28. return 0 === strpos($dsn, 'in-memory://');
  29. }
  30. public function reset()
  31. {
  32. foreach ($this->createdTransports as $transport) {
  33. $transport->reset();
  34. }
  35. }
  36. }