コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * @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 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;
 }
コード例 #5
0
 /**
  * @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);
 }
コード例 #6
0
 /**
  * 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');
 }
コード例 #7
0
 /**
  * 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');
 }
コード例 #8
0
 /**
  * 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);
 }
コード例 #9
0
 /**
  * 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);
 }
 /**
  * @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());
 }
コード例 #11
0
 /**
  * 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;
 }
コード例 #12
0
 /**
  * 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;
 }
コード例 #13
0
 /**
  * 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);
 }
 /**
  */
 public function setUp()
 {
     $this->ajaxWidgetComponent = new AjaxWidgetComponent();
     $this->mockObjectManager = $this->getMockBuilder(\TYPO3\Flow\Object\ObjectManagerInterface::class)->getMock();
     $this->inject($this->ajaxWidgetComponent, 'objectManager', $this->mockObjectManager);
     $this->mockComponentContext = $this->getMockBuilder(\TYPO3\Flow\Http\Component\ComponentContext::class)->disableOriginalConstructor()->getMock();
     $this->mockHttpRequest = $this->getMockBuilder(\TYPO3\Flow\Http\Request::class)->disableOriginalConstructor()->getMock();
     $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(array()));
     $this->mockComponentContext->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest));
     $this->mockHttpResponse = $this->getMockBuilder(\TYPO3\Flow\Http\Response::class)->disableOriginalConstructor()->getMock();
     $this->mockComponentContext->expects($this->any())->method('getHttpResponse')->will($this->returnValue($this->mockHttpResponse));
     $this->mockAjaxWidgetContextHolder = $this->getMockBuilder(\TYPO3\Fluid\Core\Widget\AjaxWidgetContextHolder::class)->getMock();
     $this->inject($this->ajaxWidgetComponent, 'ajaxWidgetContextHolder', $this->mockAjaxWidgetContextHolder);
     $this->mockHashService = $this->getMockBuilder(\TYPO3\Flow\Security\Cryptography\HashService::class)->getMock();
     $this->inject($this->ajaxWidgetComponent, 'hashService', $this->mockHashService);
     $this->mockDispatcher = $this->getMockBuilder(\TYPO3\Flow\Mvc\Dispatcher::class)->getMock();
     $this->inject($this->ajaxWidgetComponent, 'dispatcher', $this->mockDispatcher);
     $this->mockSecurityContext = $this->getMockBuilder(\TYPO3\Flow\Security\Context::class)->getMock();
     $this->inject($this->ajaxWidgetComponent, 'securityContext', $this->mockSecurityContext);
     $this->mockPropertyMappingConfiguration = $this->getMockBuilder(\TYPO3\Flow\Property\PropertyMappingConfiguration::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->ajaxWidgetComponent, 'propertyMappingConfiguration', $this->mockPropertyMappingConfiguration);
     $this->mockPropertyMapper = $this->getMockBuilder(\TYPO3\Flow\Property\PropertyMapper::class)->disableOriginalConstructor()->getMock();
     $this->mockPropertyMapper->expects($this->any())->method('convert')->with('', 'array', $this->mockPropertyMappingConfiguration)->will($this->returnValue(array()));
     $this->inject($this->ajaxWidgetComponent, 'propertyMapper', $this->mockPropertyMapper);
 }
