Skip to content

Commit de17b91

Browse files
committed
Make shortcodes handle Response object
1 parent 8730b77 commit de17b91

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

Herbert/Framework/Shortcode.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,48 @@ public function add($name, $callable, $arguments = [])
6060
}
6161
}
6262

63-
return $this->app->call(
63+
$response = $this->app->call(
6464
$callable,
6565
array_merge([
6666
'_attributes' => $attributes,
6767
'_content' => $content
6868
], $attributes)
6969
);
70+
71+
if ($response instanceof RedirectResponse)
72+
{
73+
$response->flash();
74+
}
75+
76+
if ($response instanceof Response)
77+
{
78+
status_header($response->getStatusCode());
79+
80+
foreach ($response->getHeaders() as $key => $value)
81+
{
82+
@header($key . ': ' . $value);
83+
}
84+
85+
echo $response->getBody();
86+
87+
return;
88+
}
89+
90+
if (is_null($response) || is_string($response))
91+
{
92+
echo $response;
93+
94+
return;
95+
}
96+
97+
if (is_array($response) || $response instanceof Jsonable || $response instanceof JsonSerializable)
98+
{
99+
echo (new JsonResponse($response))->getBody();
100+
101+
return;
102+
}
103+
104+
throw new Exception('Unknown response type!');
70105
});
71106
}
72107

0 commit comments

Comments
 (0)