4e7d847830feec6a7c801867ba0013c7469b15aa
[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 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 * @package Extension Manager
34 * @subpackage Utility/Parser
35 */
36 class XmlParserFactory {
37
38 /**
39 * An array with instances of xml parsers.
40 * This member is set in the getParserInstance() function.
41 *
42 * @var array
43 */
44 static protected $instance = array();
45
46 /**
47 * Keeps array of all available parsers.
48 *
49 * TODO: This would better be moved to
50 * a global configuration array like
51 * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'].
52 * (might require EM to be moved in a sysext)
53 *
54 * @var array
55 */
56 static protected $parsers = array(
57 'extension' => array(
58 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\ExtensionXmlPullParser' => 'ExtensionXmlPullParser.php',
59 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\ExtensionXmlPushParser' => 'ExtensionXmlPushParser.php'
60 ),
61 'mirror' => array(
62 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\MirrorXmlPullParser' => 'MirrorXmlPullParser.php',
63 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\MirrorXmlPushParser' => 'MirrorXmlPushParser.php'
64 )
65 );
66
67 /**
68 * Obtains a xml parser instance.
69 *
70 * This function will return an instance of a class that implements
71 * \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
72 *
73 * @param string $parserType type of parser, one of extension and mirror
74 * @param string $excludeClassNames (optional) comma-separated list of class names
75 * @return \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser an instance of an extension.xml parser
76 */
77 static public function getParserInstance($parserType, $excludeClassNames = '') {
78 if (!isset(self::$instance[$parserType]) || !is_object(self::$instance[$parserType]) || !empty($excludeClassNames)) {
79 // reset instance
80 self::$instance[$parserType] = ($objParser = NULL);
81 foreach (self::$parsers[$parserType] as $className => $file) {
82 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($excludeClassNames, $className)) {
83 $objParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
84 if ($objParser->isAvailable()) {
85 self::$instance[$parserType] =& $objParser;
86 break;
87 }
88 $objParser = NULL;
89 }
90 }
91 }
92 return self::$instance[$parserType];
93 }
94
95 }
96
97
98 ?>