2 namespace TYPO3\CMS\Extbase\Utility;
23 const PARSE_TYPE_PATTERN =
'/^\\\\?(?P<type>integer|int|float|double|boolean|bool|string|DateTime|Tx_[a-zA-Z0-9_]+|[A-Z][a-zA-Z0-9\\\\_]+|object|resource|array|ArrayObject|SplObjectStorage|TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\ObjectStorage)(?:<\\\\?(?P<elementType>[a-zA-Z0-9\\\\_]+)>)?/';
33 protected static $collectionTypes = array(
'array',
'ArrayObject',
'SplObjectStorage', \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class);
46 if (preg_match(self::PARSE_TYPE_PATTERN, $type, $matches)) {
47 $type = self::normalizeType($matches[
'type']);
48 $elementType = isset($matches[
'elementType']) ? self::normalizeType($matches[
'elementType']) : null;
50 if ($elementType !== null && !self::isCollectionType($type)) {
51 throw new \TYPO3\CMS\Extbase\Utility\Exception\InvalidTypeException(
'Found an invalid element type declaration in %s. Type "' . $type .
'" must not have an element type hint (' . $elementType .
').', 1264093642);
56 'elementType' => $elementType
59 throw new \TYPO3\CMS\Extbase\Utility\Exception\InvalidTypeException(
'Found an invalid element type declaration in %s. A type "' . var_export($type,
true) .
'" does not exist.', 1264093630);
96 return preg_match(self::LITERAL_TYPE_PATTERN, $type) === 1;
107 return in_array(self::normalizeType($type), array(
'array',
'string',
'float',
'integer',
'boolean'),
true);
118 return is_subclass_of($type, \TYPO3\CMS\Core\Type\TypeInterface::class);
129 if (in_array($type, self::$collectionTypes,
true)) {
133 if (class_exists($type) ===
true || interface_exists($type) ===
true) {
134 foreach (self::$collectionTypes as $collectionType) {
135 if (is_subclass_of($type, $collectionType) ===
true) {
152 return is_array($value) || $value instanceof \Traversable;
161 public static function hex2bin($hexadecimalData)
164 $length = strlen($hexadecimalData);
165 for ($i = 0; $i < $length; $i += 2) {
166 $binaryData .= pack(
'C', hexdec(substr($hexadecimalData, $i, 2)));