Passed
Push — master ( 669ab6...e096b1 )
by
unknown
14:08
created

ViewHelperResolverFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
dl 0
loc 17
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Fluid\Core\ViewHelper;
19
20
use Psr\Container\ContainerInterface;
21
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
22
23
/**
24
 * Factory class registered in ServiceProvider to create a ViewHelperResolver.
25
 *
26
 * Note fluid is a failsafe mode aware extensions since its used in the install
27
 * tool. We thus need a ServiceProvider.php to correctly instantiate / inject
28
 * these class objects. This would be simple, but ViewHelperResolver has state,
29
 * and the failsafe mode expects injected services to not have state.
30
 *
31
 * So, to retrieve a ViewHelperResolver instance, an instance of this factory
32
 * is retrieved instead (which is a singleton), which then creates a 'fresh'
33
 * instance of the ViewHelperResolver each time create() is called.
34
 *
35
 * @internal May change / vanish any time
36
 */
37
final class ViewHelperResolverFactory
38
{
39
    private ContainerInterface $container;
40
    private ObjectManagerInterface $objectManager;
41
42
    public function __construct(
43
        ContainerInterface $container,
44
        ObjectManagerInterface $objectManager
45
    ) {
46
        $this->container = $container;
47
        $this->objectManager = $objectManager;
48
    }
49
50
    public function create(): ViewHelperResolver
51
    {
52
        $namespaces = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces'] ?? [];
53
        return new ViewHelperResolver($this->container, $this->objectManager, $namespaces);
54
    }
55
}
56