a6d11625f5a7955a3a8a10444f222f657e22d1a5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Parser / XmlParserFactory.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Marcus Krause <marcus#exp2010@t3sec.info>
8 * Steffen Kamper <info@sk-typo3.de>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Factory for XML parsers.
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 * @since 2010-02-10
33 */
34 class XmlParserFactory {
35
36 /**
37 * An array with instances of xml parsers.
38 * This member is set in the getParserInstance() function.
39 *
40 * @var array
41 */
42 static protected $instance = array();
43
44 /**
45 * Keeps array of all available parsers.
46 *
47 * TODO: This would better be moved to
48 * a global configuration array like
49 * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'].
50 * (might require EM to be moved in a sysext)
51 *
52 * @var array
53 */
54 static protected $parsers = array(
55 'extension' => array(
56 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\ExtensionXmlPullParser' => 'ExtensionXmlPullParser.php',
57 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\ExtensionXmlPushParser' => 'ExtensionXmlPushParser.php'
58 ),
59 'mirror' => array(
60 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\MirrorXmlPullParser' => 'MirrorXmlPullParser.php',
61 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\MirrorXmlPushParser' => 'MirrorXmlPushParser.php'
62 )
63 );
64
65 /**
66 * Obtains a xml parser instance.
67 *
68 * This function will return an instance of a class that implements
69 * \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
70 *
71 * @param string $parserType type of parser, one of extension and mirror
72 * @param string $excludeClassNames (optional) comma-separated list of class names
73 * @return \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser an instance of an extension.xml parser
74 */
75 static public function getParserInstance($parserType, $excludeClassNames = '') {
76 if (!isset(self::$instance[$parserType]) || !is_object(self::$instance[$parserType]) || !empty($excludeClassNames)) {
77 // reset instance
78 self::$instance[$parserType] = ($objParser = NULL);
79 foreach (self::$parsers[$parserType] as $className => $file) {
80 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeClassNames, $className)) {
81 $objParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
82 if ($objParser->isAvailable()) {
83 self::$instance[$parserType] = &$objParser;
84 break;
85 }
86 $objParser = NULL;
87 }
88 }
89 }
90 return self::$instance[$parserType];
91 }
92
93 }