コード例 #1
0
 /**
  */
 public function setUp()
 {
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder('TYPO3\\Flow\\Package\\PackageManager')->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), TRUE);
     $this->packageFactory = new PackageFactory($this->mockPackageManager);
 }
コード例 #2
0
 /**
  *
  */
 public function setUp()
 {
     $this->queueManager = new QueueManager();
     $this->queueManager->injectSettings(array('queues' => array('TestQueue' => array('className' => 'TYPO3\\Jobqueue\\Common\\Tests\\Unit\\Fixtures\\TestQueue'))));
     $this->jobManager = new JobManager();
     ObjectAccess::setProperty($this->jobManager, 'queueManager', $this->queueManager, true);
 }
コード例 #3
0
 /**
  */
 public function setUp()
 {
     ComposerUtility::flushCaches();
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder(\TYPO3\Flow\Package\PackageManager::class)->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), true);
 }
コード例 #4
0
 /**
  * @param string $type
  * @param array $bookableRequests
  * @return Registration\AbstractBookable[]
  */
 protected function requestBookable($type, $bookableRequests)
 {
     /** @var \T3DD\Backend\Domain\Repository\Registration\AbstractBookableRepository $repository */
     $repository = $this->{strtolower($type) . 'Repository'};
     $fractionBase = (int) isset($this->configuration[$type]['fractionBase']) ? $this->configuration[$type]['fractionBase'] : static::DEFAULT_FRACTION_BASE;
     $availableQuota = (int) isset($this->configuration[$type]['availableQuota']) ? $this->configuration[$type]['availableQuota'] * $fractionBase : 0;
     $spentQuota = $repository->getSpentQuota();
     $requestedBookables = [];
     foreach ($bookableRequests as $bookableRequest) {
         $requestFraction = round($fractionBase / $bookableRequest['divisor']);
         $quotaApplies = (bool) isset($bookableRequest['quotaApplies']) ? $bookableRequest['quotaApplies'] : TRUE;
         $className = 'T3DD\\Backend\\Domain\\Model\\Registration\\' . $type;
         $requestedBookable = new $className();
         $requestedBookable->setFraction($requestFraction);
         $requestedBookable->setQuotaApplies($quotaApplies);
         \TYPO3\Flow\Reflection\ObjectAccess::setProperty($bookableRequest['participant'], $type, $requestedBookable);
         if (!$quotaApplies) {
             $requestedBookable->setBookingState(Registration\AbstractBookable::BOOKING_STATE_PENDING);
         } else {
             $spentQuota += $requestFraction;
             if ($spentQuota > $availableQuota) {
                 $requestedBookable->setBookingState(Registration\AbstractBookable::BOOKING_STATE_WAITING);
             } else {
                 $requestedBookable->setBookingState(Registration\AbstractBookable::BOOKING_STATE_PENDING);
             }
         }
         $requestedBookables[] = $requestedBookable;
         $repository->add($requestedBookable);
     }
     return $requestedBookables;
 }
コード例 #5
0
ファイル: EntityFactory.php プロジェクト: econic/testing
 /**
  * Mocks an entity as wished
  * 
  * @param  string  $fqcn             the fully qualified class name
  * @param  boolean $persist          if the entity should be directly persisted or not
  * @param  array   $customProperties the properties to set if wished
  * @return Object
  */
 public function create($fqcn, $persist = false, $customProperties = array())
 {
     $entityConfiguration = $this->entityConfiguration[$fqcn];
     $this->validateEntityConfiguration($fqcn, $entityConfiguration);
     // create from reflection class if constructor needs arguments
     if (!empty($entityConfiguration['constructorArguments'])) {
         $reflector = new \ReflectionClass($fqcn);
         $constructorArguments = $this->getValuesFromConfigurations($entityConfiguration['constructorArguments']);
         $entity = $reflector->newInstanceArgs($constructorArguments);
     } else {
         $entity = new $fqcn();
     }
     // set the properties
     $configuredProperties = $entityConfiguration['properties'] ?: array();
     $properties = array_merge($configuredProperties, $customProperties);
     foreach ($this->getValuesFromConfigurations($properties, $persist) as $propertyName => $propertyValue) {
         $propertyCouldBeSet = ObjectAccess::setProperty($entity, $propertyName, $propertyValue);
         if (!$propertyCouldBeSet) {
             throw new \Exception($fqcn . '::$' . $propertyName . ' could not be set to ' . print_r($propertyValue, true), 1416481470);
         }
     }
     // persist if wished
     if ($persist && is_string($entityConfiguration['repository'])) {
         $this->objectManager->get($entityConfiguration['repository'])->add($entity);
         // flush this entity here...
         $this->entityManager->flush($entity);
         // add to managed entities
         $identifier = $this->persistenceManager->getIdentifierByObject($entity);
         $this->managedEntities[$identifier] = $entity;
     }
     return $entity;
 }
