Debian Codegraph @

lib/3rdParty/composer/php-http/discovery/src/Psr17FactoryDiscovery.php

raw symbols SCIP
1 <?php
2
3 namespace Http\Discovery;
4
5 use Http\Discovery\Exception\DiscoveryFailedException;
6 use Http\Discovery\Exception\NotFoundException as RealNotFoundException;
7 use Psr\Http\Message\RequestFactoryInterface;
8 use Psr\Http\Message\ResponseFactoryInterface;
9 use Psr\Http\Message\ServerRequestFactoryInterface;
10 use Psr\Http\Message\StreamFactoryInterface;
11 use Psr\Http\Message\UploadedFileFactoryInterface;
12 use Psr\Http\Message\UriFactoryInterface;
13
14 /**
15 * Finds PSR-17 factories.
16 *
17 * @author Tobias Nyholm <[email protected]>
18 */
19 final class Psr17FactoryDiscovery extends ClassDiscovery
20 {
21 private static function createException($type, Exception $e)
22 {
23 return new RealNotFoundException(
24 'No PSR-17 '.$type.' found. Install a package from this list: https://packagist.org/providers/psr/http-factory-implementation',
25 0,
26 $e
27 );
28 }
29
30 /**
31 * @return RequestFactoryInterface
32 *
33 * @throws RealNotFoundException
34 */
35 public static function findRequestFactory()
36 {
37 try {
38 $messageFactory = static::findOneByType(RequestFactoryInterface::class);
39 } catch (DiscoveryFailedException $e) {
40 throw self::createException('request factory', $e);
41 }
42
43 return static::instantiateClass($messageFactory);
44 }
45
46 /**
47 * @return ResponseFactoryInterface
48 *
49 * @throws RealNotFoundException
50 */
51 public static function findResponseFactory()
52 {
53 try {
54 $messageFactory = static::findOneByType(ResponseFactoryInterface::class);
55 } catch (DiscoveryFailedException $e) {
56 throw self::createException('response factory', $e);
57 }
58
59 return static::instantiateClass($messageFactory);
60 }
61
62 /**
63 * @return ServerRequestFactoryInterface
64 *
65 * @throws RealNotFoundException
66 */
67 public static function findServerRequestFactory()
68 {
69 try {
70 $messageFactory = static::findOneByType(ServerRequestFactoryInterface::class);
71 } catch (DiscoveryFailedException $e) {
72 throw self::createException('server request factory', $e);
73 }
74
75 return static::instantiateClass($messageFactory);
76 }
77
78 /**
79 * @return StreamFactoryInterface
80 *
81 * @throws RealNotFoundException
82 */
83 public static function findStreamFactory()
84 {
85 try {
86 $messageFactory = static::findOneByType(StreamFactoryInterface::class);
87 } catch (DiscoveryFailedException $e) {
88 throw self::createException('stream factory', $e);
89 }
90
91 return static::instantiateClass($messageFactory);
92 }
93
94 /**
95 * @return UploadedFileFactoryInterface
96 *
97 * @throws RealNotFoundException
98 */
99 public static function findUploadedFileFactory()
100 {
101 try {
102 $messageFactory = static::findOneByType(UploadedFileFactoryInterface::class);
103 } catch (DiscoveryFailedException $e) {
104 throw self::createException('uploaded file factory', $e);
105 }
106
107 return static::instantiateClass($messageFactory);
108 }
109
110 /**
111 * @return UriFactoryInterface
112 *
113 * @throws RealNotFoundException
114 */
115 public static function findUriFactory()
116 {
117 try {
118 $messageFactory = static::findOneByType(UriFactoryInterface::class);
119 } catch (DiscoveryFailedException $e) {
120 throw self::createException('url factory', $e);
121 }
122
123 return static::instantiateClass($messageFactory);
124 }
125
126 /**
127 * @return UriFactoryInterface
128 *
129 * @throws RealNotFoundException
130 *
131 * @deprecated This will be removed in 2.0. Consider using the findUriFactory() method.
132 */
133 public static function findUrlFactory()
134 {
135 return static::findUriFactory();
136 }
137 }