[BUGFIX] Use push parser instead of pull parser on fetching extension list
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Parser / XmlParserFactory.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Factory for XML parsers.
19 * @since 2010-02-10
20 */
21 class XmlParserFactory
22 {
23 /**
24 * An array with instances of xml parsers.
25 * This member is set in the getParserInstance() function.
26 *
27 * @var array
28 */
29 protected static $instance = array();
30
31 /**
32 * Keeps array of all available parsers.
33 *
34 * @todo This would better be moved to a global configuration array like
35 * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']. (might require EM to be moved in a sysext)
36 *
37 * @var array
38 */
39 protected static $parsers = array(
40 'extension' => array(
41 \TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser::class => 'ExtensionXmlPushParser.php',
42 \TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser::class => 'ExtensionXmlPullParser.php',
43 ),
44 'mirror' => array(
45 \TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser::class => 'MirrorXmlPushParser.php',
46 \TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser::class=> 'MirrorXmlPullParser.php',
47 )
48 );
49
50 /**
51 * Obtains a xml parser instance.
52 *
53 * This function will return an instance of a class that implements
54 * \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
55 *
56 * @param string $parserType type of parser, one of extension and mirror
57 * @param string $excludeClassNames (optional) comma-separated list of class names
58 * @return \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser an instance of an extension.xml parser
59 */
60 public static function getParserInstance($parserType, $excludeClassNames = '')
61 {
62 if (!isset(self::$instance[$parserType]) || !is_object(self::$instance[$parserType]) || !empty($excludeClassNames)) {
63 // reset instance
64 self::$instance[$parserType] = ($objParser = null);
65 foreach (self::$parsers[$parserType] as $className => $file) {
66 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeClassNames, $className)) {
67 $objParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
68 if ($objParser->isAvailable()) {
69 self::$instance[$parserType] = &$objParser;
70 break;
71 }
72 $objParser = null;
73 }
74 }
75 }
76 return self::$instance[$parserType];
77 }
78 }