/** * @Flow\Before("method(TYPO3\Neos\Controller\Backend\ContentController->uploadAssetAction())") * @param JoinPointInterface $joinPoint The current join point * @return void */ public function rewriteSiteAssetCollection(JoinPointInterface $joinPoint) { if ($this->lookupNodeFilter === NULL || $this->lookupPropertyName === NULL) { return; } /** @var ContentController $contentController */ $contentController = $joinPoint->getProxy(); /** @var ActionRequest $actionRequest */ $actionRequest = ObjectAccess::getProperty($contentController, 'request', TRUE); $nodeContextPath = $actionRequest->getInternalArgument('__node'); if ($nodeContextPath === NULL) { return; } $node = $this->propertyMapper->convert($nodeContextPath, NodeInterface::class); $flowQuery = new FlowQuery(array($node)); /** @var NodeInterface $documentNode */ $documentNode = $flowQuery->closest($this->lookupNodeFilter)->get(0); if (!$documentNode->hasProperty($this->lookupPropertyName)) { return; } /** @var AssetCollection $assetCollection */ $assetCollection = $this->assetCollectionRepository->findByIdentifier($documentNode->getProperty($this->lookupPropertyName)); if ($assetCollection === NULL) { return; } /** @var Asset $asset */ $asset = $joinPoint->getMethodArgument('asset'); $assetCollection->addAsset($asset); $this->assetCollectionRepository->update($assetCollection); }
/** * @param string $identifier * @param array $issuerOrganizationConfiguration * @return IssuerOrganization */ protected function getIssuerOrganizationFromConfiguration($identifier, $issuerOrganizationConfiguration) { /** @var IssuerOrganization $issuerOrganization */ $issuerOrganization = $this->propertyMapper->convert($issuerOrganizationConfiguration, 'Networkteam\\OpenBadges\\Domain\\Model\\IssuerOrganization'); $issuerOrganization->setIdentifier($identifier); return $issuerOrganization; }
/** * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface|null $configuration * @return mixed|\Netlogix\JsonApiOrg\Schema\ResourceInterface|\TYPO3\Flow\Error\Error */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { if (is_string($source)) { $sourceArray = json_decode($source, true); $source = is_array($sourceArray) ? $sourceArray : ['id' => $source]; } if (!array_key_exists('type', $source)) { $dummyPayload = $this->objectManager->get($targetType); $typeIdentifier = $dummyPayload->getType(); $source['type'] = $this->exposableTypeMap->getType($typeIdentifier); } if (array_key_exists('id', $source)) { $arguments = $source['id']; } else { $arguments = []; } $payload = $this->propertyMapper->convert($arguments, $this->exposableTypeMap->getClassName($source['type'])); $resourceInformation = $this->resourceMapper->findResourceInformation($payload); $resource = $resourceInformation->getResource($payload); if (isset($source['attributes'])) { $attributes = $resource->getAttributes(); foreach ($source['attributes'] as $fieldName => $value) { $attributes[$fieldName] = $value; } } if (isset($source['relationships'])) { $relationships = $resource->getRelationships(); foreach ($source['relationships'] as $fieldName => $value) { $relationships[$fieldName] = $value; } } return $resource; }
/** * Convert raw property values to the correct type according to a node type configuration * * @param NodeType $nodeType * @param string $propertyName * @param string $rawValue * @param Context $context * @return mixed */ public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context) { $propertyType = $nodeType->getPropertyType($propertyName); switch ($propertyType) { case 'string': return $rawValue; case 'reference': return $this->convertReference($rawValue, $context); case 'references': return $this->convertReferences($rawValue, $context); case 'DateTime': return $this->convertDateTime($rawValue); case 'integer': return $this->convertInteger($rawValue); case 'boolean': return $this->convertBoolean($rawValue); case 'array': return $this->convertArray($rawValue); default: $innerType = $propertyType; if ($propertyType !== null) { try { $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($propertyType); $innerType = $parsedType['elementType'] ?: $parsedType['type']; } catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) { } } if (is_string($rawValue) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') { return $this->propertyMapper->convert(json_decode($rawValue, true), $propertyType, $configuration); } } }
/** * @param array $requestData * @return array * @throws \Exception * @throws \TYPO3\Flow\Property\Exception * @throws \TYPO3\Flow\Security\Exception */ public function resourceRequest(array $requestData) { /** @var Resource $resource */ $resource = $this->propertyMapper->convert($requestData[RequestStack::RESULT_DATA_IDENTIFIER], Resource::class); if (!$resource) { throw new \Exception('This request data can not be processed', 1452854971); } return json_decode(json_encode($resource), true); }
/** * Returns a previously uploaded resource. * If errors occurred during property mapping for this property, NULL is returned * * @return \TYPO3\Flow\Resource\Resource */ protected function getUploadedResource() { if ($this->getMappingResultsForProperty()->hasErrors()) { return NULL; } $resourceObject = $this->getValue(FALSE); if ($resourceObject instanceof \TYPO3\Flow\Resource\Resource) { return $resourceObject; } return $this->propertyMapper->convert($resourceObject, 'TYPO3\\Flow\\Resource\\Resource'); }
/** * Returns a previously uploaded image. * If errors occurred during property mapping for this property, NULL is returned * * @return \TYPO3\Media\Domain\Model\Image */ protected function getUploadedImage() { if ($this->getMappingResultsForProperty()->hasErrors()) { return NULL; } $image = $this->getValue(FALSE); if ($image instanceof \TYPO3\Media\Domain\Model\Image) { return $image; } return $this->propertyMapper->convert($image, 'TYPO3\\Media\\Domain\\Model\\Image'); }
/** * Returns a previously uploaded resource. * If errors occurred during property mapping for this property, NULL is returned * * @return Resource */ protected function getUploadedResource() { if ($this->getMappingResultsForProperty()->hasErrors()) { return null; } $resourceObject = $this->getValue(false); if ($resourceObject instanceof PersistentResource) { return $resourceObject; } return $this->propertyMapper->convert($resourceObject, PersistentResource::class); }
/** * Returns a previously uploaded image. * If errors occurred during property mapping for this property, NULL is returned * * @return Image */ protected function getUploadedImage() { if ($this->getMappingResultsForProperty()->hasErrors()) { return null; } $image = $this->getValue(false); if ($image instanceof Image) { return $image; } return $this->propertyMapper->convert($image, Image::class); }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * The return value can be one of three types: * - an arbitrary object, or a simple type (which has been created while mapping). * This is the normal case. * - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. * - An instance of \TYPO3\Flow\Error\Error -- This will be a user-visible error message later on. * Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened. * * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return mixed|\TYPO3\Flow\Error\Error the target type, or an error object if a user-error occurred * @throws \TYPO3\Flow\Property\Exception\TypeConverterException thrown in case a developer error occurred * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL) { $result = array(); $convertElements = $configuration->getConfigurationValue(\TYPO3\Flow\Persistence\Doctrine\ArrayTypeConverter::class, self::CONFIGURATION_CONVERT_ELEMENTS); foreach ($source as $element) { if ($convertElements === TRUE) { $element = $this->propertyMapper->convert($element, 'array', $configuration); } $result[] = $element; } return $result; }
/** * @test * @expectedException \TYPO3\Flow\Property\Exception */ public function entityWithImmutablePropertyCanNotBeUpdatedWhenImmutablePropertyChanged() { $result = $this->propertyMapper->convert($this->sourceProperties, \TYPO3\Flow\Tests\Functional\Property\Fixtures\TestEntityWithImmutableProperty::class); $identifier = $this->persistenceManager->getIdentifierByObject($result); $this->persistenceManager->add($result); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $update = array('__identity' => $identifier, 'age' => '25', 'name' => 'Christian D'); $result = $this->propertyMapper->convert($update, \TYPO3\Flow\Tests\Functional\Property\Fixtures\TestEntityWithImmutableProperty::class); $this->assertInstanceOf(\TYPO3\Flow\Tests\Functional\Property\Fixtures\TestEntityWithImmutableProperty::class, $result); $this->assertEquals('Christian M', $result->getName()); }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * The return value can be one of three types: * - an arbitrary object, or a simple type (which has been created while mapping). * This is the normal case. * - NULL, indicating that this object should *not* be mapped (i.e. a "File Upload" Converter could return NULL if no file has been uploaded, and a silent failure should occur. * - An instance of Error -- This will be a user-visible error message later on. * Furthermore, it should throw an Exception if an unexpected failure (like a security error) occurred or a configuration issue happened. * * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return mixed|Error the target type, or an error object if a user-error occurred * @throws TypeConverterException thrown in case a developer error occurred * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) { $result = []; $convertElements = $configuration->getConfigurationValue(ArrayTypeConverter::class, self::CONFIGURATION_CONVERT_ELEMENTS); foreach ($source as $element) { if ($convertElements === true) { $element = $this->propertyMapper->convert($element, 'array', $configuration); } $result[] = $element; } return $result; }
/** * Map the party from the given source data * * @param array $source * @return \TYPO3\Party\Domain\Model\AbstractParty */ protected function mapParty(array $source) { if (!isset($source['__type'])) { throw new Exception('Cannot map party without explicit type (server should return "__type" in party account data):' . json_encode($source), 1354111717); } $partyType = $source['__type']; unset($source['__type']); if (isset($this->typeMapping[$partyType])) { $partyType = $this->typeMapping[$partyType]; } $configuration = new TrustedPropertyMappingConfiguration(); // TODO Deal with mapping errors from property mapper return $this->propertyMapper->convert($source, $partyType, $configuration); }
/** * Returns the specified property. * * If the node has a content object attached, the property will be fetched * there if it is gettable. * * @param string $propertyName Name of the property * @param boolean $returnNodesAsIdentifiers If enabled, references to nodes are returned as node identifiers instead of NodeData objects * @return mixed value of the property * @api */ public function getProperty($propertyName, $returnNodesAsIdentifiers = false) { $value = $this->nodeData->getProperty($propertyName); if (!empty($value)) { $nodeType = $this->getNodeType(); if ($nodeType->hasConfiguration('properties.' . $propertyName)) { $expectedPropertyType = $nodeType->getPropertyType($propertyName); switch ($expectedPropertyType) { case 'references': if ($returnNodesAsIdentifiers === false) { $nodes = array(); foreach ($value as $nodeIdentifier) { $node = $this->context->getNodeByIdentifier($nodeIdentifier); // $node can be NULL if the node is not visible according to the current content context: if ($node !== null) { $nodes[] = $node; } } $value = $nodes; } break; case 'reference': if ($returnNodesAsIdentifiers === false) { $value = $this->context->getNodeByIdentifier($value); } break; default: $value = $this->propertyMapper->convert($value, $expectedPropertyType); break; } } } return $value; }
/** * Converts and adds ImageAdjustments to the ImageVariant * * @param ImageInterface $asset * @param mixed $source * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface $configuration * @return ImageInterface|NULL */ protected function applyTypeSpecificHandling($asset, $source, array $convertedChildProperties, PropertyMappingConfigurationInterface $configuration) { if ($asset instanceof ImageVariant) { $adjustments = []; if (isset($source['adjustments'])) { foreach ($source['adjustments'] as $adjustmentType => $adjustmentOptions) { if (isset($adjustmentOptions['__type'])) { $adjustmentType = $adjustmentOptions['__type']; unset($adjustmentOptions['__type']); } $identity = null; if (isset($adjustmentOptions['__identity'])) { $identity = $adjustmentOptions['__identity']; unset($adjustmentOptions['__identity']); } $adjustment = $this->propertyMapper->convert($adjustmentOptions, $adjustmentType, $configuration); if ($identity !== null) { ObjectAccess::setProperty($adjustment, 'persistence_object_identifier', $identity, true); } $adjustments[] = $adjustment; } } elseif (isset($source['processingInstructions'])) { $adjustments = $this->processingInstructionsConverter->convertFrom($source['processingInstructions'], 'array'); } if (count($adjustments) > 0) { $asset->addAdjustments($adjustments); } } return $asset; }
/** * @return \DateTime */ protected function getSelectedDate() { $date = $this->getValue(); if ($date instanceof \DateTime) { return $date; } if ($date !== NULL) { $date = $this->propertyMapper->convert($date, 'DateTime'); if (!$date instanceof \DateTime) { return NULL; } return $date; } if ($this->hasArgument('initialDate')) { return new \DateTime($this->arguments['initialDate']); } }
/** * Build the proper pluginRequest to render the PluginView * of some configured Master Plugin * * @return ActionRequest */ protected function buildPluginRequest() { /** @var $parentRequest ActionRequest */ $parentRequest = $this->tsRuntime->getControllerContext()->getRequest(); $pluginRequest = new ActionRequest($parentRequest); if (!$this->node instanceof NodeInterface) { $pluginRequest->setArgumentNamespace('--' . $this->getPluginNamespace()); $this->passArgumentsToPluginRequest($pluginRequest); $pluginRequest->setControllerPackageKey($this->getPackage()); $pluginRequest->setControllerSubpackageKey($this->getSubpackage()); $pluginRequest->setControllerName($this->getController()); $pluginRequest->setControllerActionName($this->getAction()); return $pluginRequest; } $pluginNodePath = $this->node->getProperty('plugin'); if (strlen($pluginNodePath) === 0) { return $pluginRequest; } $pluginViewName = $this->node->getProperty('view'); // Set the node to render this to the masterPlugin node $this->node = $this->propertyMapper->convert($pluginNodePath, 'TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); $pluginRequest->setArgument('__node', $this->node); $pluginRequest->setArgumentNamespace('--' . $this->getPluginNamespace()); $this->passArgumentsToPluginRequest($pluginRequest); if ($pluginRequest->getControllerObjectName() !== '') { return $pluginRequest; } $controllerObjectPairs = array(); foreach ($this->pluginService->getPluginViewDefinitionsByPluginNodeType($this->node->getNodeType()) as $pluginViewDefinition) { /** @var PluginViewDefinition $pluginViewDefinition */ if ($pluginViewDefinition->getName() !== $pluginViewName) { continue; } $controllerObjectPairs = $pluginViewDefinition->getControllerActionPairs(); break; } if ($controllerObjectPairs === array()) { return $pluginRequest; } $defaultControllerObjectName = key($controllerObjectPairs); $defaultActionName = current($controllerObjectPairs[$defaultControllerObjectName]); $pluginRequest->setControllerObjectName($defaultControllerObjectName); $pluginRequest->setControllerActionName($defaultActionName); return $pluginRequest; }
/** * @param array $contextArray * @return array */ public function unserializeContext(array $contextArray) { $unserializedContext = []; foreach ($contextArray as $variableName => $typeAndValue) { $value = $this->propertyMapper->convert($typeAndValue['value'], $typeAndValue['type']); $unserializedContext[$variableName] = $value; } return $unserializedContext; }
/** * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration * @return object the target type */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL) { if ($source === '') { return NULL; } // TODO: Check if we find a typo3.org user that match if (filter_var($source, FILTER_VALIDATE_EMAIL)) { $source = array('email' => $source); } else { if (!strpos(' ', $source)) { $source = array('username' => $source); } else { $source = array('name' => $source); } } /** @var \TYPO3\Flow\Mvc\Controller\MvcPropertyMappingConfiguration $configuration */ $configuration->allowAllProperties(); $configuration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, TRUE); return $this->propertyMapper->convert($source, $targetType, $configuration); }
/** * Generates an array of strings from the given array of context variables * * @param array $contextVariables * @return array * @throws \InvalidArgumentException */ protected function serializeContext(array $contextVariables) { $serializedContextArray = []; foreach ($contextVariables as $variableName => $contextValue) { // TODO This relies on a converter being available from the context value type to string if ($contextValue !== null) { $serializedContextArray[$variableName]['type'] = $this->getTypeForContextValue($contextValue); $serializedContextArray[$variableName]['value'] = $this->propertyMapper->convert($contextValue, 'string'); } } return $serializedContextArray; }
/** * Renders the URI to a given node instance or -path. * * @param ControllerContext $controllerContext * @param mixed $node A node object or a string node path, if a relative path is provided the baseNode argument is required * @param NodeInterface $baseNode * @param string $format Format to use for the URL, for example "html" or "json" * @param boolean $absolute If set, an absolute URI is rendered * @param array $arguments Additional arguments to be passed to the UriBuilder (for example pagination parameters) * @param string $section * @param boolean $addQueryString If set, the current query parameters will be kept in the URI * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE * @param boolean $resolveShortcuts INTERNAL Parameter - if FALSE, shortcuts are not redirected to their target. Only needed on rare backend occasions when we want to link to the shortcut itself. * @return string The rendered URI * @throws \InvalidArgumentException if the given node/baseNode is not valid * @throws NeosException if no URI could be resolved for the given node */ public function createNodeUri(ControllerContext $controllerContext, $node = null, NodeInterface $baseNode = null, $format = null, $absolute = false, array $arguments = array(), $section = '', $addQueryString = false, array $argumentsToBeExcludedFromQueryString = array(), $resolveShortcuts = true) { $this->lastLinkedNode = null; if (!($node instanceof NodeInterface || is_string($node) || $baseNode instanceof NodeInterface)) { throw new \InvalidArgumentException('Expected an instance of NodeInterface or a string for the node argument, or alternatively a baseNode argument.', 1373101025); } if (is_string($node)) { $nodeString = $node; if ($nodeString === '') { throw new NeosException(sprintf('Empty strings can not be resolved to nodes.', $nodeString), 1415709942); } preg_match(NodeInterface::MATCH_PATTERN_CONTEXTPATH, $nodeString, $matches); if (isset($matches['WorkspaceName']) && $matches['WorkspaceName'] !== '') { $node = $this->propertyMapper->convert($nodeString, 'TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); } else { if ($baseNode === null) { throw new NeosException('The baseNode argument is required for linking to nodes with a relative path.', 1407879905); } /** @var ContentContext $contentContext */ $contentContext = $baseNode->getContext(); $normalizedPath = $this->nodeService->normalizePath($nodeString, $baseNode->getPath(), $contentContext->getCurrentSiteNode()->getPath()); $node = $contentContext->getNode($normalizedPath); } if (!$node instanceof NodeInterface) { throw new NeosException(sprintf('The string "%s" could not be resolved to an existing node.', $nodeString), 1415709674); } } elseif (!$node instanceof NodeInterface) { $node = $baseNode; } if (!$node instanceof NodeInterface) { throw new NeosException(sprintf('Node must be an instance of NodeInterface or string, given "%s".', gettype($node)), 1414772029); } $this->lastLinkedNode = $node; if ($resolveShortcuts === true) { $resolvedNode = $this->nodeShortcutResolver->resolveShortcutTarget($node); } else { // this case is only relevant in extremely rare occasions in the Neos Backend, when we want to generate // a link towards the *shortcut itself*, and not to its target. $resolvedNode = $node; } if (is_string($resolvedNode)) { return $resolvedNode; } if (!$resolvedNode instanceof NodeInterface) { throw new NeosException(sprintf('Could not resolve shortcut target for node "%s"', $node->getPath()), 1414771137); } /** @var ActionRequest $request */ $request = $controllerContext->getRequest()->getMainRequest(); $uriBuilder = clone $controllerContext->getUriBuilder(); $uriBuilder->setRequest($request); $uri = $uriBuilder->reset()->setSection($section)->setCreateAbsoluteUri($absolute)->setArguments($arguments)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->setFormat($format ?: $request->getFormat())->uriFor('show', array('node' => $resolvedNode), 'Frontend\\Node', 'TYPO3.Neos'); return $uri; }
/** * @param BadgeClass $badgeClass * @return array */ public function badgeClassToArray(BadgeClass $badgeClass) { if ($badgeClass->getImage() !== NULL) { $helper = new \TYPO3\Media\ViewHelpers\Uri\ImageViewHelper(); $imageUri = $helper->render($badgeClass->getImage(), self::BADGE_IMAGE_SIZE, self::BADGE_IMAGE_SIZE, FALSE, FALSE); } else { $imageUri = NULL; } if (strpos($badgeClass->getCriteria(), 'http') === 0) { $criteriaUri = $badgeClass->getCriteria(); } else { $criteriaNode = $this->propertyMapper->convert($badgeClass->getCriteria(), 'TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); if ($criteriaNode === NULL) { $criteriaUri = NULL; } else { $criteriaUri = $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(TRUE)->setFormat('html')->uriFor('show', array('node' => $criteriaNode), 'Frontend\\Node', 'TYPO3.Neos'); } } $issuerUri = $this->controllerContext->getUriBuilder()->reset()->setCreateAbsoluteUri(TRUE)->setFormat('json')->uriFor('show', array('issuerOrganization' => $badgeClass->getIssuerIdentifier()), 'IssuerOrganization'); return array('name' => $badgeClass->getName(), 'description' => $badgeClass->getDescription(), 'image' => $imageUri, 'criteria' => $criteriaUri, 'issuer' => $issuerUri, 'tags' => $badgeClass->getTags()); }
/** * Convert raw property values to the correct type according to a node type configuration * * @param NodeType $nodeType * @param string $propertyName * @param string $rawValue * @param Context $context * @return mixed */ public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context) { $propertyType = $nodeType->getPropertyType($propertyName); switch ($propertyType) { case 'string': return $rawValue; case 'reference': return $this->convertReference($rawValue, $context); case 'references': return $this->convertReferences($rawValue, $context); case 'DateTime': return $this->convertDateTime($rawValue); case 'integer': return $this->convertInteger($rawValue); case 'boolean': return $this->convertBoolean($rawValue); case 'array': return $this->convertArray($rawValue); default: $innerType = $propertyType; if ($propertyType !== null) { try { $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($propertyType); $innerType = $parsedType['elementType'] ?: $parsedType['type']; } catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) { } } if ((is_string($rawValue) || is_array($rawValue)) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') { $propertyMappingConfiguration = new MvcPropertyMappingConfiguration(); $propertyMappingConfiguration->allowOverrideTargetType(); $propertyMappingConfiguration->allowAllProperties(); $propertyMappingConfiguration->skipUnknownProperties(); $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true); $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true); return $this->propertyMapper->convert($rawValue, $propertyType, $propertyMappingConfiguration); } else { return $rawValue; } } }
/** * @param mixed $value * @return mixed */ public function process($value) { if ($this->dataType !== null) { $value = $this->propertyMapper->convert($value, $this->dataType, $this->propertyMappingConfiguration); $messages = $this->propertyMapper->getMessages(); } else { $messages = new \TYPO3\Flow\Error\Result(); } $validationResult = $this->validator->validate($value); $messages->merge($validationResult); $this->processingMessages->merge($messages); return $value; }
/** * Returns the resource information with the highest priority being capable * of dealing with the given $payload. * * The controllerContext is added to the resource information object to allow * it to create proper URIs. * * @todo Use runtime cache based on spl_object_hash * @param mixed $payload * @return \Netlogix\JsonApiOrg\Resource\Information\ResourceInformationInterface */ public function findResourceInformation($payload) { if (is_array($payload) && isset($payload['type']) && isset($payload['id'])) { $payload = $this->propertyMapper->convert((string) $payload['id'], $this->exposableTypeMap->getClassName($payload['type'])); } /** @var ResourceInformationInterface $resourceInformation */ foreach ($this->resourceInformation as $resourceInformation) { if ($resourceInformation->canHandle($payload)) { return $resourceInformation; } } return null; }
/** * Parses the request body according to the media type. * * @param HttpRequest $httpRequest * @return array */ protected function parseRequestBody(HttpRequest $httpRequest) { $requestBody = $httpRequest->getContent(); if ($requestBody === null || $requestBody === '') { return []; } $mediaTypeConverter = $this->objectManager->get(MediaTypeConverterInterface::class); $propertyMappingConfiguration = new PropertyMappingConfiguration(); $propertyMappingConfiguration->setTypeConverter($mediaTypeConverter); $propertyMappingConfiguration->setTypeConverterOption(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, $httpRequest->getHeader('Content-Type')); $arguments = $this->propertyMapper->convert($requestBody, 'array', $propertyMappingConfiguration); return $arguments; }
/** * @param HttpRequest $httpRequest * @param array $routingMatchResults * @return array */ protected function mergeArguments(HttpRequest $httpRequest, array $routingMatchResults = NULL) { // HTTP body arguments $this->propertyMappingConfiguration->setTypeConverterOption(\TYPO3\Flow\Property\TypeConverter\MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, $httpRequest->getHeader('Content-Type')); $arguments = $this->propertyMapper->convert($httpRequest->getContent(), 'array', $this->propertyMappingConfiguration); // HTTP arguments (e.g. GET parameters) $arguments = Arrays::arrayMergeRecursiveOverrule($httpRequest->getArguments(), $arguments); // Routing results if ($routingMatchResults !== NULL) { $arguments = Arrays::arrayMergeRecursiveOverrule($arguments, $routingMatchResults); } return $arguments; }
/** * Writes out a single property into the XML structure. * * @param array $data The data as an array, the given property name is looked up there * @param string $propertyName The name of the property * @param string $elementName an optional name to use, defaults to $propertyName * @return void */ protected function writeConvertedElement(array &$data, $propertyName, $elementName = null, $declaredPropertyType = null) { if (array_key_exists($propertyName, $data) && $data[$propertyName] !== null) { $propertyValue = $data[$propertyName]; $this->xmlWriter->startElement($elementName ?: $propertyName); if (!empty($propertyValue)) { switch ($declaredPropertyType) { case null: case 'reference': case 'references': break; default: $propertyValue = $this->propertyMapper->convert($propertyValue, $declaredPropertyType); break; } } $this->xmlWriter->writeAttribute('__type', gettype($propertyValue)); try { if (is_object($propertyValue) && !$propertyValue instanceof \DateTime) { $objectIdentifier = $this->persistenceManager->getIdentifierByObject($propertyValue); if ($objectIdentifier !== null) { $this->xmlWriter->writeAttribute('__identifier', $objectIdentifier); } if ($propertyValue instanceof \Doctrine\ORM\Proxy\Proxy) { $className = get_parent_class($propertyValue); } else { $className = get_class($propertyValue); } $this->xmlWriter->writeAttribute('__classname', $className); $this->xmlWriter->writeAttribute('__encoding', 'json'); $converted = json_encode($this->propertyMapper->convert($propertyValue, 'array', $this->propertyMappingConfiguration)); $this->xmlWriter->text($converted); } elseif (is_array($propertyValue)) { foreach ($propertyValue as $key => $element) { $this->writeConvertedElement($propertyValue, $key, 'entry' . $key); } } else { if ($propertyValue instanceof \DateTime) { $this->xmlWriter->writeAttribute('__classname', 'DateTime'); } $this->xmlWriter->text($this->propertyMapper->convert($propertyValue, 'string', $this->propertyMappingConfiguration)); } } catch (\Exception $exception) { $this->xmlWriter->writeComment(sprintf('Could not convert property "%s" to string.', $propertyName)); $this->xmlWriter->writeComment($exception->getMessage()); $this->systemLogger->logException($exception); $this->exceptionsDuringExport[] = $exception; } $this->xmlWriter->endElement(); } }
/** * @test */ public function persistentEntityCanBeSerializedToIdentifierUsingObjectSource() { $entity = new Fixtures\TestEntity(); $entity->setName('Egon Olsen'); $entity->setAge(42); $entity->setAverageNumberOfKids(3.5); $this->persistenceManager->add($entity); $entityIdentifier = $this->persistenceManager->getIdentifierByObject($entity); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $source = $entity; $result = $this->propertyMapper->convert($source, 'string'); $this->assertSame($entityIdentifier, $result); }
/** * Calls a behat step method * * @Flow\Internal * @param string $testHelperObjectName * @param string $methodName * @param boolean $withoutSecurityChecks */ public function callBehatStepCommand($testHelperObjectName, $methodName, $withoutSecurityChecks = FALSE) { $testHelper = $this->objectManager->get($testHelperObjectName); $rawMethodArguments = $this->request->getExceedingArguments(); $mappedArguments = array(); for ($i = 0; $i < count($rawMethodArguments); $i += 2) { $mappedArguments[] = $this->propertyMapper->convert($rawMethodArguments[$i + 1], $rawMethodArguments[$i]); } $result = NULL; try { if ($withoutSecurityChecks === TRUE) { $this->securityContext->withoutAuthorizationChecks(function () use($testHelper, $methodName, $mappedArguments, &$result) { $result = call_user_func_array(array($testHelper, $methodName), $mappedArguments); }); } else { $result = call_user_func_array(array($testHelper, $methodName), $mappedArguments); } } catch (\Exception $exception) { $this->outputLine('EXCEPTION: %s %d %s in %s:%s %s', array(get_class($exception), $exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString())); return; } $this->output('SUCCESS: %s', array($result)); }