コード例 #6
0
 /**
  * @param JoinPointInterface $joinPoint
  * @return mixed Result of the target method
  * @Flow\Around("class(TYPO3\Flow\Cli\Request) && method(.*->getCommand())")
  */
 public function replaceCommandWithDomainCommand(JoinPointInterface $joinPoint)
 {
     /** @var Request $proxy */
     $proxy = $joinPoint->getProxy();
     if ($proxy->getControllerObjectName() === DomainCommandController::class) {
         ObjectAccess::setProperty($proxy, 'command', $this->buildDomainCommand($proxy->getControllerCommandName()), TRUE);
     }
     return $joinPoint->getAdviceChain()->proceed($joinPoint);
 }
 /**
  * @test
  */
 public function collectionValidatorIsValidEarlyReturnsOnUnitializedDoctrinePersistenceCollections()
 {
     $entityManager = $this->getMock(\Doctrine\ORM\EntityManager::class, array(), array(), '', false);
     $collection = new \Doctrine\Common\Collections\ArrayCollection(array());
     $persistentCollection = new \Doctrine\ORM\PersistentCollection($entityManager, '', $collection);
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($persistentCollection, 'initialized', false, true);
     $this->mockValidatorResolver->expects($this->never())->method('createValidator');
     $this->validator->validate($persistentCollection);
 }
コード例 #8
0
 /**
  * @param array $row
  * @return object
  */
 public function hydrate(array $row)
 {
     $dto = $this->getNewDtoInstance();
     foreach ($row as $column => $value) {
         if (ObjectAccess::isPropertySettable($dto, $column)) {
             ObjectAccess::setProperty($dto, $column, $value);
         }
     }
     return $dto;
 }
コード例 #9
0
 /**
  * Builds a transformation object from the given configuration.
  *
  * @param array $transformationConfiguration
  * @return \TYPO3\TYPO3CR\Migration\Transformations\TransformationInterface
  * @throws \TYPO3\TYPO3CR\Migration\Exception\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 (!\TYPO3\Flow\Reflection\ObjectAccess::setProperty($transformation, $settingName, $settingValue)) {
             throw new \TYPO3\TYPO3CR\Migration\Exception\MigrationException('Cannot set setting "' . $settingName . '" on transformation "' . $transformationClassName . '" , check your configuration.', 1343293094);
         }
     }
     return $transformation;
 }
コード例 #10
0
 /**
  * @Given /^I have the following policies:$/
  */
 public function iHaveTheFollowingPolicies($string)
 {
     self::$testingPolicyPathAndFilename = $this->environment->getPathToTemporaryDirectory() . 'Policy.yaml';
     file_put_contents(self::$testingPolicyPathAndFilename, $string->getRaw());
     $configurationManager = $this->objectManager->get('TYPO3\\Flow\\Configuration\\ConfigurationManager');
     $configurations = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($configurationManager, 'configurations', TRUE);
     unset($configurations[\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_POLICY]);
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($configurationManager, 'configurations', $configurations, TRUE);
     $policyService = $this->objectManager->get('TYPO3\\Flow\\Security\\Policy\\PolicyService');
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($policyService, 'initialized', FALSE, TRUE);
 }
コード例 #11
0
 /**
  * @test
  */
 public function ignoredClassesCanBeOverwrittenBySettings()
 {
     $object = new ApplicationContext('Development');
     $this->assertEquals('TYPO3\\Flow\\Core\\ApplicationContext prototype object', Debugger::renderDump($object, 10, TRUE));
     Debugger::clearState();
     $currentConfiguration = ObjectAccess::getProperty($this->configurationManager, 'configurations', TRUE);
     $configurationOverwrite['Settings']['TYPO3']['Flow']['error']['debugger']['ignoredClasses']['TYPO3\\\\Flow\\\\Core\\\\.*'] = FALSE;
     $newConfiguration = Arrays::arrayMergeRecursiveOverrule($currentConfiguration, $configurationOverwrite);
     ObjectAccess::setProperty($this->configurationManager, 'configurations', $newConfiguration, TRUE);
     $this->assertContains('rootContextString', Debugger::renderDump($object, 10, TRUE));
 }
