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

FluidTYPO3 / flux / 27757675993

18 Jun 2026 11:55AM UTC coverage: 89.162% (-3.5%) from 92.646%
27757675993

push

github

NamelessCoder
[TASK] Address last phpstan warnings

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

96.55
/Classes/Provider/ProviderResolver.php
1
<?php
2
namespace FluidTYPO3\Flux\Provider;
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\Core;
12
use FluidTYPO3\Flux\Hooks\HookHandler;
13
use FluidTYPO3\Flux\Provider\Interfaces\RecordProviderInterface;
14
use TYPO3\CMS\Core\SingletonInterface;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16

17
/**
18
 * Provider Resolver
19
 *
20
 * Returns one or more Provider instances based on parameters.
21
 */
22
class ProviderResolver implements SingletonInterface
23
{
24
    protected array $providers = [];
25

26
    /**
27
     * Resolve fluidpages specific configuration provider. Always
28
     * returns the main PageProvider type which needs to be used
29
     * as primary PageProvider when processing a complete page
30
     * rather than just the "sub configuration" field value.
31
     */
32
    public function resolvePageProvider(array $row): ?ProviderInterface
33
    {
34
        $provider = $this->resolvePrimaryConfigurationProvider('pages', PageProvider::FIELD_NAME_MAIN, $row);
×
35
        return $provider;
×
36
    }
37

38
    /**
39
     * ResolveUtility the top-priority ConfigurationPrivider which can provide
40
     * a working FlexForm configuration baed on the given parameters.
41
     *
42
     * @template T
43
     * @param class-string<T>[] $interfaces
44
     * @return T|null
45
     */
46
    public function resolvePrimaryConfigurationProvider(
47
        ?string $table,
48
        ?string $fieldName,
49
        ?array $row = null,
50
        ?string $extensionKey = null,
51
        array $interfaces = [ProviderInterface::class]
52
    ) {
53
        $providers = $this->resolveConfigurationProviders($table, $fieldName, $row, $extensionKey, $interfaces);
4✔
54
        return reset($providers) ?: null;
4✔
55
    }
56

57
    /**
58
     * Resolves a ConfigurationProvider which can provide a working FlexForm
59
     * configuration based on the given parameters.
60
     *
61
     * @template T
62
     * @param class-string<T>[] $interfaces
63
     * @return T[]
64
     */
65
    public function resolveConfigurationProviders(
66
        ?string $table,
67
        ?string $fieldName,
68
        ?array $row = null,
69
        ?string $extensionKey = null,
70
        array $interfaces = [ProviderInterface::class]
71
    ) {
72
        $row = false === is_array($row) ? [] : $row;
12✔
73
        $providers = $this->getAllRegisteredProviderInstances();
12✔
74
        if ($interfaces) {
12✔
75
            $providers = array_filter(
12✔
76
                $providers,
12✔
77
                function ($provider) use ($interfaces) {
12✔
78
                    foreach ((array) $interfaces as $interface) {
12✔
79
                        if (!is_a($provider, $interface, true)) {
12✔
80
                            return false;
4✔
81
                        }
82
                    }
83
                    return true;
12✔
84
                }
12✔
85
            );
12✔
86
        }
87
        usort(
12✔
88
            $providers,
12✔
89
            function (ProviderInterface $a, ProviderInterface $b) use ($row) {
12✔
90
                return $b->getPriority($row) <=> $a->getPriority($row);
12✔
91
            }
12✔
92
        );
12✔
93
        // RecordProviderInterface being missing will automatically include the Provider. Those that do
94
        // implement the interface will be asked if they should trigger on the table/field/row/ext combo.
95
        $providers = array_filter(
12✔
96
            $providers,
12✔
97
            function (ProviderInterface $provider) use ($row, $table, $fieldName, $extensionKey) {
12✔
98
                return !$provider instanceof RecordProviderInterface
12✔
99
                    || $provider->trigger($row, $table, $fieldName, $extensionKey);
12✔
100
            }
12✔
101
        );
12✔
102
        return HookHandler::trigger(
12✔
103
            HookHandler::PROVIDERS_RESOLVED,
12✔
104
            [
12✔
105
                'table' => $table,
12✔
106
                'field' => $fieldName,
12✔
107
                'record' => $row,
12✔
108
                'extensionKey' => $extensionKey,
12✔
109
                'interfaces' => $interfaces,
12✔
110
                'providers' => $providers
12✔
111
            ]
12✔
112
        )['providers'];
12✔
113
    }
114

115
    /**
116
     * @return ProviderInterface[]
117
     */
118
    protected function getAllRegisteredProviderInstances(): array
119
    {
120
        if (empty($this->providers)) {
4✔
121
            $providers = $this->loadCoreRegisteredProviders();
4✔
122
            $this->providers = $this->validateAndInstantiateProviders($providers);
4✔
123
        }
124
        return $this->providers;
4✔
125
    }
126

127
    /**
128
     * @return ProviderInterface[]
129
     */
130
    protected function validateAndInstantiateProviders(array $providers): array
131
    {
132
        $instances = [];
20✔
133
        foreach ($providers as $classNameOrInstance) {
20✔
134
            if (!is_a($classNameOrInstance, ProviderInterface::class, true)) {
16✔
135
                $className = is_object($classNameOrInstance) ? get_class($classNameOrInstance) : $classNameOrInstance;
8✔
136
                throw new \RuntimeException(
8✔
137
                    $className . ' must implement ProviderInterfaces from Flux/Provider',
8✔
138
                    1327173536
8✔
139
                );
8✔
140
            }
141
            if (true === is_object($classNameOrInstance)) {
8✔
142
                /** @var ProviderInterface $provider */
143
                $provider = $classNameOrInstance;
4✔
144
            } else {
145
                /** @var ProviderInterface $provider */
146
                $provider = GeneralUtility::makeInstance($classNameOrInstance);
4✔
147
            }
148
            $instances[] = $provider;
8✔
149
        }
150
        return $instances;
12✔
151
    }
152

153
    protected function loadCoreRegisteredProviders(): array
154
    {
155
        return Core::getRegisteredFlexFormProviders();
4✔
156
    }
157
}
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