• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FluidTYPO3 / flux / 27753814608

18 Jun 2026 10:39AM UTC coverage: 89.162% (-3.5%) from 92.646%
27753814608

Pull #2288

github

web-flow
Merge 37edf9f2e into 2614049c6
Pull Request #2288: [FEATURE] Prepare for v14 support

210 of 348 new or added lines in 56 files covered. (60.34%)

121 existing lines in 9 files now uncovered.

6228 of 6985 relevant lines covered (89.16%)

40.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.76
/Classes/Form/Transformation/Transformer/ObjectTransformer.php
1
<?php
2
namespace FluidTYPO3\Flux\Form\Transformation\Transformer;
3

4
/*
5
 * This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Flux\Attribute\DataTransformer;
12
use FluidTYPO3\Flux\Form\FormInterface;
13
use FluidTYPO3\Flux\Form\Transformation\DataTransformerInterface;
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
16
use TYPO3\CMS\Extbase\Persistence\RepositoryInterface;
17

18
/**
19
 * Object Transformer
20
 */
21
#[DataTransformer('flux.datatransformer.object')]
22
class ObjectTransformer implements DataTransformerInterface
23
{
24
    public function canTransformToType(string $type): bool
25
    {
26
        return $this->isDomainModelClassName($type) || class_exists($type) || (
28✔
27
            class_exists($this->resolveContainerClassName($type)) &&
28✔
28
            class_exists($this->resolveContainedClassName($type))
28✔
29
        );
28✔
30
    }
31

32
    public function getPriority(): int
33
    {
34
        return 0;
28✔
35
    }
36

37
    /**
38
     * @param string|class-string $value
39
     * @return DomainObjectInterface|DomainObjectInterface[]|iterable|object|null
40
     */
41
    public function transform(FormInterface $component, string $type, $value)
42
    {
43
        return $this->getObjectOfType($type, $value);
8✔
44
    }
45

46
    /**
47
     * Gets DomainObject(s) or instance of $dataType identified by, or constructed with parameter $uids
48
     *
49
     * @param string|class-string $dataType
50
     * @param string|array|int $uids
51
     * @return DomainObjectInterface|DomainObjectInterface[]|object|null
52
     */
53
    protected function getObjectOfType(string $dataType, $uids)
54
    {
55
        $dataType = ltrim($dataType, '\\');
8✔
56
        $identifiers = is_array($uids) ? $uids : GeneralUtility::trimExplode(',', trim((string) $uids, ','), true);
8✔
57
        /** @var int[] $identifiers */
58
        $identifiers = array_map('intval', $identifiers);
8✔
59
        $isModel = $this->isDomainModelClassName($dataType);
8✔
60
        if (false !== strpos($dataType, '<')) {
8✔
UNCOV
61
            $container = $this->resolveContainerClassName($dataType);
×
UNCOV
62
            $object = $this->resolveContainedClassName($dataType);
×
63
        } else {
64
            $container = null;
8✔
65
            $object = $dataType;
8✔
66
        }
67
        $repositoryClassName = $this->resolveRepositoryClassName($object);
8✔
68
        // Fast decisions
69
        if ($isModel && null === $container) {
8✔
UNCOV
70
            if (class_exists($repositoryClassName)) {
×
71
                /** @var RepositoryInterface $repository */
UNCOV
72
                $repository = GeneralUtility::makeInstance($repositoryClassName);
×
UNCOV
73
                $repositoryObjects = $this->loadObjectsFromRepository($repository, $identifiers);
×
74
                /** @var DomainObjectInterface|false $firstRepositoryObject */
UNCOV
75
                $firstRepositoryObject = reset($repositoryObjects);
×
UNCOV
76
                return $firstRepositoryObject ?: null;
×
77
            }
78
        } elseif (class_exists($dataType)) {
8✔
79
            // using constructor value to support objects like DateTime
80
            return GeneralUtility::makeInstance($dataType, $uids);
8✔
81
        }
82
        // slower decisions with support for type-hinted collection objects
UNCOV
83
        if ($container && $object) {
×
UNCOV
84
            if ($isModel && class_exists($repositoryClassName) && count($identifiers) > 0) {
×
85
                /** @var RepositoryInterface $repository */
UNCOV
86
                $repository = GeneralUtility::makeInstance($repositoryClassName);
×
UNCOV
87
                return $this->loadObjectsFromRepository($repository, $identifiers);
×
88
            } else {
89
                $objects = [];
×
90
                foreach ($identifiers as $identifier) {
×
91
                    $objects[] = $this->getObjectOfType($object, $identifier);
×
92
                }
93
                $container = GeneralUtility::makeInstance($container, $objects);
×
94
                return $container;
×
95
            }
96
        }
97
        return null;
×
98
    }
99

100
    /**
101
     * @return class-string
102
     */
103
    protected function resolveContainerClassName(string $compoundType): string
104
    {
105
        /** @var class-string $class */
106
        $class = explode('<', trim($compoundType, '>'))[0] ?? 'invalid';
16✔
107
        return $class;
16✔
108
    }
109

110
    /**
111
     * @return class-string
112
     */
113
    protected function resolveContainedClassName(string $compoundType): string
114
    {
115
        /** @var class-string $class */
116
        $class = ltrim(explode('<', trim($compoundType, '>'))[1] ?? 'invalid', '\\');
8✔
117
        return $class;
8✔
118
    }
119

120
    protected function resolveRepositoryClassName(string $object): string
121
    {
122
        return str_replace('\\Domain\\Model\\', '\\Domain\\Repository\\', $object) . 'Repository';
8✔
123
    }
124

125
    protected function isDomainModelClassName(string $dataType): bool
126
    {
127
        return (false !== strpos($dataType, '\\Domain\\Model\\'));
32✔
128
    }
129

130
    /**
131
     * @return DomainObjectInterface[]
132
     */
133
    protected function loadObjectsFromRepository(RepositoryInterface $repository, array $identifiers): iterable
134
    {
135
        /** @var DomainObjectInterface[] $objects */
UNCOV
136
        $objects = array_map([$repository, 'findByUid'], $identifiers);
×
UNCOV
137
        return $objects;
×
138
    }
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc