PHP Class Neos\Flow\Mvc\View\JsonView

Inheritance: extends AbstractView
Afficher le fichier Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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

renderArray() protected méthode

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

setConfiguration() public méthode

public setConfiguration ( array $configuration ) : void
$configuration array The rendering configuration for this JSON view
Résultat void

setVariablesToRender() public méthode

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

transformObject() protected méthode

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
Résultat array Object structure as an array

transformValue() protected méthode

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
Résultat 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
Résultat array

$controllerContext protected_oe property

protected ControllerContext,Neos\Flow\Mvc\Controller $controllerContext
Résultat Neos\Flow\Mvc\Controller\ControllerContext

$persistenceManager protected_oe property

protected PersistenceManagerInterface,Neos\Flow\Persistence $persistenceManager
Résultat Neos\Flow\Persistence\PersistenceManagerInterface

$supportedOptions protected_oe property

Supported options
protected array $supportedOptions
Résultat array

$variablesToRender protected_oe property

Only variables whose name is contained in this array will be rendered
protected array $variablesToRender
Résultat array