88use Phplrt \Contracts \Source \ReadableInterface ;
99use Phplrt \Contracts \Source \SourceExceptionInterface ;
1010use Phplrt \Contracts \Source \SourceFactoryInterface ;
11+ use Psr \Http \Message \StreamInterface ;
1112
1213trait SourceFactoryTrait
1314{
@@ -31,11 +32,13 @@ public static function getSourceFactory(): SourceFactoryInterface
3132 * : ReadableInterface)
3233 * )
3334 * @throws SourceExceptionInterface
34- *
35- * @psalm-suppress NoValue : Allow any value
3635 */
3736 public static function new (mixed $ source ): ReadableInterface
3837 {
38+ if ($ source instanceof StreamInterface) {
39+ return static ::fromPsrStream ($ source );
40+ }
41+
3942 $ factory = self ::getSourceFactory ();
4043
4144 return $ factory ->create ($ source );
@@ -46,6 +49,7 @@ public static function new(mixed $source): ReadableInterface
4649 * @param non-empty-string|null $pathname
4750 *
4851 * @return ($pathname is null ? ReadableInterface : FileInterface)
52+ * @throws SourceExceptionInterface
4953 */
5054 public static function empty (?string $ pathname = null ): ReadableInterface
5155 {
@@ -57,6 +61,7 @@ public static function empty(?string $pathname = null): ReadableInterface
5761 * @param non-empty-string|null $pathname
5862 *
5963 * @return ($pathname is null ? ReadableInterface : FileInterface)
64+ * @throws SourceExceptionInterface
6065 */
6166 public static function fromSources (string $ sources , ?string $ pathname = null ): ReadableInterface
6267 {
@@ -97,6 +102,24 @@ public static function fromPathname(string $pathname): FileInterface
97102 return new File ($ pathname );
98103 }
99104
105+ /**
106+ * @param non-empty-string|null $pathname
107+ *
108+ * @return ($pathname is null ? ReadableInterface : FileInterface)
109+ * @throws SourceExceptionInterface
110+ *
111+ * @deprecated since phplrt 3.4 and will be removed in 4.0, use {@see fromResource()} instead.
112+ */
113+ public static function fromPsrStream (StreamInterface $ stream , ?string $ pathname = null ): ReadableInterface
114+ {
115+ trigger_deprecation ('phplrt/source ' , '3.4 ' , <<<'MSG'
116+ Using "%s::fromPsrStream($stream)" with %s argument is deprecated,
117+ use "%1$s::fromResource($stream->detach())" instead.
118+ MSG, static ::class, $ stream ::class);
119+
120+ return static ::fromResource ($ stream ->detach (), $ pathname );
121+ }
122+
100123 /**
101124 * @param resource $resource
102125 * @param non-empty-string|null $pathname
0 commit comments