2 namespace TYPO3\CMS\Extbase\Mvc\View;
213 $response = $this->controllerContext->getResponse();
218 $typoScriptFrontendController =
$GLOBALS[
'TSFE'];
219 if (empty($typoScriptFrontendController->config[
'config'][
'disableCharsetHeader'])) {
222 $typoScriptFrontendController->setContentType(
'application/json');
227 $response->setHeader(
'Content-Type',
'application/json; charset=' . trim($typoScriptFrontendController->metaCharset));
230 $response->setHeader(
'Content-Type',
'application/json');
234 return json_encode($propertiesToRender);
246 if (count($this->variablesToRender) === 1) {
247 $variableName = current($this->variablesToRender);
248 $valueToRender = isset($this->variables[$variableName]) ? $this->variables[$variableName] : null;
249 $configuration = isset($this->configuration[$variableName]) ? $this->configuration[$variableName] : array();
251 $valueToRender = array();
252 foreach ($this->variablesToRender as $variableName) {
253 $valueToRender[$variableName] = isset($this->variables[$variableName]) ? $this->variables[$variableName] : null;
270 if (is_array($value) || $value instanceof \ArrayAccess) {
272 foreach ($value as $key => $element) {
273 if (isset($configuration[
'_descendAll']) && is_array($configuration[
'_descendAll'])) {
274 $array[$key] = $this->
transformValue($element, $configuration[
'_descendAll']);
276 if (isset($configuration[
'_only']) && is_array($configuration[
'_only']) && !in_array($key, $configuration[
'_only'])) {
279 if (isset($configuration[
'_exclude']) && is_array($configuration[
'_exclude']) && in_array($key, $configuration[
'_exclude'])) {
282 $array[$key] = $this->
transformValue($element, isset($configuration[$key]) ? $configuration[$key] : array());
286 }
elseif (is_object($value)) {
303 if ($object instanceof \DateTime) {
304 return $object->format(\DateTime::ISO8601);
306 $propertyNames = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettablePropertyNames($object);
308 $propertiesToRender = array();
309 foreach ($propertyNames as $propertyName) {
310 if (isset($configuration[
'_only']) && is_array($configuration[
'_only']) && !in_array($propertyName, $configuration[
'_only'])) {
313 if (isset($configuration[
'_exclude']) && is_array($configuration[
'_exclude']) && in_array($propertyName, $configuration[
'_exclude'])) {
317 $propertyValue = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($object, $propertyName);
319 if (!is_array($propertyValue) && !is_object($propertyValue)) {
320 $propertiesToRender[$propertyName] = $propertyValue;
321 }
elseif (isset($configuration[
'_descend']) && array_key_exists($propertyName, $configuration[
'_descend'])) {
322 $propertiesToRender[$propertyName] = $this->
transformValue($propertyValue, $configuration[
'_descend'][$propertyName]);
325 if (isset($configuration[
'_exposeObjectIdentifier']) && $configuration[
'_exposeObjectIdentifier'] ===
true) {
326 if (isset($configuration[
'_exposedObjectIdentifierKey']) && strlen($configuration[
'_exposedObjectIdentifierKey']) > 0) {
327 $identityKey = $configuration[
'_exposedObjectIdentifierKey'];
329 $identityKey =
'__identity';
331 $propertiesToRender[$identityKey] = $this->persistenceManager->getIdentifierByObject($object);
333 if (isset($configuration[
'_exposeClassName']) && ($configuration[
'_exposeClassName'] === self::EXPOSE_CLASSNAME_FULLY_QUALIFIED || $configuration[
'_exposeClassName'] === self::EXPOSE_CLASSNAME_UNQUALIFIED)) {
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;