コード例 #15
0
 /**
  * @test
  */
 public function importWithArrayPropertiesImportsCorrectly()
 {
     $xmlReader = new \XMLReader();
     $result = $xmlReader->open(__DIR__ . '/Fixtures/NodesWithArrayProperties.xml', null, LIBXML_PARSEHUGE);
     $this->assertTrue($result);
     /** @var \TYPO3\TYPO3CR\Domain\Service\ImportExport\NodeImportService $nodeImportService */
     $nodeImportService = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\ImportExport\\NodeImportService', array('persistNodeData'));
     $this->inject($nodeImportService, 'propertyMapper', $this->mockPropertyMapper);
     $this->inject($nodeImportService, 'securityContext', $this->mockSecurityContext);
     $expectedNodeDatas = array(array('identifier' => 'e45e3b2c-3f14-2c14-6230-687fa4696504', 'nodeType' => 'TYPO3.Neos.NodeTypes:Page', 'workspace' => 'live', 'sortingIndex' => '300', 'version' => '3', 'removed' => false, 'hidden' => false, 'hiddenInIndex' => false, 'path' => 'node53a18fb53bdf2', 'pathHash' => '3f1d4fea7c0b21d21098960149de9c80', 'parentPath' => '/', 'parentPathHash' => '6666cd76f96956469e7be39d750cc7d9', 'properties' => array('foos' => array(0 => 'content of entry0', 1 => 'content of entry1'), 'bar' => 'a bar walks into a foo', 'empty' => null, 'bars' => array()), 'accessRoles' => array(), 'dimensionValues' => array('language' => array('en_US'))));
     $nodeImportService->expects($this->atLeastOnce())->method('persistNodeData')->will($this->returnCallback(function ($nodeData) use(&$actualNodeDatas) {
         unset($nodeData['Persistence_Object_Identifier']);
         $actualNodeDatas[] = $nodeData;
         return true;
     }));
     $this->mockPropertyMapper->expects($this->any())->method('convert')->will($this->returnCallback(function ($source, $targetType) {
         return array('targetType' => $targetType, 'source' => $source);
     }));
     $nodeImportService->import($xmlReader, '/');
     $this->assertInstanceOf('DateTime', $actualNodeDatas[0]['creationDateTime']);
     $this->assertInstanceOf('DateTime', $actualNodeDatas[0]['lastModificationDateTime']);
     unset($actualNodeDatas[0]['creationDateTime']);
     unset($actualNodeDatas[0]['lastModificationDateTime']);
     $this->assertEquals($expectedNodeDatas, $actualNodeDatas);
 }
 /**
  * Lists all currently active and registered type converters
  *
  * All active converters are listed with ordered by priority and grouped by
  * source type first and target type second.
  *
  * @return void
  */
 public function listCommand()
 {
     foreach ($this->propertyMapper->getTypeConverters() as $sourceType => $targetTypePriorityAndInstance) {
         $this->outputLine();
         $this->outputLine('<b>Source type "%s":</b>', [$sourceType]);
         foreach ($targetTypePriorityAndInstance as $targetType => $priorityAndInstance) {
             $this->outputFormatted('<b>Target type "%s":</b>', [$targetType], 4);
             krsort($priorityAndInstance);
             foreach ($priorityAndInstance as $priority => $instance) {
                 $this->outputFormatted('%3s: %s', [$priority, get_class($instance)], 8);
             }
             $this->outputLine();
         }
         $this->outputLine();
     }
 }
 /**
  * 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;
 }
コード例 #18
0
 /**
  * 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;
 }
コード例 #19
0
 /**
  * @test
  */
 public function handleMergesInternalArgumentsWithRoutingMatchResults()
 {
     $this->mockHttpRequest->expects($this->any())->method('getArguments')->will($this->returnValue(array('__internalArgument1' => 'request', '__internalArgument2' => 'request', '__internalArgument3' => 'request')));
     $this->mockPropertyMapper->expects($this->any())->method('convert')->with('', 'array', $this->mockPropertyMappingConfiguration)->will($this->returnValue(array('__internalArgument2' => 'requestBody', '__internalArgument3' => 'requestBody')));
     $this->mockComponentContext->expects($this->atLeastOnce())->method('getParameter')->with('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'matchResults')->will($this->returnValue(array('__internalArgument3' => 'routing')));
     $this->mockActionRequest->expects($this->once())->method('setArguments')->with(array('__internalArgument1' => 'request', '__internalArgument2' => 'requestBody', '__internalArgument3' => 'routing'));
     $this->dispatchComponent->handle($this->mockComponentContext);
 }
コード例 #20
0
 /**
  * @test
  */
 public function getTargetPropertyNameShouldReturnTheUnmodifiedPropertyNameWithoutConfiguration()
 {
     $defaultConfiguration = $this->propertyMapper->buildPropertyMappingConfiguration();
     $this->assertTrue($defaultConfiguration->getConfigurationValue(\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
     $this->assertTrue($defaultConfiguration->getConfigurationValue(\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
     $this->assertNull($defaultConfiguration->getConfigurationFor('foo')->getConfigurationValue(\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
     $this->assertNull($defaultConfiguration->getConfigurationFor('foo')->getConfigurationValue(\TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::class, \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));
 }
コード例 #21
0
 /**
  * @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']);
     }
 }
コード例 #22
0
 /**
  * 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;
 }
コード例 #23
0
 /**
  * @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;
 }
コード例 #24
0
 /**
  * @test
  */
 public function processConvertsValueIfDataTypeIsSpecified()
 {
     $this->processingRule->setDataType('SomeDataType');
     $mockPropertyMappingConfiguration = $this->getMockBuilder('TYPO3\\Flow\\Property\\PropertyMappingConfiguration')->getMock();
     $this->processingRule->_set('propertyMappingConfiguration', $mockPropertyMappingConfiguration);
     $this->mockPropertyMapper->expects($this->once())->method('convert')->with('Some Value', 'SomeDataType', $mockPropertyMappingConfiguration)->will($this->returnValue('Converted Value'));
     $this->mockPropertyMapper->expects($this->any())->method('getMessages')->will($this->returnValue(new \TYPO3\Flow\Error\Result()));
     $this->assertEquals('Converted Value', $this->processingRule->process('Some Value'));
 }
コード例 #25
0
 /**
  * @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);
 }
コード例 #26
0
 /**
  * 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;
 }
コード例 #27
0
 /**
  * @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());
 }
コード例 #28
0
 /**
  * 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;
 }
コード例 #29
0
 /**
  * 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;
             }
     }
 }
コード例 #30
0
ファイル: ProcessingRule.php プロジェクト: kitsunet/form
 /**
  * @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;
 }