StreamFactoryDiscovery.php 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Http\Discovery;
  3. use Http\Discovery\Exception\DiscoveryFailedException;
  4. use Http\Message\StreamFactory;
  5. /**
  6. * Finds a Stream Factory.
  7. *
  8. * @author Михаил Красильников <m.krasilnikov@yandex.ru>
  9. */
  10. final class StreamFactoryDiscovery extends ClassDiscovery
  11. {
  12. /**
  13. * Finds a Stream Factory.
  14. *
  15. * @return StreamFactory
  16. *
  17. * @throws Exception\NotFoundException
  18. */
  19. public static function find()
  20. {
  21. try {
  22. $streamFactory = static::findOneByType(StreamFactory::class);
  23. } catch (DiscoveryFailedException $e) {
  24. throw new NotFoundException(
  25. 'No stream factories found. To use Guzzle, Diactoros or Slim Framework factories install php-http/message and the chosen message implementation.',
  26. 0,
  27. $e
  28. );
  29. }
  30. return static::instantiateClass($streamFactory);
  31. }
  32. }