2 declare(strict_types = 1);
212 public function render(): string
214 $response = $this->controllerContext->getResponse();
215 if ($response instanceof WebResponse) {
217 if (!empty(
$GLOBALS[
'TSFE']) &&
$GLOBALS[
'TSFE'] instanceof TypoScriptFrontendController) {
219 $typoScriptFrontendController =
$GLOBALS[
'TSFE'];
220 if (empty($typoScriptFrontendController->config[
'config'][
'disableCharsetHeader'])) {
223 $typoScriptFrontendController->setContentType(
'application/json');
228 $response->setHeader(
'Content-Type',
'application/json; charset=' . trim($typoScriptFrontendController->metaCharset));
231 $response->setHeader(
'Content-Type',
'application/json');
235 return json_encode($propertiesToRender, JSON_UNESCAPED_UNICODE);
246 if (count($this->variablesToRender) === 1) {
247 $variableName = current($this->variablesToRender);
248 $valueToRender = $this->variables[$variableName] ??
null;
252 foreach ($this->variablesToRender as $variableName) {
253 $valueToRender[$variableName] = $this->variables[$variableName] ??
null;
270 if (is_array($value) || $value instanceof \ArrayAccess) {
272 foreach ($value as $key => $element) {
287 if (is_object($value)) {
303 if ($object instanceof \DateTime) {
304 return $object->format(\DateTime::ATOM);
308 $propertiesToRender = [];
309 foreach ($propertyNames as $propertyName) {
319 if (!is_array($propertyValue) && !is_object($propertyValue)) {
320 $propertiesToRender[$propertyName] = $propertyValue;
329 $identityKey =
'__identity';
331 $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
334 $className = get_class($object);
335 $classNameParts = explode(
'\\', $className);
336 $propertiesToRender[
'__class'] = (
$configuration[
'_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED ? $className : array_pop($classNameParts));
339 return $propertiesToRender;