コード例 #12
0
 public function setUp()
 {
     $this->factory = new \Ag\Login\Domain\Factory\AccountFactory();
     $loginFactory = m::mock('\\TYPO3\\Flow\\Security\\AccountFactory');
     $loginFactory->shouldReceive('createAccountWithPassword')->andReturnUsing(function ($email, $password) {
         $login = new \TYPO3\Flow\Security\Account();
         $login->setAccountIdentifier($email);
         return $login;
     });
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($this->factory, 'accountFactory', $loginFactory, TRUE);
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($this->factory, 'emailAddressValidator', new \TYPO3\Flow\Validation\Validator\EmailAddressValidator(), TRUE);
 }
コード例 #13
0
 /**
  * @param JobConfigurationInterface $jobConfiguration
  * @param string $persistenceIdentifier the persistence identifier for the form.
  * @param string $factoryClass The fully qualified class name of the factory (which has to implement \TYPO3\Form\Factory\FormFactoryInterface)
  * @param string $presetName name of the preset to use
  * @param array $overrideConfiguration factory specific configuration
  * @return string the rendered form
  */
 public function render(JobConfigurationInterface $jobConfiguration, $persistenceIdentifier = null, $factoryClass = 'TYPO3\\Form\\Factory\\ArrayFormFactory', $presetName = 'default', array $overrideConfiguration = [])
 {
     if (isset($persistenceIdentifier)) {
         $overrideConfiguration = Arrays::arrayMergeRecursiveOverrule($this->formPersistenceManager->load($persistenceIdentifier), $overrideConfiguration);
     }
     $factory = $this->objectManager->get($factoryClass);
     /** @var FormDefinition $formDefinition */
     $formDefinition = $factory->build($overrideConfiguration, $presetName);
     ObjectAccess::setProperty($formDefinition, 'identifier', 'options', true);
     $this->postProcessFormDefinition($jobConfiguration, $formDefinition);
     $response = new Response($this->controllerContext->getResponse());
     $form = $formDefinition->bind($this->controllerContext->getRequest(), $response);
     $form->getRequest()->setArgumentNamespace('--options');
     return $form->render();
 }
コード例 #14
0
 /**
  * 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(\TYPO3\Flow\Configuration\ConfigurationManager::class);
     $configurations = \TYPO3\Flow\Reflection\ObjectAccess::getProperty($configurationManager, 'configurations', true);
     unset($configurations[\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_POLICY]);
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($configurationManager, 'configurations', $configurations, true);
     $policyService = $this->objectManager->get(\TYPO3\Flow\Security\Policy\PolicyService::class);
     \TYPO3\Flow\Reflection\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 = 'TYPO3.TypoScript: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);
 }
コード例 #16
0
 /**
  * @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);
 }
コード例 #17
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 \TYPO3\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;
 }
コード例 #18
0
 /**
  * @param array $serializedMessage
  * @return Message
  */
 public function unserialize($serializedMessage)
 {
     if (is_array($serializedMessage) === FALSE) {
         throw new \InvalidArgumentException('The ArraySerializer can only unserialize arrays.', 1427369045);
     }
     if (array_key_exists('messageType', $serializedMessage) === FALSE || array_key_exists('payload', $serializedMessage) === FALSE || is_array($serializedMessage['payload']) === FALSE) {
         throw new \InvalidArgumentException('The serialized message is corrupted.', 1427369459);
     }
     $messageType = str_replace('.', '\\', $serializedMessage['messageType']);
     if (class_exists($messageType) === FALSE) {
         throw new \InvalidArgumentException('Unserialization for message of type "' . $messageType . '" failed. No such class.', 1427369534);
     }
     $message = new $messageType();
     foreach ($serializedMessage['payload'] as $propertyName => $propertyValue) {
         if (ObjectAccess::isPropertySettable($message, $propertyName)) {
             ObjectAccess::setProperty($message, $propertyName, $propertyValue);
         }
     }
     return $message;
 }
