Completed
Push — master ( c92ef6...3f980f )
by
unknown
13:33
created

XmlParserFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getParserInstance() 0 15 5
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
17
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20
/**
21
 * Factory for XML parsers.
22
 * @internal This class is a specific ExtensionManager implementation and is not part of the Public TYPO3 API.
23
 */
24
class XmlParserFactory
25
{
26
    /**
27
     * An array with instances of xml parsers.
28
     * This member is set in the getParserInstance() function.
29
     *
30
     * @var AbstractExtensionXmlParser
31
     */
32
    protected static $instance;
33
34
    /**
35
     * Keeps array of all available parsers.
36
     *
37
     * @var array
38
     */
39
    protected static $parsers = [
40
        ExtensionXmlPushParser::class,
41
        ExtensionXmlPullParser::class,
42
    ];
43
44
    /**
45
     * Obtains a xml parser instance.
46
     *
47
     * This function will return an instance of a class that implements
48
     * \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
49
     *
50
     * @return AbstractExtensionXmlParser an instance of an extension.xml parser
51
     */
52
    public static function getParserInstance()
53
    {
54
        if (!isset(self::$instance) || !is_object(self::$instance)) {
55
            // reset instance
56
            self::$instance = null;
57
            foreach (self::$parsers as $className) {
58
                /** @var AbstractExtensionXmlParser $objParser */
59
                $objParser = GeneralUtility::makeInstance($className);
60
                if ($objParser->isAvailable()) {
61
                    self::$instance = $objParser;
62
                    break;
63
                }
64
            }
65
        }
66
        return self::$instance;
67
    }
68
}
69