/**
  */
 public function setUp()
 {
     ComposerUtility::flushCaches();
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder(\Neos\Flow\Package\PackageManager::class)->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), true);
 }
 /**
  * @test
  */
 public function ignoredClassesCanBeOverwrittenBySettings()
 {
     $object = new ApplicationContext('Development');
     $this->assertEquals(sprintf('%s prototype object', ApplicationContext::class), Debugger::renderDump($object, 10, true));
     Debugger::clearState();
     $currentConfiguration = ObjectAccess::getProperty($this->configurationManager, 'configurations', true);
     $configurationOverwrite['Settings']['Neos']['Flow']['error']['debugger']['ignoredClasses']['Neos\\\\Flow\\\\Core\\\\.*'] = false;
     $newConfiguration = Arrays::arrayMergeRecursiveOverrule($currentConfiguration, $configurationOverwrite);
     ObjectAccess::setProperty($this->configurationManager, 'configurations', $newConfiguration, true);
     $this->assertContains('rootContextString', Debugger::renderDump($object, 10, true));
 }
 /**
  * Builds a transformation object from the given configuration.
  *
  * @param array $transformationConfiguration
  * @return TransformationInterface
  * @throws MigrationException if a given setting is not supported
  */
 protected function buildTransformationObject($transformationConfiguration)
 {
     $transformationClassName = $this->resolveTransformationClassName($transformationConfiguration['type']);
     $transformation = new $transformationClassName();
     foreach ($transformationConfiguration['settings'] as $settingName => $settingValue) {
         if (!ObjectAccess::setProperty($transformation, $settingName, $settingValue)) {
             throw new MigrationException('Cannot set setting "' . $settingName . '" on transformation "' . $transformationClassName . '" , check your configuration.', 1343293094);
         }
     }
     return $transformation;
 }
 /**
  * WARNING: If using this step definition, IT MUST RUN AS ABSOLUTELY FIRST STEP IN A SCENARIO!
  *
  * @Given /^I have the following policies:$/
  */
 public function iHaveTheFollowingPolicies($string)
 {
     if ($this->subProcess !== null) {
         // This check ensures that this statement is ran *before* a subprocess is opened; as the Policy.yaml
         // which is set here influences the Proxy Building Process.
         throw new \Exception('Step "I have the following policies:" must run as FIRST step in a scenario, because otherwise the proxy-classes are already built in the wrong manner!');
     }
     self::$testingPolicyPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Policy.yaml';
     file_put_contents(self::$testingPolicyPathAndFilename, $string->getRaw());
     $configurationManager = $this->objectManager->get(ConfigurationManager::class);
     $configurations = ObjectAccess::getProperty($configurationManager, 'configurations', true);
     unset($configurations[ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_POLICY]);
     ObjectAccess::setProperty($configurationManager, 'configurations', $configurations, true);
     $policyService = $this->objectManager->get(PolicyService::class);
     ObjectAccess::setProperty($policyService, 'initialized', false, true);
 }
 /**
  * @test
  * @dataProvider attributeExamples
  */
 public function evaluateTests($properties, $expectedOutput)
 {
     $path = 'attributes/test';
     $this->mockTsRuntime->expects($this->any())->method('evaluate')->will($this->returnCallback(function ($evaluatePath, $that) use($path, $properties) {
         $relativePath = str_replace($path . '/', '', $evaluatePath);
         return ObjectAccess::getPropertyPath($properties, str_replace('/', '.', $relativePath));
     }));
     $typoScriptObjectName = 'Neos.Fusion:Attributes';
     $renderer = new AttributesImplementation($this->mockTsRuntime, $path, $typoScriptObjectName);
     if ($properties !== null) {
         foreach ($properties as $name => $value) {
             ObjectAccess::setProperty($renderer, $name, $value);
         }
     }
     $result = $renderer->evaluate();
     $this->assertEquals($expectedOutput, $result);
 }
 /**
  * @param string $dataSourceIdentifier
  * @param NodeInterface $node
  * @return string
  * @throws NeosException
  */
 public function indexAction($dataSourceIdentifier, NodeInterface $node = null)
 {
     $dataSources = static::getDataSources($this->objectManager);
     if (!isset($dataSources[$dataSourceIdentifier])) {
         throw new NeosException(sprintf('Data source with identifier "%s" does not exist.', $dataSourceIdentifier), 1414088186);
     }
     /** @var $dataSource DataSourceInterface */
     $dataSource = new $dataSources[$dataSourceIdentifier]();
     if (ObjectAccess::isPropertySettable($dataSource, 'controllerContext')) {
         ObjectAccess::setProperty($dataSource, 'controllerContext', $this->controllerContext);
     }
     $arguments = $this->request->getArguments();
     unset($arguments['dataSourceIdentifier']);
     unset($arguments['node']);
     $values = $dataSource->getData($node, $arguments);
     $this->view->assign('value', $values);
 }
