Skip to content

Commit 09d0471

Browse files
authored
Merge pull request #15 from blitz-php/devs
Devs
2 parents 0293c93 + 7c8fc79 commit 09d0471

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/Http/Concerns/InteractsWithInput.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,23 @@ public function input(?string $key = null, mixed $default = null): mixed
276276
*/
277277
public function str(string $key, mixed $default = null): Stringable
278278
{
279-
return Text::of($this->input($key, $default));
279+
if (null === $value = $this->string($key, $default)) {
280+
return null;
281+
}
282+
283+
return Text::of($value);
280284
}
281285

282286
/**
283287
* Récupérez l'entrée de la requête en tant que chaine de caractere.
284288
*/
285-
public function string(string $key, mixed $default = null): string
289+
public function string(string $key, mixed $default = null): ?string
286290
{
287-
return $this->str($key, $default)->value();
291+
if (null === $value = $this->input($key, $default)) {
292+
return null;
293+
}
294+
295+
return (string) $value;
288296
}
289297

290298
/**

src/Router/Dispatcher.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use BlitzPHP\Contracts\Event\EventManagerInterface;
1818
use BlitzPHP\Contracts\Http\ResponsableInterface;
1919
use BlitzPHP\Contracts\Router\RouteCollectionInterface;
20+
use BlitzPHP\Contracts\Support\Arrayable;
2021
use BlitzPHP\Debug\Timer;
2122
use BlitzPHP\Enums\Method;
2223
use BlitzPHP\Exceptions\PageNotFoundException;
@@ -608,13 +609,17 @@ protected function formatResponse(ResponseInterface $response, $returned): Respo
608609
return $returned->toResponse($this->request);
609610
}
610611

612+
if ($returned instanceof Arrayable) {
613+
$returned = $returned->toArray();
614+
}
615+
611616
if (is_object($returned)) {
612-
if (method_exists($returned, '__toString')) {
613-
$returned = $returned->__toString();
614-
} elseif (method_exists($returned, 'toArray')) {
617+
if (method_exists($returned, 'toArray')) {
615618
$returned = $returned->toArray();
616619
} elseif (method_exists($returned, 'toJSON')) {
617620
$returned = $returned->toJSON();
621+
} elseif (method_exists($returned, '__toString')) {
622+
$returned = $returned->__toString();
618623
} else {
619624
$returned = (array) $returned;
620625
}

0 commit comments

Comments
 (0)