/** * Updates the username and password credentials from the POST vars, if the POST parameters * are available. Sets the authentication status to REAUTHENTICATION_NEEDED, if credentials have been sent. * * @param \TYPO3\FLOW3\Mvc\ActionRequest $actionRequest The current action request instance * @return void */ public function updateCredentials(\TYPO3\FLOW3\Mvc\ActionRequest $actionRequest) { $getArguments = $actionRequest->getArguments(); if (!empty($getArguments['user']) && !empty($getArguments['signature']) && !empty($getArguments['expires']) && !empty($getArguments['version']) && !empty($getArguments['tpa_id']) && !empty($getArguments['action']) && !empty($getArguments['flags']) && !empty($getArguments['userdata'])) { $this->credentials['username'] = $getArguments['user']; $this->credentials['signature'] = \TYPO3\FLOW3\Utility\TypeHandling::hex2bin($getArguments['signature']); $this->credentials['expires'] = $getArguments['expires']; $this->credentials['version'] = $getArguments['version']; $this->credentials['tpaId'] = $getArguments['tpa_id']; $this->credentials['action'] = $getArguments['action']; $this->credentials['flags'] = $getArguments['flags']; $this->credentials['userdata'] = $getArguments['userdata']; $this->setAuthenticationStatus(self::AUTHENTICATION_NEEDED); } }
/** * Checks if the given value is valid according to the validator, and returns * the Error Messages object which occurred. * * @param mixed $value The value that should be validated * @return \TYPO3\FLOW3\Error\Result * @api */ public function validate($value) { $this->result = new \TYPO3\FLOW3\Error\Result(); if ($this->acceptsEmptyValues === FALSE || $this->isEmpty($value) === FALSE) { if ($value instanceof \Doctrine\ORM\PersistentCollection && !$value->isInitialized()) { return $this->result; } elseif (is_object($value) && !\TYPO3\FLOW3\Utility\TypeHandling::isCollectionType(get_class($value)) && !is_array($value)) { $this->addError('The given subject was not a collection.', 1317204797); return $this->result; } elseif (is_object($value) && $this->isValidatedAlready($value)) { return $this->result; } else { $this->isValid($value); } } return $this->result; }
/** * Sets the data type of this argument that is also used for property mapping. * @param string $dataType * @return \TYPO3\FLOW3\Mvc\Controller\Argument $this */ public function setDataType($dataType) { $this->dataType = \TYPO3\FLOW3\Utility\TypeHandling::normalizeType($dataType); return $this; }
/** * Convert a value to the internal object data format * * @param string $identifier The object's identifier * @param object $object The object with the property to flatten * @param string $propertyName The name of the property * @param array $propertyMetaData The property metadata * @param array $propertyData Reference to the property data array * @return void * @api */ protected function flattenValue($identifier, $object, $propertyName, array $propertyMetaData, array &$propertyData) { $propertyValue = \TYPO3\FLOW3\Reflection\ObjectAccess::getProperty($object, $propertyName, TRUE); if ($propertyValue instanceof \TYPO3\FLOW3\Persistence\Aspect\PersistenceMagicInterface) { $propertyData[$propertyName] = array('type' => get_class($propertyValue), 'multivalue' => FALSE, 'value' => $this->processObject($propertyValue, $identifier)); } else { switch ($propertyMetaData['type']) { case 'DateTime': $propertyData[$propertyName] = array('multivalue' => FALSE, 'value' => $this->processDateTime($propertyValue)); break; case 'Doctrine\\Common\\Collections\\Collection': case 'Doctrine\\Common\\Collections\\ArrayCollection': $propertyValue = $propertyValue === NULL ? array() : $propertyValue->toArray(); case 'array': $propertyData[$propertyName] = array('multivalue' => TRUE, 'value' => $this->processArray($propertyValue, $identifier, $this->persistenceSession->getCleanStateOfProperty($object, $propertyName))); break; case 'SplObjectStorage': $propertyData[$propertyName] = array('multivalue' => TRUE, 'value' => $this->processSplObjectStorage($propertyValue, $identifier, $this->persistenceSession->getCleanStateOfProperty($object, $propertyName))); break; default: if ($propertyValue === NULL && !\TYPO3\FLOW3\Utility\TypeHandling::isSimpleType($propertyMetaData['type'])) { $this->removeDeletedReference($object, $propertyName, $propertyMetaData); } $propertyData[$propertyName] = array('multivalue' => FALSE, 'value' => $propertyValue); break; } $propertyData[$propertyName]['type'] = $propertyMetaData['type']; } }
/** * Builds a base validator conjunction for the given data type. * * The base validation rules are those which were declared directly in a class (typically * a model) through some validate annotations on properties. * * If a property holds a class for which a base validator exists, that property will be * checked as well, regardless of a validate annotation * * Additionally, if a custom validator was defined for the class in question, it will be added * to the end of the conjunction. A custom validator is found if it follows the naming convention * "Replace '\Model\' by '\Validator\' and append 'Validator'". * * Example: $targetClassName is TYPO3\Foo\Domain\Model\Quux, then the validator will be found if it has the * name TYPO3\Foo\Domain\Validator\QuuxValidator * * @param string $indexKey The key to use as index in $this->baseValidatorConjunctions; calculated from target class name and validation groups * @param string $targetClassName The data type to build the validation conjunction for. Needs to be the fully qualified class name. * @param array $validationGroups The validation groups to build the validator for * @return void * @throws Exception\NoSuchValidatorException * @throws \InvalidArgumentException */ protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups) { $conjunctionValidator = new ConjunctionValidator(); $this->baseValidatorConjunctions[$indexKey] = $conjunctionValidator; if (class_exists($targetClassName)) { // Model based validator $objectValidator = new GenericObjectValidator(array()); foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $classPropertyName) { $classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($targetClassName, $classPropertyName); try { $parsedType = \TYPO3\FLOW3\Utility\TypeHandling::parseType(trim(implode('', $classPropertyTagsValues['var']), ' \\')); } catch (\TYPO3\FLOW3\Utility\Exception\InvalidTypeException $exception) { throw new \InvalidArgumentException(sprintf(' @var annotation of ' . $exception->getMessage(), 'class "' . $targetClassName . '", property "' . $classPropertyName . '"'), 1315564744); } $propertyTargetClassName = $parsedType['type']; if (\TYPO3\FLOW3\Utility\TypeHandling::isCollectionType($propertyTargetClassName) === TRUE) { $collectionValidator = $this->createValidator('TYPO3\\FLOW3\\Validation\\Validator\\CollectionValidator', array('elementType' => $parsedType['elementType'], 'validationGroups' => $validationGroups)); $objectValidator->addPropertyValidator($classPropertyName, $collectionValidator); } elseif (class_exists($propertyTargetClassName) && $this->objectManager->isRegistered($propertyTargetClassName) && $this->objectManager->getScope($propertyTargetClassName) === \TYPO3\FLOW3\Object\Configuration\Configuration::SCOPE_PROTOTYPE) { $validatorForProperty = $this->getBaseValidatorConjunction($propertyTargetClassName, $validationGroups); if (count($validatorForProperty) > 0) { $objectValidator->addPropertyValidator($classPropertyName, $validatorForProperty); } } $validateAnnotations = $this->reflectionService->getPropertyAnnotations($targetClassName, $classPropertyName, 'TYPO3\\FLOW3\\Annotations\\Validate'); foreach ($validateAnnotations as $validateAnnotation) { if (count(array_intersect($validateAnnotation->validationGroups, $validationGroups)) === 0) { // In this case, the validation groups for the property do not match current validation context continue; } $newValidator = $this->createValidator($validateAnnotation->type, $validateAnnotation->options); if ($newValidator === NULL) { throw new \TYPO3\FLOW3\Validation\Exception\NoSuchValidatorException('Invalid validate annotation in ' . $targetClassName . '::' . $classPropertyName . ': Could not resolve class name for validator "' . $validateAnnotation->type . '".', 1241098027); } $objectValidator->addPropertyValidator($classPropertyName, $newValidator); } } if (count($objectValidator->getPropertyValidators()) > 0) { $conjunctionValidator->addValidator($objectValidator); } // Custom validator for the class $possibleValidatorClassName = str_replace('\\Model\\', '\\Validator\\', $targetClassName) . 'Validator'; $customValidator = $this->createValidator($possibleValidatorClassName); if ($customValidator !== NULL) { $conjunctionValidator->addValidator($customValidator); } } }
/** * @test * @dataProvider literalTypes */ public function isLiteralReturnsTrueForLiteralType($type) { $this->assertTrue(\TYPO3\FLOW3\Utility\TypeHandling::isLiteral($type)); }
/** * Determine the type converter to be used. If no converter has been found, an exception is raised. * * @param mixed $source * @param string $targetType * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration * @return \TYPO3\FLOW3\Property\TypeConverterInterface Type Converter which should be used to convert between $source and $targetType. * @throws \TYPO3\FLOW3\Property\Exception\TypeConverterException * @throws \TYPO3\FLOW3\Property\Exception\InvalidTargetException */ protected function findTypeConverter($source, $targetType, \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration) { if ($configuration->getTypeConverter() !== NULL) { return $configuration->getTypeConverter(); } $sourceType = $this->determineSourceType($source); if (!is_string($targetType)) { throw new \TYPO3\FLOW3\Property\Exception\InvalidTargetException('The target type was no string, but of type "' . gettype($targetType) . '"', 1297941727); } if (strpos($targetType, '<') !== FALSE) { $targetType = substr($targetType, 0, strpos($targetType, '<')); } $converter = NULL; if (\TYPO3\FLOW3\Utility\TypeHandling::isSimpleType($targetType)) { if (isset($this->typeConverters[$sourceType][$targetType])) { $converter = $this->findEligibleConverterWithHighestPriority($this->typeConverters[$sourceType][$targetType], $source, $targetType); } } else { $converter = $this->findFirstEligibleTypeConverterInObjectHierarchy($source, $sourceType, $targetType); } if ($converter === NULL) { throw new \TYPO3\FLOW3\Property\Exception\TypeConverterException('No converter found which can be used to convert from "' . $sourceType . '" to "' . $targetType . '".'); } return $converter; }
/** * Adds properties of the class at hand to the class schema. * * Only non-transient properties annotated with a var annotation will be added. * Invalid annotations will cause an exception to be thrown. Properties pointing * to existing classes will only be added if the target type is annotated as * entity or valueobject. * * @param \TYPO3\FLOW3\Reflection\ClassSchema $classSchema * @return void * @throws \InvalidArgumentException * @throws \TYPO3\FLOW3\Reflection\Exception\InvalidPropertyTypeException */ protected function addPropertiesToClassSchema(\TYPO3\FLOW3\Reflection\ClassSchema $classSchema) { // those are added as property even if not tagged with entity/valueobject $propertyTypeWhiteList = array('DateTime', 'SplObjectStorage', 'Doctrine\\Common\\Collections\\Collection', 'Doctrine\\Common\\Collections\\ArrayCollection'); $className = $classSchema->getClassName(); $needsArtificialIdentity = TRUE; foreach ($this->getClassPropertyNames($className) as $propertyName) { if ($this->isPropertyTaggedWith($className, $propertyName, 'var') && !$this->isPropertyAnnotatedWith($className, $propertyName, 'TYPO3\\FLOW3\\Annotations\\Transient')) { $declaredType = trim(implode(' ', $this->getPropertyTagValues($className, $propertyName, 'var')), ' \\'); if (preg_match('/\\s/', $declaredType) === 1) { throw new \TYPO3\FLOW3\Reflection\Exception\InvalidPropertyTypeException('The @var annotation for "' . $className . '::$' . $propertyName . '" seems to be invalid.', 1284132314); } if ($this->isPropertyAnnotatedWith($className, $propertyName, 'Doctrine\\ORM\\Mapping\\Id')) { $needsArtificialIdentity = FALSE; } try { $parsedType = \TYPO3\FLOW3\Utility\TypeHandling::parseType($declaredType); } catch (\TYPO3\FLOW3\Utility\Exception\InvalidTypeException $exception) { throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $className . '" for property "' . $propertyName . '"'), 1315564475); } if (!in_array($parsedType['type'], $propertyTypeWhiteList) && (class_exists($parsedType['type']) || interface_exists($parsedType['type'])) && !($this->isClassAnnotatedWith($parsedType['type'], 'TYPO3\\FLOW3\\Annotations\\Entity') || $this->isClassAnnotatedWith($parsedType['type'], 'Doctrine\\ORM\\Mapping\\Entity') || $this->isClassAnnotatedWith($parsedType['type'], 'TYPO3\\FLOW3\\Annotations\\ValueObject'))) { continue; } $classSchema->addProperty($propertyName, $declaredType, $this->isPropertyAnnotatedWith($className, $propertyName, 'TYPO3\\FLOW3\\Annotations\\Lazy')); if ($this->isPropertyAnnotatedWith($className, $propertyName, 'TYPO3\\FLOW3\\Annotations\\Identity')) { $classSchema->markAsIdentityProperty($propertyName); } } } if ($needsArtificialIdentity === TRUE) { $classSchema->addProperty('FLOW3_Persistence_Identifier', 'string'); } }
/** * Returns a greater than or equal criterion used for matching objects against a query * * @param string $propertyName The name of the property to compare against * @param mixed $operand The value to compare with * @return \TYPO3\FLOW3\Persistence\Generic\Qom\Comparison * @throws \TYPO3\FLOW3\Persistence\Exception\InvalidQueryException if used on a multi-valued property or with a non-literal/non-DateTime operand * @api */ public function greaterThanOrEqual($propertyName, $operand) { if ($this->classSchema->isMultiValuedProperty($propertyName)) { throw new \TYPO3\FLOW3\Persistence\Exception\InvalidQueryException('Property "' . $propertyName . '" must not be multi-valued', 1276774883); } if (!$operand instanceof \DateTime && !\TYPO3\FLOW3\Utility\TypeHandling::isLiteral(gettype($operand))) { throw new \TYPO3\FLOW3\Persistence\Exception\InvalidQueryException('Operand must be a literal or DateTime, was ' . gettype($operand), 1276774884); } return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, '_entity'), \TYPO3\FLOW3\Persistence\QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); }
/** * Adds (defines) a specific property and its type. * * @param string $name Name of the property * @param string $type Type of the property * @param boolean $lazy Whether the property should be lazy-loaded when reconstituting * @return void * @throws \InvalidArgumentException */ public function addProperty($name, $type, $lazy = FALSE) { try { $type = \TYPO3\FLOW3\Utility\TypeHandling::parseType($type); } catch (\TYPO3\FLOW3\Utility\Exception\InvalidTypeException $exception) { throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $name . '"'), 1315564474); } $this->properties[$name] = array('type' => $type['type'], 'elementType' => $type['elementType'], 'lazy' => $lazy); }
/** * Return the type of a given sub-property inside the $targetType * * @param string $targetType * @param string $propertyName * @param \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration * @return string * @api */ public function getTypeOfChildProperty($targetType, $propertyName, \TYPO3\FLOW3\Property\PropertyMappingConfigurationInterface $configuration) { $parsedTargetType = \TYPO3\FLOW3\Utility\TypeHandling::parseType($targetType); return $parsedTargetType['elementType']; }