Esempio n. 7
0
 /**
  * Factory method which creates the specified transport with the given options.
  *
  * @param string $transportType Object name of the transport to create
  * @param array $transportOptions Options for the transport
  * @param array $transportArguments Constructor arguments for the transport
  * @return \Neos\SwiftMailer\TransportInterface The created transport instance
  * @throws Exception
  */
 public function create($transportType, array $transportOptions = array(), array $transportArguments = null)
 {
     if (!class_exists($transportType)) {
         throw new Exception('The specified transport backend "' . $transportType . '" does not exist.', 1269351207);
     }
     if (is_array($transportArguments)) {
         $class = new \ReflectionClass($transportType);
         $transport = $class->newInstanceArgs($transportArguments);
     } else {
         $transport = new $transportType();
     }
     foreach ($transportOptions as $optionName => $optionValue) {
         if (ObjectAccess::isPropertySettable($transport, $optionName)) {
             ObjectAccess::setProperty($transport, $optionName, $optionValue);
         }
     }
     return $transport;
 }
Esempio n. 8
0
 /**
  * @param PaletteInterface $proxy
  * @param $profilePath
  * @return \Imagine\Image\Profile
  */
 protected function createAndSetProfileOnProxy(PaletteInterface $proxy, $profilePath)
 {
     if (substr($profilePath, 0, 11) !== 'resource://') {
         $profilePath = $this->packageManager->getPackage('imagine.imagine')->getPackagePath() . 'lib/Imagine/resources/' . $profilePath;
     }
     $profile = Profile::fromPath($profilePath);
     ObjectAccess::setProperty($proxy, 'profile', $profile, TRUE);
     return $profile;
 }
 /**
  * @test
  */
 public function collectionValidatorIsValidEarlyReturnsOnUnitializedDoctrinePersistenceCollections()
 {
     $entityManager = $this->getMockBuilder(\Doctrine\ORM\EntityManager::class)->disableOriginalConstructor()->getMock();
     $persistentCollection = new \Doctrine\ORM\PersistentCollection($entityManager, new \Doctrine\ORM\Mapping\ClassMetadata(''), new \Doctrine\Common\Collections\ArrayCollection());
     ObjectAccess::setProperty($persistentCollection, 'initialized', false, true);
     $this->mockValidatorResolver->expects($this->never())->method('createValidator');
     $this->validator->validate($persistentCollection);
 }
 /**
  * Iterates through the given $properties setting them on the specified $node using the appropriate TypeConverters.
  *
  * @param object $nodeLike
  * @param NodeType $nodeType
  * @param array $properties
  * @param TYPO3CRContext $context
  * @param PropertyMappingConfigurationInterface $configuration
  * @return void
  * @throws TypeConverterException
  */
 protected function setNodeProperties($nodeLike, NodeType $nodeType, array $properties, TYPO3CRContext $context, PropertyMappingConfigurationInterface $configuration = null)
 {
     $nodeTypeProperties = $nodeType->getProperties();
     unset($properties['_lastPublicationDateTime']);
     foreach ($properties as $nodePropertyName => $nodePropertyValue) {
         if (substr($nodePropertyName, 0, 2) === '__') {
             continue;
         }
         $nodePropertyType = isset($nodeTypeProperties[$nodePropertyName]['type']) ? $nodeTypeProperties[$nodePropertyName]['type'] : null;
         switch ($nodePropertyType) {
             case 'reference':
                 $nodePropertyValue = $context->getNodeByIdentifier($nodePropertyValue);
                 break;
             case 'references':
                 $nodeIdentifiers = json_decode($nodePropertyValue);
                 $nodePropertyValue = array();
                 if (is_array($nodeIdentifiers)) {
                     foreach ($nodeIdentifiers as $nodeIdentifier) {
                         $referencedNode = $context->getNodeByIdentifier($nodeIdentifier);
                         if ($referencedNode !== null) {
                             $nodePropertyValue[] = $referencedNode;
                         }
                     }
                 } elseif ($nodeIdentifiers !== null) {
                     throw new TypeConverterException(sprintf('node type "%s" expects an array of identifiers for its property "%s"', $nodeType->getName(), $nodePropertyName), 1383587419);
                 }
                 break;
             case 'DateTime':
                 if ($nodePropertyValue !== '' && ($nodePropertyValue = \DateTime::createFromFormat(\DateTime::W3C, $nodePropertyValue)) !== false) {
                     $nodePropertyValue->setTimezone(new \DateTimeZone(date_default_timezone_get()));
                 } else {
                     $nodePropertyValue = null;
                 }
                 break;
             case 'integer':
                 $nodePropertyValue = intval($nodePropertyValue);
                 break;
             case 'boolean':
                 if (is_string($nodePropertyValue)) {
                     $nodePropertyValue = $nodePropertyValue === 'true' ? true : false;
                 }
                 break;
             case 'array':
                 $nodePropertyValue = json_decode($nodePropertyValue, true);
                 break;
         }
         if (substr($nodePropertyName, 0, 1) === '_') {
             $nodePropertyName = substr($nodePropertyName, 1);
             ObjectAccess::setProperty($nodeLike, $nodePropertyName, $nodePropertyValue);
             continue;
         }
         if (!isset($nodeTypeProperties[$nodePropertyName])) {
             if ($configuration !== null && $configuration->shouldSkipUnknownProperties()) {
                 continue;
             } else {
                 throw new TypeConverterException(sprintf('Node type "%s" does not have a property "%s" according to the schema', $nodeType->getName(), $nodePropertyName), 1359552744);
             }
         }
         $innerType = $nodePropertyType;
         if ($nodePropertyType !== null) {
             try {
                 $parsedType = TypeHandling::parseType($nodePropertyType);
                 $innerType = $parsedType['elementType'] ?: $parsedType['type'];
             } catch (InvalidTypeException $exception) {
             }
         }
         if (is_string($nodePropertyValue) && $this->objectManager->isRegistered($innerType) && $nodePropertyValue !== '') {
             $nodePropertyValue = $this->propertyMapper->convert(json_decode($nodePropertyValue, true), $nodePropertyType, $configuration);
         }
         $nodeLike->setProperty($nodePropertyName, $nodePropertyValue);
     }
 }
Esempio n. 11
0
 /**
  * This serves a rather strange use case: renaming columns used in FK constraints.
  *
  * For a column that is used in a FK constraint to be renamed, the FK constraint has to be
  * dropped first, then the column can be renamed and last the FK constraint needs to be
  * added back (using the new name, of course).
  *
  * This method helps with the task of handling the FK constraints during this. Given a list
  * of tables that contain columns to be renamed and a search/replace pair for the column name,
  * it will return an array with arrays with drop and add SQL statements.
  *
  * Use them like this before and after renaming the affected fields:
  *
  * // collect foreign keys pointing to "our" tables
  * $tableNames = array(...);
  * $foreignKeyHandlingSql = $this->getForeignKeyHandlingSql($schema, $tableNames, 'old_name', 'new_name');
  *
  * // drop FK constraints
  * foreach ($foreignKeyHandlingSql['drop'] as $sql) {
  *     $this->addSql($sql);
  * }
  *
  * // rename columns now
  *
  * // add back FK constraints
  * foreach ($foreignKeyHandlingSql['add'] as $sql) {
  *     $this->addSql($sql);
  * }
  *
  * @param Schema $schema
  * @param AbstractPlatform $platform
  * @param array $tableNames
  * @param string $search
  * @param string $replace
  * @return array
  */
 public static function getForeignKeyHandlingSql(Schema $schema, AbstractPlatform $platform, $tableNames, $search, $replace)
 {
     $foreignKeyHandlingSql = ['drop' => [], 'add' => []];
     $tables = $schema->getTables();
     foreach ($tables as $table) {
         $foreignKeys = $table->getForeignKeys();
         foreach ($foreignKeys as $foreignKey) {
             if (!in_array($table->getName(), $tableNames) && !in_array($foreignKey->getForeignTableName(), $tableNames)) {
                 continue;
             }
             $localColumns = $foreignKey->getLocalColumns();
             $foreignColumns = $foreignKey->getForeignColumns();
             if (in_array($search, $foreignColumns) || in_array($search, $localColumns)) {
                 if (in_array($foreignKey->getLocalTableName(), $tableNames)) {
                     array_walk($localColumns, function (&$value) use($search, $replace) {
                         if ($value === $search) {
                             $value = $replace;
                         }
                     });
                 }
                 if (in_array($foreignKey->getForeignTableName(), $tableNames)) {
                     array_walk($foreignColumns, function (&$value) use($search, $replace) {
                         if ($value === $search) {
                             $value = $replace;
                         }
                     });
                 }
                 $identifierConstructorCallback = function ($columnName) {
                     return new Identifier($columnName);
                 };
                 $localColumns = array_map($identifierConstructorCallback, $localColumns);
                 $foreignColumns = array_map($identifierConstructorCallback, $foreignColumns);
                 $newForeignKey = clone $foreignKey;
                 ObjectAccess::setProperty($newForeignKey, '_localColumnNames', $localColumns, true);
                 ObjectAccess::setProperty($newForeignKey, '_foreignColumnNames', $foreignColumns, true);
                 $foreignKeyHandlingSql['drop'][] = $platform->getDropForeignKeySQL($foreignKey, $table);
                 $foreignKeyHandlingSql['add'][] = $platform->getCreateForeignKeySQL($newForeignKey, $table);
             }
         }
     }
     return $foreignKeyHandlingSql;
 }
 /**
  * Set the given $identity on the created $object.
  *
  * @param object $object
  * @param string|array $identity
  * @return void
  * @todo set identity properly if it is composite or custom property
  */
 protected function setIdentity($object, $identity)
 {
     ObjectAccess::setProperty($object, 'Persistence_Object_Identifier', $identity, true);
 }
