Skip to content

Commit 387e6ff

Browse files
committed
Update README.md with the new internal API
I've changed the internal API but I forgot to update the documentation. This commit rectifies this.
1 parent a38facd commit 387e6ff

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,19 @@ To see more examples of how to use the library check the [integration tests](tes
136136

137137
### Custom stringifiers
138138

139-
Stringifier library is extensible, you can create your own stringifiers and use them with the `Stringify` class.
139+
Stringifier library is extensible, you can create your own stringifiers and handlers. Considering the internal design,
140+
it's best to create an implementation of `Handler`, and then use it to create a `HandlerStringifier`.
140141

141142
```php
142-
use Respect\Stringifier\Stringifier;
143-
use Respect\Stringifier\Stringifiers\CompositeStringifier;
143+
use Respect\Stringifier\DumpStringifier;
144+
use Respect\Stringifier\Handler;
145+
use Respect\Stringifier\Handlers\CompositeHandler;
146+
use Respect\Stringifier\HandlerStringifier;
144147
use Respect\Stringifier\Stringify;
145148

146-
$compositeStringifier = CompositeStringifier::createDefault();
147-
$compositeStringifier->prependStringifier(new class implements Stringifier {
148-
public function stringify(mixed $raw, int $depth): ?string
149+
$compositeHandler = CompositeHandler::create();
150+
$compositeHandler->prependStringifier(new class implements Handler {
151+
public function handle(mixed $raw, int $depth): ?string
149152
{
150153
if (is_object($raw) && method_exists($raw, 'toString')) {
151154
return $raw->toString();
@@ -155,13 +158,15 @@ $compositeStringifier->prependStringifier(new class implements Stringifier {
155158
}
156159
});
157160

158-
$stringify = new Stringify($compositeStringifier);
161+
$stringifier = new HandlerStringifier($compositeHandler, new DumpStringifier());
159162

160-
echo $stringify->value(new class {
163+
echo $stringifier->stringify(new class {
161164
public function toString(): string
162165
{
163166
return 'Hello, world!';
164167
}
165168
});
166169
// Hello, world!
167170
```
171+
172+
The `DumpStringifier` is a fallback stringifier that uses `print_r`-like output. You can replace it with any other.

0 commit comments

Comments
 (0)