コード例 #19
0
 /**
  *
  * @param string $objectName
  * @param array $overrideProperties
  * @param boolean $addObjectToPersistence
  * @return object
  */
 public function buildObject($objectName, $overrideProperties = array(), $addObjectToPersistence = FALSE)
 {
     if (!isset($this->fixtureDefinitions[$objectName])) {
         throw new \Exception('Object name ' . $objectName . ' not configured in fixture definitions');
     }
     $properties = \TYPO3\Flow\Utility\Arrays::arrayMergeRecursiveOverrule($this->fixtureDefinitions[$objectName], $overrideProperties);
     $className = isset($properties['__type']) ? $properties['__type'] : $this->baseType;
     unset($properties['__type']);
     $object = new $className();
     foreach ($properties as $propertyName => $propertyValue) {
         if (\TYPO3\Flow\Reflection\ObjectAccess::isPropertySettable($object, $propertyName)) {
             \TYPO3\Flow\Reflection\ObjectAccess::setProperty($object, $propertyName, $propertyValue);
         }
     }
     $this->setCustomProperties($object, $properties, $addObjectToPersistence);
     if ($addObjectToPersistence) {
         $this->addObjectToPersistence($object);
     }
     return $object;
 }
コード例 #20
0
 /**
  * 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 = array();
     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);
     }
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($unitOfWork, 'entityInsertions', $entityInsertions, true);
     foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
         $this->validateObject($entity, $validatedInstancesContainer);
     }
 }
コード例 #21
0
 /**
  * @test
  * @dataProvider attributeExamples
  */
 public function evaluateTests($properties, $expectedOutput, $expectedOutputAsArray)
 {
     //		print_r(func_get_args());
     $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 = 'TYPO3.TypoScript: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->assertInstanceOf('M12\\Foundation\\TypoScriptObjects\\AttributesImplementation', $result);
     $this->assertTrue(is_string($result->getAsString()));
     $this->assertTrue(is_array($result->getAsArray()));
     $this->assertEquals($expectedOutput, $result);
     $this->assertEquals($expectedOutput, $result->getAsString());
     $this->assertEquals($expectedOutputAsArray, $result->getAsArray());
 }
コード例 #22
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 \Doctrine\DBAL\Schema\Schema $schema
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @param array $tableNames
  * @param string $search
  * @param string $replace
  * @return array
  */
 public static function getForeignKeyHandlingSql(\Doctrine\DBAL\Schema\Schema $schema, \Doctrine\DBAL\Platforms\AbstractPlatform $platform, $tableNames, $search, $replace)
 {
     $foreignKeyHandlingSql = array('drop' => array(), 'add' => array());
     $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;
                 \TYPO3\Flow\Reflection\ObjectAccess::setProperty($newForeignKey, '_localColumnNames', $localColumns, true);
                 \TYPO3\Flow\Reflection\ObjectAccess::setProperty($newForeignKey, '_foreignColumnNames', $foreignColumns, true);
                 $foreignKeyHandlingSql['drop'][] = $platform->getDropForeignKeySQL($foreignKey, $table);
                 $foreignKeyHandlingSql['add'][] = $platform->getCreateForeignKeySQL($newForeignKey, $table);
             }
         }
     }
     return $foreignKeyHandlingSql;
 }
コード例 #23
0
 /**
  * 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);
 }
コード例 #24
0
 /**
  * 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 \TYPO3\TYPO3CR\Domain\Model\AbstractNodeData $sourceNode
  * @param boolean $isCopy
  * @return void
  */
 public function similarize(AbstractNodeData $sourceNode, $isCopy = false)
 {
     $this->properties = array();
     foreach ($sourceNode->getProperties() as $propertyName => $propertyValue) {
         $this->setProperty($propertyName, $propertyValue);
     }
     $propertyNames = array('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);
     }
 }