Esempio n. 13
0
 /**
  * Set options on the given (AbstractArray)TypoScript object
  *
  * @param AbstractArrayTypoScriptObject $typoScriptObject
  * @param array $typoScriptConfiguration
  * @return void
  */
 protected function setPropertiesOnTypoScriptObject(AbstractArrayTypoScriptObject $typoScriptObject, array $typoScriptConfiguration)
 {
     foreach ($typoScriptConfiguration as $key => $value) {
         // skip keys which start with __, as they are purely internal.
         if ($key[0] === '_' && $key[1] === '_' && in_array($key, Parser::$reservedParseTreeKeys, true)) {
             continue;
         }
         ObjectAccess::setProperty($typoScriptObject, $key, $value);
     }
 }
 /**
  * Set a specific option of this object
  *
  * @param string $optionName
  * @param mixed $value
  * @return void
  */
 public function setOption($optionName, $value)
 {
     $this->options[$optionName] = $value;
     if (ObjectAccess::isPropertySettable($this, $optionName)) {
         ObjectAccess::setProperty($this, $optionName, $value);
     }
 }
 /**
  * @param array $elements
  * @return FlowQuery
  */
 protected function createFlowQuery(array $elements)
 {
     $flowQuery = $this->getAccessibleMock(FlowQuery::class, ['dummy'], [$elements]);
     // Set up mock persistence manager to return dummy object identifiers
     $this->mockPersistenceManager = $this->createMock(PersistenceManagerInterface::class);
     $this->mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(function ($object) {
         if (isset($object->__identity)) {
             return $object->__identity;
         }
     }));
     $mockPersistenceManager = $this->mockPersistenceManager;
     $objectManager = $this->createMock(ObjectManagerInterface::class);
     $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) use($mockPersistenceManager) {
         $instance = new $className();
         // Special case to inject the mock persistence manager into the filter operation
         if ($className === Operations\Object\FilterOperation::class) {
             ObjectAccess::setProperty($instance, 'persistenceManager', $mockPersistenceManager, true);
         }
         return $instance;
     }));
     $operationResolver = $this->getAccessibleMock(OperationResolver::class, ['dummy']);
     $operationResolver->_set('objectManager', $objectManager);
     $operationResolver->_set('finalOperationNames', ['count' => 'count', 'get' => 'get', 'is' => 'is', 'property' => 'property']);
     $operationResolver->_set('operations', ['count' => [300 => Operations\CountOperation::class], 'first' => [300 => Operations\FirstOperation::class], 'last' => [300 => Operations\LastOperation::class], 'slice' => [300 => Operations\SliceOperation::class], 'get' => [300 => Operations\GetOperation::class], 'is' => [300 => Operations\IsOperation::class], 'filter' => [300 => Operations\Object\FilterOperation::class], 'children' => [300 => Operations\Object\ChildrenOperation::class], 'property' => [300 => Operations\Object\PropertyOperation::class]]);
     $flowQuery->_set('operationResolver', $operationResolver);
     return $flowQuery;
 }
