Skip to content

Commit cd9c883

Browse files
committed
DefaultController: Hard code root node name
Fix the following for low coast Parameter #1 $string of function substr expects string, string|false given.
1 parent 14a1c78 commit cd9c883

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

code_samples/api/rest_api/src/Rest/Controller/DefaultController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function __construct(private SerializerInterface $serializer)
254254
{
255255
}
256256

257-
public function greet(Request $request): Response//Greeting
257+
public function greet(Request $request): Response|Greeting
258258
{
259259
$contentType = $request->headers->get('Content-Type');
260260
if ($contentType) {
@@ -266,17 +266,17 @@ public function greet(Request $request): Response//Greeting
266266
$greeting = new Greeting();
267267
}
268268

269+
//return $greeting;
270+
269271
$accept = $request->headers->get('Accept', 'application/' . self::DEFAULT_FORMAT);
270272
preg_match('@.*[/+](?P<format>[^/+]+)@', $accept, $matches);
271273
$format = empty($matches['format']) ? self::DEFAULT_FORMAT : $matches['format'];
272274
if (!in_array($format, self::AVAILABLE_FORMATS)) {
273275
$format = self::DEFAULT_FORMAT;
274276
}
275277

276-
//return $greeting;
277-
278278
$serialized = $this->serializer->serialize($greeting, $format, [
279-
XmlEncoder::ROOT_NODE_NAME => substr(strrchr(get_class($greeting), '\\'), 1),
279+
XmlEncoder::ROOT_NODE_NAME => 'Greeting',
280280
]);
281281

282282
return new Response($serialized, Response::HTTP_OK, ['Content-Type' => "application/vnd.ibexa.api.Greeting+$format"]);

0 commit comments

Comments
 (0)