diff --git a/.styleci.yml b/.styleci.yml index ab650bd..3843bb1 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -17,12 +17,10 @@ enabled: - whitespace_after_comma_in_array - function_typehint_space - hash_to_slash_comment - - no_alias_functions - lowercase_cast - no_leading_namespace_whitespace - native_function_casing - no_empty_statement - - self_accessor - no_short_bool_cast - no_unneeded_control_parentheses diff --git a/Classes/ConfigurationObjectMapper.php b/Classes/ConfigurationObjectMapper.php index 4114ec7..3b42a20 100644 --- a/Classes/ConfigurationObjectMapper.php +++ b/Classes/ConfigurationObjectMapper.php @@ -91,7 +91,7 @@ public function convert($source, $targetType, PropertyMappingConfigurationInterf $this->configurationObjectConversionDTO = new ConfigurationObjectConversionDTO($this->rootTargetType, $this->serviceFactory); $this->getTypeConverterDTO = new GetTypeConverterDTO($this->rootTargetType, $this->serviceFactory); - $result = call_user_func_array(['parent', 'convert'], func_get_args()); + $result = parent::convert($source, $targetType, $configuration); unset($this->configurationObjectConversionDTO); unset($this->getTypeConverterDTO); diff --git a/Classes/Core/Core.php b/Classes/Core/Core.php index bda808a..68518dc 100644 --- a/Classes/Core/Core.php +++ b/Classes/Core/Core.php @@ -300,8 +300,6 @@ public function injectParentsUtility(ParentsUtility $parentsUtility) */ public function getCacheService() { - $this->cacheService->registerInternalCache(); - return $this->cacheService; } diff --git a/Classes/Core/Service/CacheService.php b/Classes/Core/Service/CacheService.php index fd705c6..dc51a7e 100644 --- a/Classes/Core/Service/CacheService.php +++ b/Classes/Core/Service/CacheService.php @@ -13,107 +13,21 @@ namespace Romm\ConfigurationObject\Core\Service; -use TYPO3\CMS\Core\Cache\Backend\FileBackend; use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; -use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; class CacheService implements SingletonInterface { - const CACHE_IDENTIFIER = 'cache_configuration_object'; + const CACHE_IDENTIFIER = 'configuration_object'; const CACHE_TAG_DYNAMIC_CACHE = 'dynamic-cache'; - /** - * Options for the internal cache. - * - * @var array - */ - protected $cacheOptions = [ - 'backend' => FileBackend::class, - 'frontend' => VariableFrontend::class, - 'groups' => ['all', 'system'] - ]; - /** * @var CacheManager */ protected $cacheManager; - /** - * Function called from `ext_localconf` file which will register the - * internal cache earlier. - * - * @internal - */ - public function registerInternalCache() - { - $cacheManager = $this->getCacheManager(); - - if (false === $cacheManager->hasCache(self::CACHE_IDENTIFIER)) { - $cacheManager->setCacheConfigurations([self::CACHE_IDENTIFIER => $this->cacheOptions]); - } - } - - /** - * This function will take care of initializing all caches that were defined - * previously by the `CacheService` which allows dynamic caches to be used - * for every configuration object type. - * - * @see \Romm\ConfigurationObject\Service\Items\Cache\CacheService::initialize() - * @internal - */ - public function registerDynamicCaches() - { - $dynamicCaches = $this->getCache()->getByTag(self::CACHE_TAG_DYNAMIC_CACHE); - - foreach ($dynamicCaches as $cacheData) { - $identifier = $cacheData['identifier']; - $options = $cacheData['options']; - - $this->registerCacheInternal($identifier, $options); - } - } - - /** - * Registers a new dynamic cache: the cache will be added to the cache - * manager after this function is executed. Its configuration will also be - * remembered so the cache will be registered properly during the cache - * framework initialization in further requests. - * - * @param string $identifier - * @param array $options - */ - public function registerDynamicCache($identifier, array $options) - { - if (false === $this->getCache()->has($identifier)) { - $this->getCache()->set( - $identifier, - [ - 'identifier' => $identifier, - 'options' => $options - ], - [self::CACHE_TAG_DYNAMIC_CACHE] - ); - } - - $this->registerCacheInternal($identifier, $options); - } - - /** - * @param string $identifier - * @param array $options - */ - protected function registerCacheInternal($identifier, array $options) - { - $cacheManager = $this->getCacheManager(); - - if (false === $cacheManager->hasCache($identifier)) { - $cacheManager->setCacheConfigurations([$identifier => $options]); - } - } - /** * @return FrontendInterface */ diff --git a/Classes/Legacy/Reflection/ClassSchema.php b/Classes/Legacy/Reflection/ClassSchema.php index 58e18a0..40d3c54 100644 --- a/Classes/Legacy/Reflection/ClassSchema.php +++ b/Classes/Legacy/Reflection/ClassSchema.php @@ -198,7 +198,7 @@ public function hasProperty($propertyName) } /** - * Sets the property marked as uuid of an object with @uuid + * Sets the property marked as uuid of an object with \@uuid * * @param string $propertyName * @throws \InvalidArgumentException diff --git a/Classes/Legacy/Reflection/DocCommentParser.php b/Classes/Legacy/Reflection/DocCommentParser.php index 10140ea..9010ccc 100644 --- a/Classes/Legacy/Reflection/DocCommentParser.php +++ b/Classes/Legacy/Reflection/DocCommentParser.php @@ -14,6 +14,8 @@ * The TYPO3 project - inspiring people to share! */ +use function chr; + /** * A little parser which creates tag objects from doc comments */ @@ -40,12 +42,12 @@ public function parseDocComment($docComment) { $this->description = ''; $this->tags = []; - $lines = explode(LF, $docComment); + $lines = explode(chr(10), $docComment); foreach ($lines as $line) { if ($line !== '' && strpos($line, '@') !== false) { $this->parseTag(substr($line, strpos($line, '@'))); } elseif (empty($this->tags)) { - $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . LF; + $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . chr(10); } } $this->description = trim($this->description); diff --git a/Classes/Legacy/Validation/ValidatorResolver.php b/Classes/Legacy/Validation/ValidatorResolver.php deleted file mode 100644 index 9d30cea..0000000 --- a/Classes/Legacy/Validation/ValidatorResolver.php +++ /dev/null @@ -1,543 +0,0 @@ -[a-z0-9_:.\\\\]+) - \s* - (?:\( - (?P(?:\s*[a-z0-9]+\s*=\s*(?: - "(?:\\\\"|[^"])*" - |\'(?:\\\\\'|[^\'])*\' - |(?:\s|[^,"\']*) - )(?:\s|,)*)*) - \))? - /ixS'; - - /** - * Match validator options (to parse actual options) - * @var string - */ - const PATTERN_MATCH_VALIDATOROPTIONS = '/ - \s* - (?P[a-z0-9]+) - \s*=\s* - (?P - "(?:\\\\"|[^"])*" - |\'(?:\\\\\'|[^\'])*\' - |(?:\s|[^,"\']*) - ) - /ixS'; - - /** - * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface - */ - protected $objectManager; - - /** - * @var \TYPO3\CMS\Extbase\Reflection\ReflectionService - */ - protected $reflectionService; - - /** - * @var array - */ - protected $baseValidatorConjunctions = []; - - /** - * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager - */ - public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) - { - $this->objectManager = $objectManager; - } - - /** - * @param ReflectionService $reflectionService - */ - public function injectReflectionService(ReflectionService $reflectionService) - { - $this->reflectionService = $reflectionService; - } - - /** - * Get a validator for a given data type. Returns a validator implementing - * the \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface or NULL if no validator - * could be resolved. - * - * @param string $validatorType Either one of the built-in data types or fully qualified validator class name - * @param array $validatorOptions Options to be passed to the validator - * @return \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface Validator or NULL if none found. - */ - public function createValidator($validatorType, array $validatorOptions = []) - { - try { - /** - * @todo remove throwing Exceptions in resolveValidatorObjectName - */ - $validatorObjectName = $this->resolveValidatorObjectName($validatorType); - - $validator = $this->objectManager->get($validatorObjectName, $validatorOptions); - - if (!($validator instanceof \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface)) { - throw new Exception\NoSuchValidatorException('The validator "' . $validatorObjectName . '" does not implement TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface!', 1300694875); - } - - return $validator; - } catch (NoSuchValidatorException $e) { - return null; - } - } - - /** - * Resolves and returns the base validator conjunction for the given data type. - * - * If no validator could be resolved (which usually means that no validation is necessary), - * NULL is returned. - * - * @param string $targetClassName The data type to search a validator for. Usually the fully qualified object name - * @return ConjunctionValidator The validator conjunction or NULL - */ - public function getBaseValidatorConjunction($targetClassName) - { - if (!array_key_exists($targetClassName, $this->baseValidatorConjunctions)) { - $this->buildBaseValidatorConjunction($targetClassName, $targetClassName); - } - - return $this->baseValidatorConjunctions[$targetClassName]; - } - - /** - * Detects and registers any validators for arguments: - * - by the data type specified in the param annotations - * - additional validators specified in the validate annotations of a method - * - * @param string $className - * @param string $methodName - * @param array $methodParameters Optional pre-compiled array of method parameters - * @param array $methodValidateAnnotations Optional pre-compiled array of validate annotations (as array) - * @return ConjunctionValidator[] An Array of ValidatorConjunctions for each method parameters. - * @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException - * @throws \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException - * @throws \TYPO3\CMS\Extbase\Validation\Exception\InvalidTypeHintException - */ - public function buildMethodArgumentsValidatorConjunctions($className, $methodName, array $methodParameters = null, array $methodValidateAnnotations = null) - { - /** @var ConjunctionValidator[] $validatorConjunctions */ - $validatorConjunctions = []; - - if ($methodParameters === null) { - $methodParameters = $this->reflectionService->getMethodParameters($className, $methodName); - } - if (empty($methodParameters)) { - return $validatorConjunctions; - } - - foreach ($methodParameters as $parameterName => $methodParameter) { - /** @var ConjunctionValidator $validatorConjunction */ - $validatorConjunction = $this->createValidator(ConjunctionValidator::class); - - if (!array_key_exists('type', $methodParameter)) { - throw new Exception\InvalidTypeHintException('Missing type information, probably no @param annotation for parameter "$' . $parameterName . '" in ' . $className . '->' . $methodName . '()', 1281962564); - } - - // @todo: remove check for old underscore model name syntax once it's possible - if (strpbrk($methodParameter['type'], '_\\') === false) { - $typeValidator = $this->createValidator($methodParameter['type']); - } else { - $typeValidator = null; - } - - if ($typeValidator !== null) { - $validatorConjunction->addValidator($typeValidator); - } - $validatorConjunctions[$parameterName] = $validatorConjunction; - } - - if ($methodValidateAnnotations === null) { - $validateAnnotations = $this->getMethodValidateAnnotations($className, $methodName); - $methodValidateAnnotations = array_map(function ($validateAnnotation) { - return [ - 'type' => $validateAnnotation['validatorName'], - 'options' => $validateAnnotation['validatorOptions'], - 'argumentName' => $validateAnnotation['argumentName'], - ]; - }, $validateAnnotations); - } - - foreach ($methodValidateAnnotations as $annotationParameters) { - $newValidator = $this->createValidator($annotationParameters['type'], $annotationParameters['options']); - if ($newValidator === null) { - throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Could not resolve class name for validator "' . $annotationParameters['type'] . '".', 1239853109); - } - if (isset($validatorConjunctions[$annotationParameters['argumentName']])) { - $validatorConjunctions[$annotationParameters['argumentName']]->addValidator($newValidator); - } elseif (strpos($annotationParameters['argumentName'], '.') !== false) { - $objectPath = explode('.', $annotationParameters['argumentName']); - $argumentName = array_shift($objectPath); - $validatorConjunctions[$argumentName]->addValidator($this->buildSubObjectValidator($objectPath, $newValidator)); - } else { - throw new Exception\InvalidValidationConfigurationException('Invalid validate annotation in ' . $className . '->' . $methodName . '(): Validator specified for argument name "' . $annotationParameters['argumentName'] . '", but this argument does not exist.', 1253172726); - } - } - - return $validatorConjunctions; - } - - /** - * Builds a chain of nested object validators by specification of the given - * object path. - * - * @param array $objectPath The object path - * @param \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator The validator which should be added to the property specified by objectPath - * @return \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator - */ - protected function buildSubObjectValidator(array $objectPath, \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $propertyValidator) - { - $rootObjectValidator = $this->objectManager->get(\TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator::class, []); - $parentObjectValidator = $rootObjectValidator; - - while (count($objectPath) > 1) { - $subObjectValidator = $this->objectManager->get(\TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator::class, []); - $subPropertyName = array_shift($objectPath); - $parentObjectValidator->addPropertyValidator($subPropertyName, $subObjectValidator); - $parentObjectValidator = $subObjectValidator; - } - - $parentObjectValidator->addPropertyValidator(array_shift($objectPath), $propertyValidator); - - return $rootObjectValidator; - } - - /** - * 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 - * @throws \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException - * @throws \InvalidArgumentException - */ - protected function buildBaseValidatorConjunction($indexKey, $targetClassName, array $validationGroups = []) - { - $conjunctionValidator = new ConjunctionValidator(); - $this->baseValidatorConjunctions[$indexKey] = $conjunctionValidator; - - // note: the simpleType check reduces lookups to the class loader - if (!TypeHandlingUtility::isSimpleType($targetClassName) && class_exists($targetClassName)) { - // Model based validator - /** @var \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator $objectValidator */ - $objectValidator = $this->objectManager->get(\TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator::class, []); - foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $classPropertyName) { - $classPropertyTagsValues = $this->reflectionService->getPropertyTagsValues($targetClassName, $classPropertyName); - - if (!isset($classPropertyTagsValues['var'])) { - throw new \InvalidArgumentException(sprintf('There is no @var annotation for property "%s" in class "%s".', $classPropertyName, $targetClassName), 1363778104); - } - try { - $parsedType = TypeHandlingUtility::parseType(trim(implode('', $classPropertyTagsValues['var']), ' \\')); - } catch (\TYPO3\CMS\Extbase\Utility\Exception\InvalidTypeException $exception) { - throw new \InvalidArgumentException(sprintf(' @var annotation of ' . $exception->getMessage(), 'class "' . $targetClassName . '", property "' . $classPropertyName . '"'), 1315564744, $exception); - } - $propertyTargetClassName = $parsedType['type']; - // note: the outer simpleType check reduces lookups to the class loader - if (!TypeHandlingUtility::isSimpleType($propertyTargetClassName)) { - if (TypeHandlingUtility::isCollectionType($propertyTargetClassName)) { - $collectionValidator = $this->createValidator(\TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator::class, ['elementType' => $parsedType['elementType'], 'validationGroups' => $validationGroups]); - $objectValidator->addPropertyValidator($classPropertyName, $collectionValidator); - } elseif (class_exists($propertyTargetClassName) && !TypeHandlingUtility::isCoreType($propertyTargetClassName) && $this->objectManager->isRegistered($propertyTargetClassName) && $this->objectManager->getScope($propertyTargetClassName) === \TYPO3\CMS\Extbase\Object\Container\Container::SCOPE_PROTOTYPE) { - $validatorForProperty = $this->getBaseValidatorConjunction($propertyTargetClassName); - if ($validatorForProperty !== null && $validatorForProperty->count() > 0) { - $objectValidator->addPropertyValidator($classPropertyName, $validatorForProperty); - } - } - } - - $validateAnnotations = []; - // @todo: Resolve annotations via reflectionService once its available - if (isset($classPropertyTagsValues['validate']) && is_array($classPropertyTagsValues['validate'])) { - foreach ($classPropertyTagsValues['validate'] as $validateValue) { - $parsedAnnotations = $this->parseValidatorAnnotation($validateValue); - - foreach ($parsedAnnotations['validators'] as $validator) { - array_push($validateAnnotations, [ - 'argumentName' => $parsedAnnotations['argumentName'] ?? null, - 'validatorName' => $validator['validatorName'] ?? null, - 'validatorOptions' => $validator['validatorOptions'] ?? null - ]); - } - } - } - - foreach ($validateAnnotations as $validateAnnotation) { - // @todo: Respect validationGroups - $newValidator = $this->createValidator($validateAnnotation['validatorName'], $validateAnnotation['validatorOptions']); - if ($newValidator === null) { - throw new Exception\NoSuchValidatorException('Invalid validate annotation in ' . $targetClassName . '::' . $classPropertyName . ': Could not resolve class name for validator "' . $validateAnnotation->type . '".', 1241098027); - } - $objectValidator->addPropertyValidator($classPropertyName, $newValidator); - } - } - - if (!empty($objectValidator->getPropertyValidators())) { - $conjunctionValidator->addValidator($objectValidator); - } - } - - $this->addCustomValidators($targetClassName, $conjunctionValidator); - } - - /** - * This adds custom validators to the passed $conjunctionValidator. - * - * A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and - * append 'Validator'". If found, it will be added to the $conjunctionValidator. - * - * In addition canValidate() will be called on all implementations of the ObjectValidatorInterface to find - * all validators that could validate the target. The one with the highest priority will be added as well. - * If multiple validators have the same priority, which one will be added is not deterministic. - * - * @param string $targetClassName - * @param ConjunctionValidator $conjunctionValidator - * @return Validator\ObjectValidatorInterface|null - */ - protected function addCustomValidators($targetClassName, ConjunctionValidator &$conjunctionValidator) - { - // @todo: get rid of ClassNamingUtility usage once we dropped underscored class name support - $possibleValidatorClassName = ClassNamingUtility::translateModelNameToValidatorName($targetClassName); - - $customValidator = $this->createValidator($possibleValidatorClassName); - if ($customValidator !== null) { - $conjunctionValidator->addValidator($customValidator); - } - - // @todo: find polytype validator for class - } - - /** - * Parses the validator options given in @validate annotations. - * - * @param string $validateValue - * @return array - */ - protected function parseValidatorAnnotation($validateValue) - { - $matches = []; - if ($validateValue[0] === '$') { - $parts = explode(' ', $validateValue, 2); - $validatorConfiguration = ['argumentName' => ltrim($parts[0], '$'), 'validators' => []]; - preg_match_all(self::PATTERN_MATCH_VALIDATORS, $parts[1], $matches, PREG_SET_ORDER); - } else { - $validatorConfiguration = ['validators' => []]; - preg_match_all(self::PATTERN_MATCH_VALIDATORS, $validateValue, $matches, PREG_SET_ORDER); - } - foreach ($matches as $match) { - $validatorOptions = []; - if (isset($match['validatorOptions'])) { - $validatorOptions = $this->parseValidatorOptions($match['validatorOptions']); - } - $validatorConfiguration['validators'][] = ['validatorName' => $match['validatorName'], 'validatorOptions' => $validatorOptions]; - } - return $validatorConfiguration; - } - - /** - * Parses $rawValidatorOptions not containing quoted option values. - * $rawValidatorOptions will be an empty string afterwards (pass by ref!). - * - * @param string $rawValidatorOptions - * @return array An array of optionName/optionValue pairs - */ - protected function parseValidatorOptions($rawValidatorOptions) - { - $validatorOptions = []; - $parsedValidatorOptions = []; - preg_match_all(self::PATTERN_MATCH_VALIDATOROPTIONS, $rawValidatorOptions, $validatorOptions, PREG_SET_ORDER); - foreach ($validatorOptions as $validatorOption) { - $parsedValidatorOptions[trim($validatorOption['optionName'])] = trim($validatorOption['optionValue']); - } - array_walk($parsedValidatorOptions, [$this, 'unquoteString']); - return $parsedValidatorOptions; - } - - /** - * Removes escapings from a given argument string and trims the outermost - * quotes. - * - * This method is meant as a helper for regular expression results. - * - * @param string &$quotedValue Value to unquote - */ - protected function unquoteString(&$quotedValue) - { - switch ($quotedValue[0]) { - case '"': - $quotedValue = str_replace('\\"', '"', trim($quotedValue, '"')); - break; - case '\'': - $quotedValue = str_replace('\\\'', '\'', trim($quotedValue, '\'')); - break; - } - $quotedValue = str_replace('\\\\', '\\', $quotedValue); - } - - /** - * Returns an object of an appropriate validator for the given class. If no validator is available - * FALSE is returned - * - * @param string $validatorName Either the fully qualified class name of the validator or the short name of a built-in validator - * - * @throws Exception\NoSuchValidatorException - * @return string Name of the validator object - */ - protected function resolveValidatorObjectName($validatorName) - { - if (strpos($validatorName, ':') !== false || strpbrk($validatorName, '_\\') === false) { - // Found shorthand validator, either extbase or foreign extension - // NotEmpty or Acme.MyPck.Ext:MyValidator - list($extensionName, $extensionValidatorName) = explode(':', $validatorName); - - if ($validatorName !== $extensionName && $extensionValidatorName !== '') { - // Shorthand custom - if (strpos($extensionName, '.') !== false) { - $extensionNameParts = explode('.', $extensionName); - $extensionName = array_pop($extensionNameParts); - $vendorName = implode('\\', $extensionNameParts); - $possibleClassName = $vendorName . '\\' . $extensionName . '\\Validation\\Validator\\' . $extensionValidatorName; - } else { - $possibleClassName = 'Tx_' . $extensionName . '_Validation_Validator_' . $extensionValidatorName; - } - } else { - // Shorthand built in - $possibleClassName = 'TYPO3\\CMS\\Extbase\\Validation\\Validator\\' . $this->getValidatorType($validatorName); - } - } else { - // Full qualified - // Tx_MyExt_Validation_Validator_MyValidator or \Acme\Ext\Validation\Validator\FooValidator - $possibleClassName = $validatorName; - if (!empty($possibleClassName) && $possibleClassName[0] === '\\') { - $possibleClassName = substr($possibleClassName, 1); - } - } - - if (substr($possibleClassName, - strlen('Validator')) !== 'Validator') { - $possibleClassName .= 'Validator'; - } - - if (class_exists($possibleClassName)) { - $possibleClassNameInterfaces = class_implements($possibleClassName); - if (!in_array(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface::class, $possibleClassNameInterfaces)) { - // The guessed validatorname is a valid class name, but does not implement the ValidatorInterface - throw new NoSuchValidatorException('Validator class ' . $validatorName . ' must implement \TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface', 1365776838); - } - $resolvedValidatorName = $possibleClassName; - } else { - throw new NoSuchValidatorException('Validator class ' . $validatorName . ' does not exist', 1365799920); - } - - return $resolvedValidatorName; - } - - /** - * Used to map PHP types to validator types. - * - * @param string $type Data type to unify - * @return string unified data type - */ - protected function getValidatorType($type) - { - switch ($type) { - case 'int': - $type = 'Integer'; - break; - case 'bool': - $type = 'Boolean'; - break; - case 'double': - $type = 'Float'; - break; - case 'numeric': - $type = 'Number'; - break; - case 'mixed': - $type = 'Raw'; - break; - default: - $type = ucfirst($type); - } - return $type; - } - - /** - * Temporary replacement for $this->reflectionService->getMethodAnnotations() - * - * @param string $className - * @param string $methodName - * - * @return array - */ - public function getMethodValidateAnnotations($className, $methodName) - { - $validateAnnotations = []; - $methodTagsValues = $this->reflectionService->getMethodTagsValues($className, $methodName); - if (isset($methodTagsValues['validate']) && is_array($methodTagsValues['validate'])) { - foreach ($methodTagsValues['validate'] as $validateValue) { - $parsedAnnotations = $this->parseValidatorAnnotation($validateValue); - - foreach ($parsedAnnotations['validators'] as $validator) { - array_push($validateAnnotations, [ - 'argumentName' => $parsedAnnotations['argumentName'], - 'validatorName' => $validator['validatorName'], - 'validatorOptions' => $validator['validatorOptions'] - ]); - } - } - } - - return $validateAnnotations; - } -} diff --git a/Classes/Traits/ConfigurationObject/MagicMethodsTrait.php b/Classes/Traits/ConfigurationObject/MagicMethodsTrait.php index d01e97e..dc53c6f 100644 --- a/Classes/Traits/ConfigurationObject/MagicMethodsTrait.php +++ b/Classes/Traits/ConfigurationObject/MagicMethodsTrait.php @@ -41,6 +41,11 @@ public function __call($name, $arguments) return $this->handleMagicMethods($name, $arguments); } + public function __set($property, $value) + { + $this->handlePropertyMagicMethod($property, 'set', [$value]); + } + /** * See class description. * diff --git a/Classes/TypeConverter/ArrayConverter.php b/Classes/TypeConverter/ArrayConverter.php index 5cfad97..6f91d78 100644 --- a/Classes/TypeConverter/ArrayConverter.php +++ b/Classes/TypeConverter/ArrayConverter.php @@ -34,7 +34,7 @@ class ArrayConverter extends AbstractTypeConverter /** * @var string */ - protected $targetType = '\\ArrayObject'; + protected $targetType = \ArrayObject::class; /** * @var int @@ -46,7 +46,7 @@ class ArrayConverter extends AbstractTypeConverter * * @inheritdoc */ - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) + public function convertFrom($source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) { $result = []; $array = ('array' === $targetType) @@ -71,8 +71,11 @@ public function convertFrom($source, $targetType, array $convertedChildPropertie * @see \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter::getTypeOfChildProperty() * @inheritdoc */ - public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) + public function getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration): string { + if ($targetType === 'array') { + return 'string'; + } /** * @see \Romm\ConfigurationObject\Reflection\ReflectionService */ @@ -84,6 +87,6 @@ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappi $parsedTargetType = TypeHandlingUtility::parseType($targetType); } - return $parsedTargetType['elementType']; + return $parsedTargetType['elementType'] ?? $parsedTargetType['type']; } } diff --git a/Classes/TypeConverter/ConfigurationObjectConverter.php b/Classes/TypeConverter/ConfigurationObjectConverter.php index 8d5e0aa..211e333 100644 --- a/Classes/TypeConverter/ConfigurationObjectConverter.php +++ b/Classes/TypeConverter/ConfigurationObjectConverter.php @@ -31,15 +31,24 @@ class ConfigurationObjectConverter extends ObjectConverter * * @inheritdoc */ - public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration) + public function getTypeOfChildProperty(string $targetType, string $propertyName, PropertyMappingConfigurationInterface $configuration): string { $specificTargetType = $this->objectContainer->getImplementationClassName($targetType); if (Core::get()->classExists($specificTargetType)) { - $propertyTags = $this->reflectionService->getPropertyTagValues($specificTargetType, $propertyName, 'var'); + $property = $this->reflectionService->getClassSchema($specificTargetType)->getProperty($propertyName); - if (!empty($propertyTags)) { - return current($propertyTags); + $elementType = $property->getElementType(); + $type = $property->getType(); + + if ($type === 'array' && $elementType !== null) { + return $elementType . '[]'; + } + if ($elementType !== null) { + return $elementType; + } + if ($type !== null) { + return $type; } } @@ -49,7 +58,7 @@ public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappi /** * @inheritdoc */ - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) + public function convertFrom($source, string $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null): ?object { try { return parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration); diff --git a/Classes/Validation/ValidatorResolver.php b/Classes/Validation/ValidatorResolver.php index 8bab806..d790d10 100644 --- a/Classes/Validation/ValidatorResolver.php +++ b/Classes/Validation/ValidatorResolver.php @@ -15,7 +15,6 @@ use Romm\ConfigurationObject\Core\Core; use Romm\ConfigurationObject\Core\Service\ObjectService; -use Romm\ConfigurationObject\Legacy\Reflection\ReflectionService; use Romm\ConfigurationObject\Service\Items\MixedTypes\MixedTypesInterface; use Romm\ConfigurationObject\Service\Items\MixedTypes\MixedTypesService; use Romm\ConfigurationObject\Validation\Validator\Internal\ConfigurationObjectValidator; @@ -34,7 +33,7 @@ * validator is `CollectionValidator`: in this case we use a custom one instead: * `MixedTypeCollectionValidator` which will support the mixed types feature. */ -class ValidatorResolver extends \Romm\ConfigurationObject\Legacy\Validation\ValidatorResolver +class ValidatorResolver extends \TYPO3\CMS\Extbase\Validation\ValidatorResolver { /** @@ -50,7 +49,7 @@ class ValidatorResolver extends \Romm\ConfigurationObject\Legacy\Validation\Vali /** * @var \Romm\ConfigurationObject\Reflection\ReflectionService */ - protected $reflectionService; + protected $legacyReflectionService; /** * @inheritdoc @@ -117,7 +116,7 @@ protected function buildBaseValidatorConjunction($indexKey, $targetClassName, ar */ protected function addMixedTypeValidators($targetClassName, GenericObjectValidator $validator) { - foreach ($this->reflectionService->getClassPropertyNames($targetClassName) as $property) { + foreach ($this->legacyReflectionService->getClassPropertyNames($targetClassName) as $property) { /* * If the property already is already bound to an object validator, * there is no need to do further checks. @@ -185,13 +184,13 @@ protected function propertyIsMixedType($className, $property) { $mixedType = false; - $propertySchema = $this->reflectionService->getClassSchema($className)->getProperty($property); + $propertySchema = $this->legacyReflectionService->getClassSchema($className)->getProperty($property); if ($this->classIsMixedType($propertySchema['type'])) { $mixedType = true; } else { - if ($this->reflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) { - $tags = $this->reflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE); + if ($this->legacyReflectionService->isPropertyTaggedWith($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE)) { + $tags = $this->legacyReflectionService->getPropertyTagValues($className, $property, MixedTypesService::PROPERTY_ANNOTATION_MIXED_TYPE); $mixedTypeClassName = reset($tags); if ($this->classIsMixedType($mixedTypeClassName)) { @@ -214,11 +213,11 @@ protected function classIsMixedType($className) } /** - * @param ReflectionService $reflectionService + * @param \Romm\ConfigurationObject\Reflection\ReflectionService $legacyReflectionService */ - public function injectReflectionService(ReflectionService $reflectionService) + public function injectLegacyReflectionService(\Romm\ConfigurationObject\Reflection\ReflectionService $legacyReflectionService) { - $this->reflectionService = Core::get()->getReflectionService(); + $this->legacyReflectionService = $legacyReflectionService; } /** diff --git a/Tests/Fixture/Company/Company.php b/Tests/Fixture/Company/Company.php index eb9d18d..028c97b 100644 --- a/Tests/Fixture/Company/Company.php +++ b/Tests/Fixture/Company/Company.php @@ -29,12 +29,12 @@ class Company implements ConfigurationObjectInterface /** * @var string - * @validate TYPO3.CMS.Extbase:NotEmpty + * @Validate("NotEmpty") */ protected $name; /** - * @var \ArrayObject + * @var \ArrayObject<\Romm\ConfigurationObject\Tests\Fixture\Company\Employee> */ protected $employees; diff --git a/Tests/Fixture/Company/Employee.php b/Tests/Fixture/Company/Employee.php index 6d97da7..84ce777 100644 --- a/Tests/Fixture/Company/Employee.php +++ b/Tests/Fixture/Company/Employee.php @@ -35,21 +35,21 @@ class Employee implements DataPreProcessorInterface, MixedTypesInterface /** * @var string - * @validate TYPO3.CMS.Extbase:NotEmpty - * @validate Romm\ConfigurationObject\Tests\Fixture\Validator\WrongValueValidator + * @Validate("NotEmpty") + * @Validate("Romm\ConfigurationObject\Tests\Fixture\Validator\WrongValueValidator") */ protected $name; /** * @var string - * @validate TYPO3.CMS.Extbase:NotEmpty - * @validate Romm.ConfigurationObject:HasValues(values="Male|Female") + * @Validate("NotEmpty") + * @Validate("Romm\ConfigurationObject\Validation\Validator\HasValuesValidator", options={"values": "Male|Female"}) */ protected $gender; /** * @var string - * @validate TYPO3.CMS.Extbase:EmailAddress + * @Validate("NotEmpty") */ protected $email; diff --git a/Tests/Unit/AbstractUnitTest.php b/Tests/Unit/AbstractUnitTest.php index b0291ef..912b7d8 100644 --- a/Tests/Unit/AbstractUnitTest.php +++ b/Tests/Unit/AbstractUnitTest.php @@ -1,16 +1,67 @@ setUpConfigurationObjectCore(); } + + /** + * Injects $dependency into property $name of $target + * + * This is a convenience method for setting a protected or private property in + * a test subject for the purpose of injecting a dependency. + * + * @param object $target The instance which needs the dependency + * @param string $name Name of the property to be injected + * @param mixed $dependency The dependency to inject – usually an object but can also be any other type + * @return void + * @throws \RuntimeException + * @throws \InvalidArgumentException + */ + protected function inject($target, $name, $dependency) + { + if (! is_object($target)) { + throw new \InvalidArgumentException('Wrong type for argument $target, must be object.', 1476107338); + } + + $objectReflection = new \ReflectionObject($target); + $methodNamePart = strtoupper($name[0]) . substr($name, 1); + if ($objectReflection->hasMethod('set' . $methodNamePart)) { + $methodName = 'set' . $methodNamePart; + $target->$methodName($dependency); + } elseif ($objectReflection->hasMethod('inject' . $methodNamePart)) { + $methodName = 'inject' . $methodNamePart; + $target->$methodName($dependency); + } elseif ($objectReflection->hasProperty($name)) { + $property = $objectReflection->getProperty($name); + $property->setAccessible(true); + $property->setValue($target, $dependency); + } else { + throw new \RuntimeException( + 'Could not inject ' . $name . ' into object of type ' . get_class($target), + 1476107339 + ); + } + } + + public function get($target, $name) + { + $objectReflection = new \ReflectionObject($target); + + $property = $objectReflection->getProperty($name); + $property->setAccessible(true); + + return $property->getValue(); + } } diff --git a/Tests/Unit/ConfigurationObjectFactoryTest.php b/Tests/Unit/ConfigurationObjectFactoryTest.php index 8b2559f..20ac087 100644 --- a/Tests/Unit/ConfigurationObjectFactoryTest.php +++ b/Tests/Unit/ConfigurationObjectFactoryTest.php @@ -1,6 +1,7 @@ 'bar']; - /** @var ConfigurationObjectFactory|\PHPUnit_Framework_MockObject_MockObject $factoryMock */ + /** @var ConfigurationObjectFactory|MockObject $factoryMock */ $factoryMock = $this->getMockBuilder(ConfigurationObjectFactory::class) ->setMethods(['get']) ->getMock(); @@ -235,7 +236,7 @@ public function createCompanyObjectWithMixedTypes() */ public function configurationObjectFactoryIsRunning() { - /** @var ConfigurationObjectFactory|\PHPUnit_Framework_MockObject_MockObject $factory */ + /** @var ConfigurationObjectFactory|MockObject $factory */ $factory = $this->getMockBuilder(ConfigurationObjectFactory::class) ->setMethods(['convertToObject']) ->getMock(); diff --git a/Tests/Unit/ConfigurationObjectInstanceTest.php b/Tests/Unit/ConfigurationObjectInstanceTest.php index 409c46d..2c19b51 100644 --- a/Tests/Unit/ConfigurationObjectInstanceTest.php +++ b/Tests/Unit/ConfigurationObjectInstanceTest.php @@ -11,7 +11,7 @@ class ConfigurationObjectInstanceTest extends AbstractUnitTest { - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Unit/ConfigurationObjectUnitTestUtility.php b/Tests/Unit/ConfigurationObjectUnitTestUtility.php index 7ec0a7f..486df8a 100644 --- a/Tests/Unit/ConfigurationObjectUnitTestUtility.php +++ b/Tests/Unit/ConfigurationObjectUnitTestUtility.php @@ -1,6 +1,8 @@ configurationObjectCoreMock->injectReflectionService($reflectionService); $this->configurationObjectCoreMock->method('getServiceFactoryInstance') - ->will( - $this->returnCallback( - function () { - /** @var ServiceFactory|\PHPUnit_Framework_MockObject_MockObject $serviceFactoryMock */ - $serviceFactoryMock = $this->getConfigurationObjectMockBuilder(ServiceFactory::class) - ->setMethods(['manageServiceData']) - ->getMock(); - $serviceFactoryMock->method('manageServiceData') - ->will( - $this->returnCallback( - function (array $service) { - $className = $service['className']; - $options = $service['options']; - - if (CacheService::class === $className) { - $options[CacheService::OPTION_CACHE_BACKEND] = TransientMemoryBackend::class; - } - - return [$className, $options]; - } - ) - ); + ->willReturnCallback( + function () { + /** @var ServiceFactory|MockObject $serviceFactoryMock */ + $serviceFactoryMock = $this->getConfigurationObjectMockBuilder(ServiceFactory::class) + ->setMethods(['manageServiceData']) + ->getMock(); + $serviceFactoryMock->method('manageServiceData') + ->willReturnCallback( + function (array $service) { + $className = $service['className']; + $options = $service['options']; + + if (CacheService::class === $className) { + $options[CacheService::OPTION_CACHE_BACKEND] = TransientMemoryBackend::class; + } - return $serviceFactoryMock; - } - ) + return [$className, $options]; + } + ); + + return $serviceFactoryMock; + } ); $cacheManager = new CacheManager; - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.2.0', '<')) { - $cacheFactory = new CacheFactory('foo', $cacheManager); - $cacheManager->injectCacheFactory($cacheFactory); - } - $cacheManager->setCacheConfigurations([ InternalCacheService::CACHE_IDENTIFIER => [ 'backend' => TransientMemoryBackend::class, @@ -135,7 +122,7 @@ function (array $service) { $this->configurationObjectCoreMock->injectCacheManager($cacheManager); $cacheService = new InternalCacheService; - $cacheService->registerInternalCache(); +// $cacheService->registerInternalCache(); $this->inject($cacheService, 'cacheManager', $cacheManager); $this->configurationObjectCoreMock->injectCacheService($cacheService); @@ -155,18 +142,8 @@ protected function injectMockedValidatorResolverInCore() /** @var ValidatorResolver $validatorResolver */ $validatorResolver = $this->getConfigurationObjectObjectManagerMock()->get(ValidatorResolver::class); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $reflectedProperty = new \ReflectionProperty($validatorResolver, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($validatorResolver, Core::get()->getObjectManager()); - - $reflectedProperty = new \ReflectionProperty($validatorResolver, 'reflectionService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($validatorResolver, Core::get()->getReflectionService()); - } else { - $validatorResolver->injectObjectManager(Core::get()->getObjectManager()); - $validatorResolver->injectReflectionService(Core::get()->getReflectionService()); - } + $validatorResolver->injectObjectManager(Core::get()->getObjectManager()); + $validatorResolver->injectReflectionService(Core::get()->getReflectionService()); $this->configurationObjectCoreMock->injectValidatorResolver($validatorResolver); } @@ -178,78 +155,44 @@ protected function injectMockedValidatorResolverInCore() */ protected function injectMockedConfigurationObjectFactory() { - /** @var ConfigurationObjectMapper|\PHPUnit_Framework_MockObject_MockObject $mockedConfigurationObjectMapper */ + /** @var ConfigurationObjectMapper|MockObject $mockedConfigurationObjectMapper */ $mockedConfigurationObjectMapper = $this->getConfigurationObjectMockBuilder(ConfigurationObjectMapper::class) ->setMethods(['getObjectConverter']) ->getMock(); - $objectContainer = new Container(); + $objectContainer = new Container(new FailsafeContainer()); $configurationObjectConverter = new ConfigurationObjectConverter(); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'objectContainer'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationObjectConverter, $objectContainer); - - $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationObjectConverter, Core::get()->getObjectManager()); - - $reflectionService = Core::get()->getReflectionService(); - $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'reflectionService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationObjectConverter, $reflectionService); - - $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'reflectionService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationObjectConverter, $reflectionService); - } else { - $configurationObjectConverter->injectObjectContainer($objectContainer); - $configurationObjectConverter->injectObjectManager(Core::get()->getObjectManager()); - - $reflectionService = new \Romm\ConfigurationObject\Legacy\Reflection\ReflectionService(); - $reflectionService->injectObjectManager(Core::get()->getObjectManager()); - $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'reflectionService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationObjectConverter, $reflectionService); - } + + $configurationObjectConverter->injectObjectContainer($objectContainer); + $configurationObjectConverter->injectObjectManager(Core::get()->getObjectManager()); + + $reflectionService = new \Romm\ConfigurationObject\Legacy\Reflection\ReflectionService(); + $reflectionService->injectObjectManager(Core::get()->getObjectManager()); + $reflectedProperty = new \ReflectionProperty($configurationObjectConverter, 'reflectionService'); + $reflectedProperty->setAccessible(true); + $reflectedProperty->setValue($configurationObjectConverter, $reflectionService); $mockedConfigurationObjectMapper->expects($this->any()) ->method('getObjectConverter') - ->will($this->returnValue($configurationObjectConverter)); + ->willReturn($configurationObjectConverter); $propertyMappingConfigurationBuilder = Core::get()->getObjectManager()->get(PropertyMappingConfigurationBuilder::class); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $reflectedProperty = new \ReflectionProperty($mockedConfigurationObjectMapper, 'configurationBuilder'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($mockedConfigurationObjectMapper, $propertyMappingConfigurationBuilder); - - $reflectedProperty = new \ReflectionProperty($mockedConfigurationObjectMapper, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($mockedConfigurationObjectMapper, Core::get()->getObjectManager()); - } else { - $mockedConfigurationObjectMapper->injectConfigurationBuilder($propertyMappingConfigurationBuilder); - $mockedConfigurationObjectMapper->injectObjectManager(Core::get()->getObjectManager()); - } + $mockedConfigurationObjectMapper->injectConfigurationBuilder($propertyMappingConfigurationBuilder); + $mockedConfigurationObjectMapper->injectObjectManager(Core::get()->getObjectManager()); $reflectionService = Core::get()->getReflectionService(); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $reflectedProperty = new \ReflectionProperty($reflectionService, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($reflectionService, Core::get()->getObjectManager()); - } else { - $reflectionService->injectObjectManager(Core::get()->getObjectManager()); - } + $reflectionService->injectObjectManager(Core::get()->getObjectManager()); $mockedConfigurationObjectMapper->initializeObject(); - /** @var ConfigurationObjectFactory|\PHPUnit_Framework_MockObject_MockObject $mockedConfigurationObjectFactory */ + /** @var ConfigurationObjectFactory|MockObject $mockedConfigurationObjectFactory */ $mockedConfigurationObjectFactory = $this->getConfigurationObjectMockBuilder(ConfigurationObjectFactory::class) ->setMethods(['getConfigurationObjectMapper']) ->getMock(); $mockedConfigurationObjectFactory->expects($this->any()) ->method('getConfigurationObjectMapper') - ->will($this->returnValue($mockedConfigurationObjectMapper)); + ->willReturn($mockedConfigurationObjectMapper); $reflectedClass = new \ReflectionClass(ConfigurationObjectFactory::class); $objectManagerProperty = $reflectedClass->getProperty('instance'); @@ -261,94 +204,44 @@ protected function injectMockedConfigurationObjectFactory() * Returns a mocked instance of the Extbase `ObjectManager`. Will allow the * main function `get()` to work properly during the tests. * - * @return ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @return ObjectManagerInterface|MockObject */ private function getConfigurationObjectObjectManagerMock() { - /** @var \PHPUnit_Framework_MockObject_MockObject $mockObjectManager */ + /** @var MockObject $mockObjectManager */ $mockObjectManager = $this->getConfigurationObjectMockBuilder(ObjectManagerInterface::class) ->getMock(); $mockObjectManager->expects($this->any()) ->method('get') - ->will( - $this->returnCallback( - function () { - $arguments = func_get_args(); - $className = array_shift($arguments); - - if (in_array(AbstractValidator::class, class_parents($className))) { - /** @var AbstractValidator|\PHPUnit_Framework_MockObject_MockObject $instance */ - $instance = $this->getConfigurationObjectMockBuilder($className) - ->setMethods(['translateErrorMessage']) - ->setConstructorArgs($arguments) - ->getMock(); - $instance->expects($this->any()) - ->method('translateErrorMessage') - ->will( - $this->returnCallback( - function ($key, $extension) { - return 'LLL:' . $extension . ':' . $key; - } - ) - ); - - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<') - && ( - GenericObjectValidator::class === $className - || in_array(GenericObjectValidator::class, class_parents($className)) - ) - ) { - /** @var ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject $configurationManager */ - $configurationManager = $this->getConfigurationObjectMockBuilder(ConfigurationManager::class) - ->setMethods(['isFeatureEnabled']) - ->getMock(); - $configurationManager->method('isFeatureEnabled') - ->willReturn(true); - - $reflectedProperty = new \ReflectionProperty($configurationManager, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationManager, Core::get()->getObjectManager()); - - /** @var EnvironmentService|\PHPUnit_Framework_MockObject_MockObject $environmentServiceMock */ - $environmentServiceMock = $this->getConfigurationObjectMockBuilder(EnvironmentService::class) - ->setMethods(['isEnvironmentInFrontendMode', 'isEnvironmentInBackendMode']) - ->getMock(); - $environmentServiceMock - ->method('isEnvironmentInFrontendMode') - ->willReturn(true); - $environmentServiceMock - ->method('isEnvironmentInBackendMode') - ->willReturn(false); - - $reflectedProperty = new \ReflectionProperty($configurationManager, 'environmentService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($configurationManager, $environmentServiceMock); - - $configurationManager->initializeObject(); - - /** @var GenericObjectValidator $instance */ - $instance->injectConfigurationManager($configurationManager); - } - } else { - $reflectionClass = new \ReflectionClass($className); - if (empty($arguments)) { - $instance = $reflectionClass->newInstance(); - } else { - $instance = $reflectionClass->newInstanceArgs($arguments); - } - - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - if ($className === ClassSchema::class) { - $reflectedProperty = new \ReflectionProperty($instance, 'typeHandlingService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($instance, new TypeHandlingService()); + ->willReturnCallback( + function () { + $arguments = func_get_args(); + $className = array_shift($arguments); + + if (in_array(AbstractValidator::class, class_parents($className))) { + /** @var AbstractValidator|MockObject $instance */ + $instance = $this->getConfigurationObjectMockBuilder($className) + ->setMethods(['translateErrorMessage']) + ->setConstructorArgs($arguments) + ->getMock(); + $instance->expects($this->any()) + ->method('translateErrorMessage') + ->willReturnCallback( + function ($key, $extension) { + return 'LLL:' . $extension . ':' . $key; } - } + ); + } else { + $reflectionClass = new \ReflectionClass($className); + if (empty($arguments)) { + $instance = $reflectionClass->newInstance(); + } else { + $instance = $reflectionClass->newInstanceArgs($arguments); } - - return $instance; } - ) + + return $instance; + } ); return $mockObjectManager; @@ -358,7 +251,7 @@ function ($key, $extension) { * Just a wrapper to have auto-completion. * * @param string $className - * @return \PHPUnit_Framework_MockObject_MockBuilder + * @return MockBuilder */ private function getConfigurationObjectMockBuilder($className) { diff --git a/Tests/Unit/Core/Service/CacheServiceTest.php b/Tests/Unit/Core/Service/CacheServiceTest.php deleted file mode 100644 index 5a86a4e..0000000 --- a/Tests/Unit/Core/Service/CacheServiceTest.php +++ /dev/null @@ -1,136 +0,0 @@ -getMockBuilder(CacheService::class) - ->setMethods(['getCacheManager']) - ->getMock(); - - $cacheServiceMock->method('getCacheManager') - ->willReturn($cacheManager); - - $this->assertFalse($cacheManager->hasCache(CacheService::CACHE_IDENTIFIER)); - $cacheServiceMock->registerInternalCache(); - $this->assertTrue($cacheManager->hasCache(CacheService::CACHE_IDENTIFIER)); - } - - /** - * Checks that the cache instance is registered only once, even if the - * registration method is called several times. - * - * @test - */ - public function internalCacheIsRegisteredOnlyOnce() - { - /** @var CacheService|\PHPUnit_Framework_MockObject_MockObject $cacheServiceMock */ - $cacheServiceMock = $this->getMockBuilder(CacheService::class) - ->setMethods(['getCacheManager']) - ->getMock(); - - /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */ - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - - $cacheManagerProphecy->hasCache(CacheService::CACHE_IDENTIFIER) - ->willReturn(false); - - $cacheManagerProphecy->setCacheConfigurations(Argument::type('array')) - ->shouldBeCalled() - ->will(function () use ($cacheManagerProphecy) { - $cacheManagerProphecy->hasCache(CacheService::CACHE_IDENTIFIER) - ->shouldBeCalled() - ->willReturn(false); - }); - - $cacheServiceMock->method('getCacheManager') - ->willReturn($cacheManagerProphecy->reveal()); - - $cacheServiceMock->registerInternalCache(); - $cacheServiceMock->registerInternalCache(); - $cacheServiceMock->registerInternalCache(); - } - - /** - * Checks that a cache can be registered dynamically, and only once per - * request. - * - * @test - */ - public function registerDynamicCacheWorksProperly() - { - $cacheIdentifier = 'foo'; - $cacheOptions = ['bar' => 'baz']; - - /** @var CacheService|\PHPUnit_Framework_MockObject_MockObject $cacheServiceMock */ - $cacheServiceMock = $this->getMockBuilder(CacheService::class) - ->setMethods(['getCache', 'getCacheManager']) - ->getMock(); - - /** @var VariableFrontend|ObjectProphecy $cacheProphecy */ - $cacheProphecy = $this->prophesize(VariableFrontend::class); - - $cacheProphecy->has($cacheIdentifier) - ->shouldBeCalledTimes(2) - ->will(function () use ($cacheProphecy, $cacheIdentifier, $cacheOptions) { - $cacheProphecy->set($cacheIdentifier, Argument::type('array'), [CacheService::CACHE_TAG_DYNAMIC_CACHE]) - ->shouldBeCalledTimes(1); - - $cacheProphecy->has($cacheIdentifier) - ->willReturn(true); - - return false; - }); - - $cacheProphecy->getByTag(CacheService::CACHE_TAG_DYNAMIC_CACHE) - ->shouldBeCalledTimes(1) - ->willReturn([ - 'foo' => [ - 'identifier' => 'foo', - 'options' => [] - ] - ]); - - $cacheServiceMock->method('getCache') - ->willReturn($cacheProphecy->reveal()); - - /** @var CacheManager|ObjectProphecy $cacheManagerProphecy */ - $cacheManagerProphecy = $this->prophesize(CacheManager::class); - - $cacheManagerProphecy->hasCache($cacheIdentifier) - ->shouldBeCalledTimes(3) - ->will(function () use ($cacheManagerProphecy, $cacheIdentifier) { - $cacheManagerProphecy->hasCache($cacheIdentifier) - ->willReturn(true); - - $cacheManagerProphecy->setCacheConfigurations(Argument::type('array')) - ->shouldBeCalledTimes(1); - - return false; - }); - - $cacheServiceMock->method('getCacheManager') - ->willReturn($cacheManagerProphecy->reveal()); - - $cacheServiceMock->registerDynamicCache($cacheIdentifier, $cacheOptions); - $cacheServiceMock->registerDynamicCache($cacheIdentifier, $cacheOptions); - $cacheServiceMock->registerDynamicCaches(); - } -} diff --git a/Tests/Unit/Core/Service/ReflectionServiceTest.php b/Tests/Unit/Core/Service/ReflectionServiceTest.php index 5ee0155..7cbb09e 100644 --- a/Tests/Unit/Core/Service/ReflectionServiceTest.php +++ b/Tests/Unit/Core/Service/ReflectionServiceTest.php @@ -2,6 +2,7 @@ namespace Romm\ConfigurationObject\Tests\Unit\Core\Service\Cache; +use PHPUnit\Framework\MockObject\MockObject; use Romm\ConfigurationObject\Core\Service\ReflectionService; use Romm\ConfigurationObject\Exceptions\PropertyNotAccessibleException; use Romm\ConfigurationObject\Legacy\Reflection\ClassReflection; @@ -41,7 +42,7 @@ public function accessiblePropertiesAreAccessed() */ public function accessiblePropertiesAreCalculatedOnce() { - /** @var ReflectionService|\PHPUnit_Framework_MockObject_MockObject $service */ + /** @var ReflectionService|MockObject $service */ $service = $this->getMockBuilder(ReflectionService::class) ->setMethods(['getClassReflection']) ->getMock(); diff --git a/Tests/Unit/Service/AbstractServiceTest.php b/Tests/Unit/Service/AbstractServiceTest.php index 0606df0..926a843 100644 --- a/Tests/Unit/Service/AbstractServiceTest.php +++ b/Tests/Unit/Service/AbstractServiceTest.php @@ -18,7 +18,7 @@ class AbstractServiceTest extends AbstractUnitTest */ protected $abstractService; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -138,13 +138,13 @@ public function callBackCanBeDelayed(array $delayedCallBacks, array $expectedRes $this->expectException($exceptionThrown); } - $this->abstractService->_setStatic('delayedCallbacks', []); + $this->inject($this->abstractService, 'delayedCallbacks', []); foreach ($delayedCallBacks as $callBackInfo) { /** @noinspection PhpMethodParametersCountMismatchInspection */ $this->abstractService->_call('delay', $callBackInfo[0], $callBackInfo[1]); } - $this->assertEquals($this->abstractService->_getStatic('delayedCallbacks'), $expectedResult); + $this->assertEquals($this->get($this->abstractService, 'delayedCallbacks'), $expectedResult); } /** diff --git a/Tests/Unit/Service/DataTransferObject/AbstractServiceDTOTest.php b/Tests/Unit/Service/DataTransferObject/AbstractServiceDTOTest.php index fbbfcc3..6b8cd8c 100644 --- a/Tests/Unit/Service/DataTransferObject/AbstractServiceDTOTest.php +++ b/Tests/Unit/Service/DataTransferObject/AbstractServiceDTOTest.php @@ -22,7 +22,7 @@ class AbstractServiceDTOTest extends AbstractUnitTest */ protected $serviceFactory; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Unit/Service/DataTransferObject/ConfigurationObjectConversionDTOTest.php b/Tests/Unit/Service/DataTransferObject/ConfigurationObjectConversionDTOTest.php index 0429e87..87d7427 100644 --- a/Tests/Unit/Service/DataTransferObject/ConfigurationObjectConversionDTOTest.php +++ b/Tests/Unit/Service/DataTransferObject/ConfigurationObjectConversionDTOTest.php @@ -13,7 +13,7 @@ class ConfigurationObjectConversionDTOTest extends AbstractUnitTest */ protected $configurationObjectConversionDataTransferObject; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Unit/Service/DataTransferObject/GetConfigurationObjectDTOTest.php b/Tests/Unit/Service/DataTransferObject/GetConfigurationObjectDTOTest.php index 2286a7e..7848177 100644 --- a/Tests/Unit/Service/DataTransferObject/GetConfigurationObjectDTOTest.php +++ b/Tests/Unit/Service/DataTransferObject/GetConfigurationObjectDTOTest.php @@ -15,7 +15,7 @@ class GetConfigurationObjectDTOTest extends AbstractUnitTest */ protected $getConfigurationObjectDTO; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Unit/Service/DataTransferObject/GetTypeConverterDTOTest.php b/Tests/Unit/Service/DataTransferObject/GetTypeConverterDTOTest.php index c4131e8..bc8756b 100644 --- a/Tests/Unit/Service/DataTransferObject/GetTypeConverterDTOTest.php +++ b/Tests/Unit/Service/DataTransferObject/GetTypeConverterDTOTest.php @@ -14,7 +14,7 @@ class GetTypeConverterDTOTest extends AbstractUnitTest */ protected $getTypeConverterDataTransferObject; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Unit/Service/Items/Cache/CacheServiceTest.php b/Tests/Unit/Service/Items/Cache/CacheServiceTest.php index e1fa33d..29bfa06 100644 --- a/Tests/Unit/Service/Items/Cache/CacheServiceTest.php +++ b/Tests/Unit/Service/Items/Cache/CacheServiceTest.php @@ -1,6 +1,7 @@ getMockBuilder(InternalCacheService::class) ->setMethods(['getCacheManager']) ->getMock(); @@ -36,7 +37,7 @@ protected function setUp() */ public function initializationIsSet() { - /** @var CacheService|AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject $mockedCacheService */ + /** @var CacheService|AccessibleObjectInterface|MockObject $mockedCacheService */ $mockedCacheService = $this->getAccessibleMock(CacheService::class, ['dummy']); $cacheManager = $mockedCacheService->getCacheManager(); @@ -74,7 +75,7 @@ public function objectExistingInCacheIsFetchedCorrectly() $configurationObjectInstance = new ConfigurationObjectInstance($dummyObject, $result); // Mocking the cache service so we can inject a custom mocked cache instance. - /** @var CacheService|AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject $mockedCacheService */ + /** @var CacheService|AccessibleObjectInterface|MockObject $mockedCacheService */ $mockedCacheService = $this->getAccessibleMock(CacheService::class, ['getCacheInstance']); $options = [ @@ -134,7 +135,7 @@ public function objectIsStoredInCache() $getConfigurationObjectDTO->setResult($configurationObjectInstance); // Mocking the cache service so we can inject a custom mocked cache instance. - /** @var CacheService|AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject $mockedCacheService */ + /** @var CacheService|AccessibleObjectInterface|MockObject $mockedCacheService */ $mockedCacheService = $this->getAccessibleMock(CacheService::class, ['getCacheInstance']); $options = [ @@ -205,7 +206,7 @@ public function validationResultIsStoredInCache() $getConfigurationObjectDTO->setResult($configurationObjectInstance); // Mocking the cache service so we can inject a custom mocked cache instance. - /** @var CacheService|AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject $mockedCacheService */ + /** @var CacheService|AccessibleObjectInterface|MockObject $mockedCacheService */ $mockedCacheService = $this->getAccessibleMock(CacheService::class, ['getCacheInstance']); $options = [ diff --git a/Tests/Unit/Service/Items/ConfigurationArray/StoreConfigurationArrayServiceTest.php b/Tests/Unit/Service/Items/ConfigurationArray/StoreConfigurationArrayServiceTest.php index c3a703b..6dd93b1 100644 --- a/Tests/Unit/Service/Items/ConfigurationArray/StoreConfigurationArrayServiceTest.php +++ b/Tests/Unit/Service/Items/ConfigurationArray/StoreConfigurationArrayServiceTest.php @@ -1,6 +1,7 @@ setResult($object); - /** @var StoreConfigurationArrayService|\PHPUnit_Framework_MockObject_MockObject $storeConfigurationArrayService */ + /** @var StoreConfigurationArrayService|MockObject $storeConfigurationArrayService */ $storeConfigurationArrayService = $this->getMockBuilder(StoreConfigurationArrayService::class) ->setMethods(['storeConfigurationArray']) ->getMock(); diff --git a/Tests/Unit/Service/Items/Parents/ParentsTraitTest.php b/Tests/Unit/Service/Items/Parents/ParentsTraitTest.php index 776bc71..2e87443 100644 --- a/Tests/Unit/Service/Items/Parents/ParentsTraitTest.php +++ b/Tests/Unit/Service/Items/Parents/ParentsTraitTest.php @@ -1,6 +1,7 @@ getMockBuilder(DummyConfigurationObjectWithParentsTrait::class) ->setMethods(['attachParent']) ->getMock(); diff --git a/Tests/Unit/Service/Items/Parents/ParentsUtilityTest.php b/Tests/Unit/Service/Items/Parents/ParentsUtilityTest.php index 9baf4e8..0f5bdd1 100644 --- a/Tests/Unit/Service/Items/Parents/ParentsUtilityTest.php +++ b/Tests/Unit/Service/Items/Parents/ParentsUtilityTest.php @@ -1,6 +1,7 @@ getMockBuilder(ParentsUtility::class) ->setMethods(['checkClassUsesParentsTrait']) ->getMock(); diff --git a/Tests/Unit/TypeConverter/ConfigurationObjectConverterTest.php b/Tests/Unit/TypeConverter/ConfigurationObjectConverterTest.php index 0157e67..d5b48e3 100644 --- a/Tests/Unit/TypeConverter/ConfigurationObjectConverterTest.php +++ b/Tests/Unit/TypeConverter/ConfigurationObjectConverterTest.php @@ -5,6 +5,7 @@ use Romm\ConfigurationObject\Tests\Fixture\Model\DummyConfigurationObjectWithConstructorArguments; use Romm\ConfigurationObject\Tests\Unit\AbstractUnitTest; use Romm\ConfigurationObject\TypeConverter\ConfigurationObjectConverter; +use TYPO3\CMS\Core\DependencyInjection\FailsafeContainer; use TYPO3\CMS\Extbase\Error\Error; use TYPO3\CMS\Extbase\Object\Container\Container; use TYPO3\CMS\Extbase\Reflection\ReflectionService; @@ -20,7 +21,7 @@ class ConfigurationObjectConverterTest extends AbstractUnitTest public function missingConstructorRequiredArgumentReturnsError() { $configurationObjectConverter = new ConfigurationObjectConverter; - $this->inject($configurationObjectConverter, 'objectContainer', new Container); + $this->inject($configurationObjectConverter, 'objectContainer', new Container(new FailsafeContainer())); $this->inject($configurationObjectConverter, 'reflectionService', new ReflectionService); $this->inject($configurationObjectConverter, 'objectManager', Core::get()->getObjectManager()); diff --git a/Tests/Unit/Validation/Validator/AbstractValidatorTest.php b/Tests/Unit/Validation/Validator/AbstractValidatorTest.php index 8a44e5f..3ff822b 100644 --- a/Tests/Unit/Validation/Validator/AbstractValidatorTest.php +++ b/Tests/Unit/Validation/Validator/AbstractValidatorTest.php @@ -1,6 +1,7 @@ getMockBuilder($className) ->setMethods($methods) ->setConstructorArgs([$arguments]) diff --git a/Tests/Unit/Validation/Validator/IconExistsValidatorTest.php b/Tests/Unit/Validation/Validator/IconExistsValidatorTest.php index db6522f..57b9381 100644 --- a/Tests/Unit/Validation/Validator/IconExistsValidatorTest.php +++ b/Tests/Unit/Validation/Validator/IconExistsValidatorTest.php @@ -1,10 +1,9 @@ getMockedValidatorInstance(IconExistsValidator::class, [], ['translateErrorMessage', 'getIconRegistry']); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $this->expectException(UnsupportedVersionException::class); - $mockedIconExistsValidator->validate($correctIcon); - } else { - $iconRegistry = $this->prophesize(IconRegistry::class); + $iconRegistry = $this->prophesize(IconRegistry::class); - $iconRegistry->isRegistered($correctIcon) - ->shouldBeCalled() - ->willReturn(true); + $iconRegistry->isRegistered($correctIcon) + ->shouldBeCalled() + ->willReturn(true); - $iconRegistry->isRegistered($incorrectIcon) - ->shouldBeCalled() - ->willReturn(false); + $iconRegistry->isRegistered($incorrectIcon) + ->shouldBeCalled() + ->willReturn(false); - $mockedIconExistsValidator->method('getIconRegistry') - ->willReturn($iconRegistry->reveal()); + $mockedIconExistsValidator->method('getIconRegistry') + ->willReturn($iconRegistry->reveal()); - $test = $mockedIconExistsValidator->validate($correctIcon); - $this->assertFalse($test->hasErrors()); + $test = $mockedIconExistsValidator->validate($correctIcon); + $this->assertFalse($test->hasErrors()); - $test = $mockedIconExistsValidator->validate($incorrectIcon); - $this->assertTrue($test->hasErrors()); - } + $test = $mockedIconExistsValidator->validate($incorrectIcon); + $this->assertTrue($test->hasErrors()); } } diff --git a/Tests/Unit/Validation/ValidatorResolverTest.php b/Tests/Unit/Validation/ValidatorResolverTest.php index 556182d..cf4c51f 100644 --- a/Tests/Unit/Validation/ValidatorResolverTest.php +++ b/Tests/Unit/Validation/ValidatorResolverTest.php @@ -4,7 +4,6 @@ use Romm\ConfigurationObject\Core\Core; use Romm\ConfigurationObject\Tests\Unit\AbstractUnitTest; use Romm\ConfigurationObject\Validation\Validator\Internal\MixedTypeCollectionValidator; -use TYPO3\CMS\Core\Utility\VersionNumberUtility; use TYPO3\CMS\Extbase\Reflection\ReflectionService; use TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator; use TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator; @@ -12,7 +11,7 @@ class ValidatorResolverTest extends AbstractUnitTest { - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -32,18 +31,8 @@ public function createValidatorChecksCollectionType() $validatorResolver = Core::get()->getValidatorResolver(); $extbaseValidatorResolver = new ExtbaseValidatorResolver(); - if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '7.6.0', '<')) { - $reflectedProperty = new \ReflectionProperty($extbaseValidatorResolver, 'objectManager'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($extbaseValidatorResolver, Core::get()->getObjectManager()); - - $reflectedProperty = new \ReflectionProperty($extbaseValidatorResolver, 'reflectionService'); - $reflectedProperty->setAccessible(true); - $reflectedProperty->setValue($extbaseValidatorResolver, Core::get()->getReflectionService()); - } else { - $extbaseValidatorResolver->injectObjectManager(Core::get()->getObjectManager()); - $extbaseValidatorResolver->injectReflectionService(new ReflectionService()); - } + $extbaseValidatorResolver->injectObjectManager(Core::get()->getObjectManager()); + $extbaseValidatorResolver->injectReflectionService(new ReflectionService()); $validator = $validatorResolver->createValidator(CollectionValidator::class); diff --git a/composer.json b/composer.json index be3c5db..05b4013 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,15 @@ } ], "require": { - "php": "^7.1", - "typo3/cms-core": "^9.5", - "typo3/cms-beuser": "^9.5" + "php": "^7.4", + "typo3/cms-core": "^10.4", + "typo3/cms-beuser": "^10.4" }, "require-dev": { "mikey179/vfsStream": "^1.6", "satooshi/php-coveralls": "^1.0", - "typo3/testing-framework": "^4.0" + "typo3/testing-framework": "^6.8", + "phpspec/prophecy-phpunit": "^2.0" }, "autoload": { "psr-4": { @@ -51,8 +52,8 @@ }, "extra": { "typo3/cms": { - "cms-package-dir": "{$vendor-dir}/typo3/cms", - "web-dir": ".Build/Web" + "web-dir": ".Build/Web", + "extension-key": "configuration_object" } } } diff --git a/ext_emconf.php b/ext_emconf.php index c4ce8ee..4570ea6 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -3,7 +3,7 @@ $EM_CONF[$_EXTKEY] = [ 'title' => 'Configuration Object', 'description' => 'Transform any configuration plain array into a dynamic and configurable object structure, and pull apart configuration handling from the main logic of your script. Use provided services to add more functionality to your objects: cache, parents, persistence and much more.', - 'version' => '2.0.0', + 'version' => '3.0.0', 'state' => 'stable', 'category' => 'backend', @@ -12,12 +12,12 @@ 'constraints' => [ 'depends' => [ - 'typo3' => '9.5.0-9.5.99', - 'php' => '7.2.0-7.99.99' + 'typo3' => '10.4.0-10.4.99', + 'php' => '7.4.0-7.99.99' ], 'conflicts' => [], 'suggests' => [] ], - 'clearCacheOnLoad' => 1 + 'clearCacheOnLoad' => true ]; diff --git a/ext_localconf.php b/ext_localconf.php index 1ca5c4f..46c0c81 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -10,9 +10,19 @@ function () { \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('disableMagicMethods'); } - /** @var \Romm\ConfigurationObject\Core\Service\CacheService $cacheService */ - $cacheService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Romm\ConfigurationObject\Core\Service\CacheService::class); - $cacheService->registerInternalCache(); - $cacheService->registerDynamicCaches(); + if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_configuration_object'])) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_configuration_object'] = [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\FileBackend::class, + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + 'groups' => ['all', 'system'] + ]; + } + if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_configuration_object_default'])) { + $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['cache_configuration_object_default'] = [ + 'backend' => \TYPO3\CMS\Core\Cache\Backend\FileBackend::class, + 'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, + 'groups' => ['all', 'system'] + ]; + } } );