PHP Class Neos\Flow\Mvc\View\JsonView

Inheritance: extends AbstractView
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$configuration array The configuration array must have the following structure: Example 1: array( 'variable1' => array( '_only' => array('property1', 'property2', ...) ), 'variable2' => array( '_exclude' => array('property3', 'property4, ...) ), 'variable3' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( '_only' => array('firstName', 'lastName') ) ) ), 'somearrayvalue' => array( '_descendAll' => array( '_only' => array('property1') ) ) ) Of variable1 only property1 and property2 will be included. Of variable2 all properties except property3 and property4 are used. Of variable3 all properties except secretTitle are included. If a property value is an array or object, it is not included by default. If, however, such a property is listed in a "_descend" section, the renderer will descend into this sub structure and include all its properties (of the next level). The configuration of each property in "_descend" has the same syntax like at the top level. Therefore - theoretically - infinitely nested structures can be configured. To export indexed arrays the "_descendAll" section can be used to include all array keys for the output. The configuration inside a "_descendAll" will be applied to each array element. Example 2: exposing object identifier array( 'variableFoo' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( // consider 'customer' being a persisted entity '_only' => array('firstName'), '_exposeObjectIdentifier' => TRUE, '_exposedObjectIdentifierKey' => 'guid' ) ) ) ) Note for entity objects you are able to expose the object's identifier also, just add an "_exposeObjectIdentifier" directive set to TRUE and an additional property '__identity' will appear keeping the persistence identifier. Renaming that property name instead of '__identity' is also possible with the directive "_exposedObjectIdentifierKey". Example 2 above would output (summarized): {"customer":{"firstName":"John","guid":"892693e4-b570-46fe-af71-1ad32918fb64"}} Example 3: exposing object's class name array( 'variableFoo' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( // consider 'customer' being an object '_only' => array('firstName'), '_exposeClassName' => Neos\Flow\Mvc\View\JsonView::EXPOSE_CLASSNAME_FULLY_QUALIFIED ) ) ) ) The _exposeClassName is similar to the objectIdentifier one, but the class name is added to the JSON object output, for example (summarized): {"customer":{"firstName":"John","__class":"Acme\Foo\Domain\Model\Customer"}} The other option is EXPOSE_CLASSNAME_UNQUALIFIED which only will give the last part of the class without the namespace, for example (summarized): {"customer":{"firstName":"John","__class":"Customer"}} This might be of interest to not provide information about the package or domain structure behind.
$controllerContext Neos\Flow\Mvc\Controller\ControllerContext
$persistenceManager Neos\Flow\Persistence\PersistenceManagerInterface
$supportedOptions array Supported options
$variablesToRender array Only variables whose name is contained in this array will be rendered

Public Methods

Method Description
render ( ) : string Transforms the value view variable to a serializable array represantion using a YAML view configuration and JSON encodes the result.
setConfiguration ( array $configuration ) : void
setVariablesToRender ( array $variablesToRender ) : void Specifies which variables this JsonView should render By default only the variable 'value' will be rendered

Protected Methods

Method Description
renderArray ( ) : array Loads the configuration and transforms the value to a serializable array.
transformObject ( object $object, array $configuration ) : array Traverses the given object structure in order to transform it into an array structure.
transformValue ( mixed $value, array $configuration ) : array Transforms a value depending on type recursively using the supplied configuration.

Method Details

render() public method

Transforms the value view variable to a serializable array represantion using a YAML view configuration and JSON encodes the result.
public render ( ) : string
return string The JSON encoded variables

renderArray() protected method

Loads the configuration and transforms the value to a serializable array.
protected renderArray ( ) : array
return array An array containing the values, ready to be JSON encoded

setConfiguration() public method

public setConfiguration ( array $configuration ) : void
$configuration array The rendering configuration for this JSON view
return void

setVariablesToRender() public method

Specifies which variables this JsonView should render By default only the variable 'value' will be rendered
public setVariablesToRender ( array $variablesToRender ) : void
$variablesToRender array
return void

transformObject() protected method

Traverses the given object structure in order to transform it into an array structure.
protected transformObject ( object $object, array $configuration ) : array
$object object Object to traverse
$configuration array Configuration for transforming the given object or NULL
return array Object structure as an array

transformValue() protected method

Transforms a value depending on type recursively using the supplied configuration.
protected transformValue ( mixed $value, array $configuration ) : array
$value mixed The value to transform
$configuration array Configuration for transforming the value
return array The transformed value

Property Details

$configuration protected_oe property

The configuration array must have the following structure: Example 1: array( 'variable1' => array( '_only' => array('property1', 'property2', ...) ), 'variable2' => array( '_exclude' => array('property3', 'property4, ...) ), 'variable3' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( '_only' => array('firstName', 'lastName') ) ) ), 'somearrayvalue' => array( '_descendAll' => array( '_only' => array('property1') ) ) ) Of variable1 only property1 and property2 will be included. Of variable2 all properties except property3 and property4 are used. Of variable3 all properties except secretTitle are included. If a property value is an array or object, it is not included by default. If, however, such a property is listed in a "_descend" section, the renderer will descend into this sub structure and include all its properties (of the next level). The configuration of each property in "_descend" has the same syntax like at the top level. Therefore - theoretically - infinitely nested structures can be configured. To export indexed arrays the "_descendAll" section can be used to include all array keys for the output. The configuration inside a "_descendAll" will be applied to each array element. Example 2: exposing object identifier array( 'variableFoo' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( // consider 'customer' being a persisted entity '_only' => array('firstName'), '_exposeObjectIdentifier' => TRUE, '_exposedObjectIdentifierKey' => 'guid' ) ) ) ) Note for entity objects you are able to expose the object's identifier also, just add an "_exposeObjectIdentifier" directive set to TRUE and an additional property '__identity' will appear keeping the persistence identifier. Renaming that property name instead of '__identity' is also possible with the directive "_exposedObjectIdentifierKey". Example 2 above would output (summarized): {"customer":{"firstName":"John","guid":"892693e4-b570-46fe-af71-1ad32918fb64"}} Example 3: exposing object's class name array( 'variableFoo' => array( '_exclude' => array('secretTitle'), '_descend' => array( 'customer' => array( // consider 'customer' being an object '_only' => array('firstName'), '_exposeClassName' => Neos\Flow\Mvc\View\JsonView::EXPOSE_CLASSNAME_FULLY_QUALIFIED ) ) ) ) The _exposeClassName is similar to the objectIdentifier one, but the class name is added to the JSON object output, for example (summarized): {"customer":{"firstName":"John","__class":"Acme\Foo\Domain\Model\Customer"}} The other option is EXPOSE_CLASSNAME_UNQUALIFIED which only will give the last part of the class without the namespace, for example (summarized): {"customer":{"firstName":"John","__class":"Customer"}} This might be of interest to not provide information about the package or domain structure behind.
protected array $configuration
return array

$controllerContext protected_oe property

protected ControllerContext,Neos\Flow\Mvc\Controller $controllerContext
return Neos\Flow\Mvc\Controller\ControllerContext

$persistenceManager protected_oe property

protected PersistenceManagerInterface,Neos\Flow\Persistence $persistenceManager
return Neos\Flow\Persistence\PersistenceManagerInterface

$supportedOptions protected_oe property

Supported options
protected array $supportedOptions
return array

$variablesToRender protected_oe property

Only variables whose name is contained in this array will be rendered
protected array $variablesToRender
return array