本文整理汇总了PHP中TYPO3\Flow\Property\PropertyMapper类的典型用法代码示例。如果您正苦于以下问题:PHP PropertyMapper类的具体用法?PHP PropertyMapper怎么用?PHP PropertyMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PropertyMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
*/
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);
}
示例2: importWithArrayPropertiesImportsCorrectly
/**
* @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);
}
示例3: handleMergesInternalArgumentsWithRoutingMatchResults
/**
* @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);
}
示例4: rewriteSiteAssetCollection
/**
* @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);
}
示例5: convertFrom
/**
* @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;
}
示例6: convert
/**
* 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);
}
}
}
示例7: getIssuerOrganizationFromConfiguration
/**
* @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;
}
开发者ID:christophlehmann,项目名称:Networkteam.OpenBadges,代码行数:12,代码来源:ConfigurableIssuerOrganizationsRepository.php
示例8: resourceRequest
/**
* @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);
}
示例9: getUploadedResource
/**
* 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');
}
示例10: getUploadedImage
/**
* 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');
}
示例11: getUploadedResource
/**
* 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);
}
示例12: getUploadedImage
/**
* 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);
}
示例13: entityWithImmutablePropertyCanNotBeUpdatedWhenImmutablePropertyChanged
/**
* @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());
}
示例14: convertFrom
/**
* 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;
}
示例15: convertFrom
/**
* 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;
}