コード例 #25
0
 /**
  * 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;
         }
         if (isset($this->properties[$propertyName]) && $this->properties[$propertyName] === $value) {
             return;
         }
         $this->properties[$propertyName] = $value;
         $this->update();
     } elseif (ObjectAccess::isPropertySettable($this->contentObjectProxy->getObject(), $propertyName)) {
         $contentObject = $this->contentObjectProxy->getObject();
         ObjectAccess::setProperty($contentObject, $propertyName, $value);
         $this->updateContentObject($contentObject);
     }
 }
コード例 #26
0
 /**
  * Converts the given $objectXml to an ImageVariant instance and returns it
  *
  * @param \SimpleXMLElement $objectXml
  * @param string $className the concrete class name of the ImageVariant to create (ImageVariant or a subclass)
  * @return ImageVariant
  * @throws NeosException
  */
 protected function importImageVariant(\SimpleXMLElement $objectXml, $className)
 {
     $processingInstructions = unserialize(trim((string) $objectXml->processingInstructions));
     if (isset($objectXml->originalImage['__identifier'])) {
         $image = $this->imageRepository->findByIdentifier((string) $objectXml->originalImage['__identifier']);
         if (is_object($image)) {
             return $this->objectManager->get($className, $image, $processingInstructions);
         }
     }
     $resourceHash = (string) $objectXml->originalImage->resource->hash;
     $resourceData = trim((string) $objectXml->originalImage->resource->content);
     if ((string) $objectXml->originalImage->resource['__identifier'] !== '') {
         $resource = $this->persistenceManager->getObjectByIdentifier((string) $objectXml->originalImage->resource['__identifier'], 'TYPO3\\Flow\\Resource\\Resource');
     }
     if (!isset($resource) || $resource === null) {
         $resource = $this->importResource((string) $objectXml->originalImage->resource->filename, $resourceHash !== '' ? $resourceHash : null, !empty($resourceData) ? $resourceData : null, (string) $objectXml->originalImage->resource['__identifier'] !== '' ? (string) $objectXml->originalImage->resource['__identifier'] : null);
     }
     $image = new Image($resource);
     if ((string) $objectXml->originalImage['__identifier'] !== '') {
         ObjectAccess::setProperty($image, 'Persistence_Object_Identifier', (string) $objectXml->originalImage['__identifier'], true);
     }
     $this->imageRepository->add($image);
     return $this->objectManager->get($className, $image, $processingInstructions);
 }
 /**
  * After returning advice, generates the value hash for the object
  *
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return void
  * @Flow\After("classAnnotatedWith(TYPO3\Flow\Annotations\ValueObject) && method(.*->__construct()) && filter(TYPO3\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver)")
  */
 public function generateValueHash(JoinPointInterface $joinPoint)
 {
     $proxy = $joinPoint->getProxy();
     $proxyClassName = get_class($proxy);
     $hashSourceParts = array();
     $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);
 }
コード例 #28
0
 /**
  * Creates, adds and returns a child node of this node. Also sets default
  * properties and creates default subnodes.
  *
  * @param string $name Name of the new node
  * @param NodeType $nodeType Node type of the new node (optional)
  * @param string $identifier The identifier of the node, unique within the workspace, optional(!)
  * @return NodeInterface
  * @api
  */
 public function createNode($name, NodeType $nodeType = null, $identifier = null)
 {
     $this->emitBeforeNodeCreate($this, $name, $nodeType, $identifier);
     $newNode = $this->createSingleNode($name, $nodeType, $identifier);
     if ($nodeType !== null) {
         foreach ($nodeType->getDefaultValuesForProperties() as $propertyName => $propertyValue) {
             if (substr($propertyName, 0, 1) === '_') {
                 ObjectAccess::setProperty($newNode, substr($propertyName, 1), $propertyValue);
             } else {
                 $newNode->setProperty($propertyName, $propertyValue);
             }
         }
         foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeType) {
             $childNodeIdentifier = $this->buildAutoCreatedChildNodeIdentifier($childNodeName, $newNode->getIdentifier());
             $alreadyPresentChildNode = $newNode->getNode($childNodeName);
             if ($alreadyPresentChildNode === null) {
                 $newNode->createNode($childNodeName, $childNodeType, $childNodeIdentifier);
             }
         }
     }
     $this->context->getFirstLevelNodeCache()->flush();
     $this->emitNodeAdded($newNode);
     $this->emitAfterNodeCreate($newNode);
     return $newNode;
 }
コード例 #29
0
 /**
  * @test
  */
 public function validatePasswordWillUseStrategyIdentifierFromHashedPassword()
 {
     $settings = array('security' => array('cryptography' => array('hashingStrategies' => array('TestStrategy' => 'TYPO3\\Flow\\Test\\TestStrategy'))));
     $this->hashService->injectSettings($settings);
     $mockStrategy = $this->getMock('TYPO3\\Flow\\Security\\Cryptography\\PasswordHashingStrategyInterface');
     $mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface');
     $mockObjectManager->expects($this->any())->method('get')->will($this->returnValue($mockStrategy));
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($this->hashService, 'objectManager', $mockObjectManager, TRUE);
     $mockStrategy->expects($this->atLeastOnce())->method('validatePassword')->with('myTestPassword', '---hashed-password---')->will($this->returnValue(TRUE));
     $result = $this->hashService->validatePassword('myTestPassword', 'TestStrategy=>---hashed-password---');
     $this->assertEquals(TRUE, $result);
 }
コード例 #30
0
 /**
  * @BeforeScenario @fixtures
  */
 public function resetContextFactory()
 {
     /** @var \TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface $contextFactory */
     $contextFactory = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface::class);
     \TYPO3\Flow\Reflection\ObjectAccess::setProperty($contextFactory, 'contextInstances', array(), true);
 }