Esempio n. 16
0
 /**
  * @BeforeScenario @fixtures
  */
 public function resetContextFactory()
 {
     /** @var ContextFactoryInterface $contextFactory */
     $contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     ObjectAccess::setProperty($contextFactory, 'contextInstances', array(), true);
 }
 /**
  * After returning advice, generates the value hash for the object
  *
  * @param JoinPointInterface $joinPoint The current join point
  * @return void
  * @Flow\After("Neos\Flow\Persistence\Aspect\PersistenceMagicAspect->isNonEmbeddedValueObject && method(.*->__construct()) && filter(Neos\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver)")
  */
 public function generateValueHash(JoinPointInterface $joinPoint)
 {
     $proxy = $joinPoint->getProxy();
     $proxyClassName = get_class($proxy);
     $hashSourceParts = [];
     $classSchema = $this->reflectionService->getClassSchema($proxyClassName);
     foreach ($classSchema->getProperties() as $property => $propertySchema) {
         // Currently, private properties are transient. Should this behaviour change, they need to be included
         // in the value hash generation
         if ($classSchema->isPropertyTransient($property) || $this->reflectionService->isPropertyPrivate($proxyClassName, $property)) {
             continue;
         }
         $propertyValue = ObjectAccess::getProperty($proxy, $property, true);
         if (is_object($propertyValue) === true) {
             // The persistence manager will return NULL if the given object is unknown to persistence
             $propertyValue = $this->persistenceManager->getIdentifierByObject($propertyValue) ?: $propertyValue;
         }
         $hashSourceParts[$property] = $propertyValue;
     }
     ksort($hashSourceParts);
     $hashSourceParts['__class_name__'] = $proxyClassName;
     $serializedSource = $this->useIgBinary === true ? igbinary_serialize($hashSourceParts) : serialize($hashSourceParts);
     $proxy = $joinPoint->getProxy();
     ObjectAccess::setProperty($proxy, 'Persistence_Object_Identifier', sha1($serializedSource), true);
 }
 /**
  * @param ApplicationContext $context
  * @return void
  */
 protected function injectApplicationContextIntoConfigurationManager(ApplicationContext $context)
 {
     ObjectAccess::setProperty($this->mockConfigurationManager, 'configurations', [ConfigurationManager::CONFIGURATION_TYPE_SETTINGS => []], true);
     ObjectAccess::setProperty($this->mockConfigurationManager, 'context', $context, true);
     ObjectAccess::setProperty($this->mockConfigurationManager, 'orderedListOfContextNames', [(string) $context], true);
     ObjectAccess::setProperty($this->mockConfigurationManager, 'includeCachedConfigurationsPathAndFilename', FLOW_PATH_CONFIGURATION . (string) $context . '/IncludeCachedConfigurations.php', true);
 }
 /**
  * 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;
 }
Esempio n. 20
0
 /**
  * This is an edge-case which occurs if somebody makes the formState persistent, which can happen when subclassing the FormRuntime.
  *
  * The goal is to build a GET request *only* containing the form state, and nothing else. Furthermore, we need to make sure
  * that we do NOT send any of the parameters with the form; as we only want the form state to be applied.
  *
  * So, if the form state contains some values, we want to be sure these values are re-displayed.
  *
  * @test
  */
 public function goingForthAndBackStoresFormValuesOfSecondPageEvenWhenSecondPageIsManuallyCalledAsGetRequest()
 {
     // 1. TEST SETUP: FORM STATE PREPARATION
     // - go to the 2nd page of the form, and fill in text2-1.
     $this->browser->request('http://localhost/test/form/simpleform/ThreePageFormWithValidation');
     $this->gotoNextFormPage($this->browser->getForm());
     $form = $this->browser->getForm();
     $form['--three-page-form-with-validation']['text2-1']->setValue('My Text on the second page');
     // - then, go back and forth, in order to get an *up-to-date* form state having the right values inside.
     $this->gotoPreviousFormPage($form);
     $this->gotoNextFormPage($this->browser->getForm());
     // 2. TEST SETUP: BUILD GET REQUEST ONLY CONTAINING FORM STATE
     $form = $this->browser->getForm();
     \Neos\Utility\ObjectAccess::setProperty($form, 'method', 'GET', true);
     // we want to stay on the current page, that's why we send __currentPage = 1. (== 2nd page of the form)
     $doc = new \DOMDocument();
     $doc->loadXML('<input type="hidden" name="--three-page-form-with-validation[__currentPage]" value="1" />');
     $node = $doc->getElementsByTagName('input')->item(0);
     $form->set(new InputFormField($node));
     // We do *not* send any form content with us, as we want to test these are properly reconstituted from the form state.
     $form->offsetUnset('--three-page-form-with-validation[text2-1]');
     // 3. TEST RUN
     // submit the GET request ONLY containing formState.
     $this->browser->submit($form);
     // now, make sure the text2-1 (which has been persisted in the form state) gets reconstituted and shown properly.
     $form = $this->browser->getForm();
     $this->assertSame('My Text on the second page', $form['--three-page-form-with-validation']['text2-1']->getValue());
 }
 /**
  * @param array $commandOptions
  * @param array $adjustmentOptions
  * @param string $commandOptionPath
  * @param string $adjustmentOptionName
  * @return void
  */
 protected function transferOptionFromCommandToAdjustment(array $commandOptions, array &$adjustmentOptions, $commandOptionPath, $adjustmentOptionName)
 {
     $commandOptionValue = ObjectAccess::getPropertyPath($commandOptions, $commandOptionPath);
     if ($commandOptionValue !== null) {
         ObjectAccess::setProperty($adjustmentOptions, $adjustmentOptionName, $commandOptionValue);
     }
 }
 /**
  * @test
  */
 public function setPropertyCanDirectlySetValuesInAnArrayObjectOrArray()
 {
     $arrayObject = new \ArrayObject();
     $array = array();
     ObjectAccess::setProperty($arrayObject, 'publicProperty', 4242);
     ObjectAccess::setProperty($array, 'key', 'value');
     $this->assertEquals(4242, $arrayObject['publicProperty']);
     $this->assertEquals('value', $array['key']);
 }
 /**
  * Resets security test requirements
  *
  * @return void
  */
 protected function tearDownSecurity()
 {
     if ($this->privilegeManager !== null) {
         $this->privilegeManager->reset();
     }
     if ($this->policyService !== null) {
         $this->policyService->reset();
     }
     if ($this->testingProvider !== null) {
         $this->testingProvider->reset();
     }
     if ($this->securityContext !== null) {
         $this->securityContext->clearContext();
     }
     if ($this->authenticationManager !== null) {
         \Neos\Utility\ObjectAccess::setProperty($this->authenticationManager, 'isAuthenticated', null, true);
     }
 }
 /**
  * Make the node "similar" to the given source node. That means,
  *  - all properties
  *  - index
  *  - node type
  *  - content object
  * will be set to the same values as in the source node.
  *
  * @param AbstractNodeData $sourceNode
  * @param boolean $isCopy
  * @return void
  */
 public function similarize(AbstractNodeData $sourceNode, $isCopy = false)
 {
     $this->properties = [];
     foreach ($sourceNode->getProperties() as $propertyName => $propertyValue) {
         $this->setProperty($propertyName, $propertyValue);
     }
     $propertyNames = ['nodeType', 'hidden', 'hiddenAfterDateTime', 'hiddenBeforeDateTime', 'hiddenInIndex', 'accessRoles'];
     if (!$isCopy) {
         $propertyNames[] = 'creationDateTime';
         $propertyNames[] = 'lastModificationDateTime';
     }
     if ($sourceNode instanceof NodeData) {
         $propertyNames[] = 'index';
     }
     foreach ($propertyNames as $propertyName) {
         ObjectAccess::setProperty($this, $propertyName, ObjectAccess::getProperty($sourceNode, $propertyName));
     }
     $contentObject = $sourceNode->getContentObject();
     if ($contentObject !== null) {
         $this->setContentObject($contentObject);
     }
 }
 /**
  * An onFlush event listener used to validate entities upon persistence.
  *
  * @param \Doctrine\ORM\Event\OnFlushEventArgs $eventArgs
  * @return void
  */
 public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs)
 {
     $unitOfWork = $this->entityManager->getUnitOfWork();
     $entityInsertions = $unitOfWork->getScheduledEntityInsertions();
     $validatedInstancesContainer = new \SplObjectStorage();
     $knownValueObjects = [];
     foreach ($entityInsertions as $entity) {
         $className = TypeHandling::getTypeForValue($entity);
         if ($this->reflectionService->getClassSchema($className)->getModelType() === ClassSchema::MODELTYPE_VALUEOBJECT) {
             $identifier = $this->getIdentifierByObject($entity);
             if (isset($knownValueObjects[$className][$identifier]) || $unitOfWork->getEntityPersister($className)->exists($entity)) {
                 unset($entityInsertions[spl_object_hash($entity)]);
                 continue;
             }
             $knownValueObjects[$className][$identifier] = true;
         }
         $this->validateObject($entity, $validatedInstancesContainer);
     }
     ObjectAccess::setProperty($unitOfWork, 'entityInsertions', $entityInsertions, true);
     foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
         $this->validateObject($entity, $validatedInstancesContainer);
     }
 }
 /**
  * Imports the given content passed as a string as a new persistent resource.
  *
  * The given content typically is binary data or a text format. On a successful import this method
  * returns a PersistentResource object representing the imported content and automatically publishes it to the
  * configured publication target.
  *
  * The specified filename will be used when presenting the resource to a user. Its file extension is
  * important because the resource management will derive the IANA Media Type from it.
  *
  * @param string $content The binary content to import
  * @param string $filename The filename to use for the newly generated resource
  * @param string $collectionName Name of the collection this new resource should be added to. By default the standard collection for persistent resources is used.
  * @param string $forcedPersistenceObjectIdentifier INTERNAL: Force the object identifier for this resource to the given UUID
  * @return PersistentResource A resource object representing the imported resource
  * @throws Exception
  * @api
  */
 public function importResourceFromContent($content, $filename, $collectionName = ResourceManager::DEFAULT_PERSISTENT_COLLECTION_NAME, $forcedPersistenceObjectIdentifier = null)
 {
     if (!is_string($content)) {
         throw new Exception(sprintf('Tried to import content into the resource collection "%s" but the given content was a %s instead of a string.', $collectionName, gettype($content)), 1380878115);
     }
     $this->initialize();
     if (!isset($this->collections[$collectionName])) {
         throw new Exception(sprintf('Tried to import a file into the resource collection "%s" but no such collection exists. Please check your settings and the code which triggered the import.', $collectionName), 1380878131);
     }
     /* @var CollectionInterface $collection */
     $collection = $this->collections[$collectionName];
     try {
         $resource = $collection->importResourceFromContent($content);
         $resource->setFilename($filename);
         if ($forcedPersistenceObjectIdentifier !== null) {
             ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedPersistenceObjectIdentifier, true);
         }
     } catch (Exception $exception) {
         throw new Exception(sprintf('Importing content into the resource collection "%s" failed: %s', $collectionName, $exception->getMessage()), 1381156155, $exception);
     }
     $this->resourceRepository->add($resource);
     $this->systemLogger->log(sprintf('Successfully imported content into the resource collection "%s" (storage: %s, a %s. SHA1: %s)', $collectionName, $collection->getStorage()->getName(), get_class($collection->getStorage()), $resource->getSha1()), LOG_DEBUG);
     return $resource;
 }
 /**
  * Sets the given properties on the object.
  *
  * @param object $object The object to set properties on
  * @param string $identifier The identifier of the object
  * @param array $objectData
  * @return void
  * @throws UnknownObjectException
  */
 public function thawProperties($object, $identifier, array $objectData)
 {
     $classSchema = $this->reflectionService->getClassSchema($objectData['classname']);
     foreach ($objectData['properties'] as $propertyName => $propertyData) {
         if (!$classSchema->hasProperty($propertyName) || $classSchema->isPropertyTransient($propertyName)) {
             continue;
         }
         $propertyValue = null;
         if ($propertyData['value'] !== null) {
             switch ($propertyData['type']) {
                 case 'integer':
                     $propertyValue = (int) $propertyData['value'];
                     break;
                 case 'float':
                     $propertyValue = (double) $propertyData['value'];
                     break;
                 case 'boolean':
                     $propertyValue = (bool) $propertyData['value'];
                     break;
                 case 'string':
                     $propertyValue = (string) $propertyData['value'];
                     break;
                 case 'array':
                     $propertyValue = $this->mapArray($propertyData['value']);
                     break;
                 case 'Doctrine\\Common\\Collections\\Collection':
                 case 'Doctrine\\Common\\Collections\\ArrayCollection':
                     $propertyValue = new ArrayCollection($this->mapArray($propertyData['value']));
                     break;
                 case 'SplObjectStorage':
                     $propertyValue = $this->mapSplObjectStorage($propertyData['value'], $classSchema->isPropertyLazy($propertyName));
                     break;
                 case 'DateTime':
                     $propertyValue = $this->mapDateTime($propertyData['value']);
                     break;
                 default:
                     if ($propertyData['value'] === false) {
                         throw new UnknownObjectException('An expected object was not found by the backend. It was expected for ' . $objectData['classname'] . '::' . $propertyName, 1289509867);
                     }
                     $propertyValue = $this->mapToObject($propertyData['value']);
                     break;
             }
         } else {
             switch ($propertyData['type']) {
                 case 'NULL':
                     continue;
                 case 'array':
                     $propertyValue = $this->mapArray(null);
                     break;
                 case Collection::class:
                 case ArrayCollection::class:
                     $propertyValue = new ArrayCollection();
                     break;
                 case 'SplObjectStorage':
                     $propertyValue = $this->mapSplObjectStorage(null);
                     break;
             }
         }
         ObjectAccess::setProperty($object, $propertyName, $propertyValue, true);
     }
     if (isset($objectData['metadata'])) {
         $object->Flow_Persistence_Metadata = $objectData['metadata'];
     }
     ObjectAccess::setProperty($object, 'Persistence_Object_Identifier', $identifier, true);
 }
 /**
  * Sets legacy "option" properties to the view for backwards compatibility.
  *
  * @param ViewInterface $view
  * @param array $renderingOptions
  * @return ViewInterface
  */
 protected function applyLegacyViewOptions(ViewInterface $view, array $renderingOptions)
 {
     if (isset($renderingOptions['templatePathAndFilename'])) {
         ObjectAccess::setProperty($view, 'templatePathAndFilename', $renderingOptions['templatePathAndFilename']);
     }
     if (isset($renderingOptions['layoutRootPath'])) {
         ObjectAccess::setProperty($view, 'layoutRootPath', $renderingOptions['layoutRootPath']);
     }
     if (isset($renderingOptions['partialRootPath'])) {
         ObjectAccess::setProperty($view, 'partialRootPath', $renderingOptions['partialRootPath']);
     }
     if (isset($renderingOptions['format'])) {
         ObjectAccess::setProperty($view, 'format', $renderingOptions['format']);
     }
     return $view;
 }
 /**
  * Convert an object from $source to an object.
  *
  * @param mixed $source
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return object the target type
  * @throws InvalidTargetException
  * @throws InvalidDataTypeException
  * @throws InvalidPropertyMappingConfigurationException
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
 {
     $object = $this->buildObject($convertedChildProperties, $targetType);
     foreach ($convertedChildProperties as $propertyName => $propertyValue) {
         $result = ObjectAccess::setProperty($object, $propertyName, $propertyValue);
         if ($result === false) {
             $exceptionMessage = sprintf('Property "%s" having a value of type "%s" could not be set in target object of type "%s". Make sure that the property is accessible properly, for example via an appropriate setter method.', $propertyName, is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue), $targetType);
             throw new InvalidTargetException($exceptionMessage, 1304538165);
         }
     }
     return $object;
 }
 /**
  * Sets the specified property.
  * If the node has a content object attached, the property will be set there
  * if it is settable.
  *
  * @param string $propertyName Name of the property
  * @param mixed $value Value of the property
  * @return void
  */
 public function setProperty($propertyName, $value)
 {
     if (!is_object($this->contentObjectProxy)) {
         switch ($this->getNodeType()->getPropertyType($propertyName)) {
             case 'references':
                 $nodeIdentifiers = array();
                 if (is_array($value)) {
                     foreach ($value as $nodeIdentifier) {
                         if ($nodeIdentifier instanceof NodeInterface || $nodeIdentifier instanceof AbstractNodeData) {
                             $nodeIdentifiers[] = $nodeIdentifier->getIdentifier();
                         } elseif (preg_match(UuidValidator::PATTERN_MATCH_UUID, $nodeIdentifier) !== 0) {
                             $nodeIdentifiers[] = $nodeIdentifier;
                         }
                     }
                 }
                 $value = $nodeIdentifiers;
                 break;
             case 'reference':
                 $nodeIdentifier = null;
                 if ($value instanceof NodeInterface || $value instanceof AbstractNodeData) {
                     $nodeIdentifier = $value->getIdentifier();
                 } elseif (preg_match(UuidValidator::PATTERN_MATCH_UUID, $value) !== 0) {
                     $nodeIdentifier = $value;
                 }
                 $value = $nodeIdentifier;
                 break;
         }
         $this->persistRelatedEntities($value);
         if (isset($this->properties[$propertyName]) && $this->properties[$propertyName] === $value) {
             return;
         }
         $this->properties[$propertyName] = $value;
         $this->addOrUpdate();
     } elseif (ObjectAccess::isPropertySettable($this->contentObjectProxy->getObject(), $propertyName)) {
         $contentObject = $this->contentObjectProxy->getObject();
         ObjectAccess::setProperty($contentObject, $propertyName, $value);
         $this->updateContentObject($contentObject);
     }
 }