Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/api/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>`
- `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`
Expand Down
6 changes: 2 additions & 4 deletions docs/core/streaming.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions docs/streaming/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
```

Expand Down
9 changes: 4 additions & 5 deletions docs/streaming/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Loading