diff --git a/docs/api/functions.md b/docs/api/functions.md index 2b5e94a..0ffedcf 100644 --- a/docs/api/functions.md +++ b/docs/api/functions.md @@ -44,9 +44,12 @@ Every constructor takes the body first and an optional `EntityEncoder`, and retu - `InternalServerError(mixed $body = null, ?EntityEncoder $encoder = null)` ## Streaming -- `Stream(mixed $source): Stream` - `FileResponse(string $path): IO` -- `StreamFromPDO(\PDOStatement $stmt): Stream` + +The stream factories come from phunkie/streams and are global functions, imported by nothing: + +- `Stream(mixed ...$source): Stream` +- `StreamFromPDO(PDOStatement $stmt): Stream` ## Core Types Helpers - `Response(Status $status, Headers $headers, Stream $body): Response` diff --git a/docs/core/streaming.md b/docs/core/streaming.md index 7ab9205..5d08902 100644 --- a/docs/core/streaming.md +++ b/docs/core/streaming.md @@ -1,6 +1,6 @@ # Streaming in Http4p -In **Http4p**, streaming is not an afterthought or a special mode—it is the default. +In **Http4p**, streaming is not an afterthought or a special mode: it is the default. Every `Request` body is a Stream. Every `Response` body is a Stream. @@ -18,11 +18,9 @@ GET('/', fn() => Ok("Hello World")); // Streams: "Hello", " ", "World" (conceptu ``` ### 2. Generating Data (Push) -You can stream data dynamically to the client. This is useful for large reports, logs, or real-time event feeds. +You can stream data dynamically to the client. This is useful for large reports, logs, or real-time event feeds. `Stream()` is phunkie/streams' global factory, so it needs no import: ```php -use function Phunkie\Streams\Functions\stream\Stream; - GET('/numbers', fn() => // Create a stream that yields numbers 1 to 10 Ok(Stream(range(1, 10)) diff --git a/docs/streaming/custom.md b/docs/streaming/custom.md index c98c421..96aac9b 100644 --- a/docs/streaming/custom.md +++ b/docs/streaming/custom.md @@ -16,11 +16,9 @@ class RandomNumberPull implements Pull { ## Creating the Stream -Use the `Stream()` helper to create a Stream from your custom Pull implementation. +Use the `Stream()` helper, a global function from phunkie/streams, to create a Stream from your custom Pull implementation: ```php -use Phunkie\Streams\Type\Stream; - $stream = Stream(new RandomNumberPull()); ``` diff --git a/docs/streaming/database.md b/docs/streaming/database.md index f34eff5..90a5fd5 100644 --- a/docs/streaming/database.md +++ b/docs/streaming/database.md @@ -4,11 +4,9 @@ You can stream database query results efficiently using `phunkie/streams` integr ## StreamFromPDO -The `StreamFromPDO` helper creates a Stream from a `PDOStatement`. It pulls rows one by one using `fetch(PDO::FETCH_ASSOC)`. +The `StreamFromPDO` helper, a global function from phunkie/streams, creates a Stream from a `PDOStatement`. It pulls rows one by one using `fetch(PDO::FETCH_ASSOC)`. ```php -use function StreamFromPDO; - $stmt = $pdo->query('SELECT * FROM huge_table'); $stream = StreamFromPDO($stmt); @@ -18,13 +16,14 @@ GET('/export', fn() => ); ``` +With [phunkie/phetch](https://github.com/phunkie/phetch) as the store, `where(User::class, 'active', true)->stream()` yields the same kind of stream with the rows hydrated into your models. + ## PDOPull -Under the hood, this uses `Phunkie\Streams\Pull\PDOPull`. You can use this class directly if you need to build custom streams or combine it with other Pull mechanics. +Under the hood, this uses `Phunkie\Streams\Pull\PDOPull`. You can use this class directly if you need to build custom streams or combine it with other Pull mechanics; `Stream()` is global as well. ```php use Phunkie\Streams\Pull\PDOPull; -use Phunkie\Streams\Type\Stream; $pull = new PDOPull($stmt); $stream = Stream($pull);