TYPO3 API  SVNRelease
class.tx_em_parser_xmlparserfactory.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010 Marcus Krause <marcus#exp2010@t3sec.info>
00006  *         Steffen Kamper <info@sk-typo3.de>
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *
00018  *  This script is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU General Public License for more details.
00022  *
00023  *  This copyright notice MUST APPEAR in all copies of the script!
00024  ***************************************************************/
00025 /**
00026  * class.tx_em_parser_xmlparserfactory.php
00027  *
00028  * Module: Extension manager - XML parser factory
00029  *
00030  * $Id: class.tx_em_parser_xmlparserfactory.php 1911 2010-02-21 14:50:40Z mkrause $
00031  *
00032  * @author  Marcus Krause <marcus#exp2010@t3sec.info>
00033  * @author  Steffen Kamper <info@sk-typo3.de>
00034  */
00035 
00036 /**
00037  * Factory for XML parsers.
00038  *
00039  * @author    Marcus Krause <marcus#exp2010@t3sec.info>
00040  * @author    Steffen Kamper <info@sk-typo3.de>
00041  *
00042  * @since      2010-02-10
00043  * @package  TYPO3
00044  * @subpackage  EM
00045  */
00046 class tx_em_Parser_XmlParserFactory {
00047 
00048     /**
00049      * An array with instances of xml parsers.
00050      * This member is set in the getParserInstance() function.
00051      *
00052      * @var array
00053      */
00054     static protected $instance = array();
00055 
00056     /**
00057      * Keeps array of all available parsers.
00058      *
00059      * TODO: This would better be moved to
00060      * a global configuration array like
00061      * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'].
00062      * (might require EM to be moved in a sysext)
00063      *
00064      * @var array
00065      */
00066     static protected $parsers = array(
00067         'extension' => array(
00068             'tx_em_parser_extensionxmlpullparser' => 'class.tx_em_parser_extensionxmlpullparser.php',
00069             'tx_em_parser_extensionxmlpushparser' => 'class.tx_em_parser_extensionxmlpushparser.php',
00070         ),
00071         'mirror' => array(
00072             'tx_em_parser_mirrorxmlpullparser' => 'class.tx_em_parser_mirrorxmlpullparser.php',
00073             'tx_em_parser_mirrorxmlpushparser' => 'class.tx_em_parser_mirrorxmlpushparser.php',
00074         ),
00075     );
00076 
00077 
00078     /**
00079      * Obtains a xml parser instance.
00080      *
00081      * This function will return an instance of a class that implements
00082      * em_extensionxml_abstract_parser.
00083      *
00084      * TODO use autoload if possible (might require EM to be moved in a sysext)
00085      *
00086      * @access  public
00087      * @param   string    $parserType: type of parser, one of extension and mirror
00088      * @param   string      $excludeClassNames: (optional) comma-separated list of class names
00089      * @return  em_extensionxml_abstract_parser an instance of an extension.xml parser
00090      */
00091     static public function getParserInstance($parserType, $excludeClassNames = '') {
00092         if (!isset(self::$instance[$parserType]) || !is_object(self::$instance[$parserType]) || !empty($excludeClassNames)) {
00093             // reset instance
00094             self::$instance[$parserType] = $objParser = NULL;
00095             foreach (self::$parsers[$parserType] as $className => $file) {
00096                 if (!t3lib_div::inList($excludeClassNames, $className)) {
00097                     //require_once(dirname(__FILE__) . '/' . $file);
00098                     $objParser = t3lib_div::makeInstance($className);
00099                     if ($objParser->isAvailable()) {
00100                         self::$instance[$parserType] = &$objParser;
00101                         break;
00102                     }
00103                     $objParser = NULL;
00104                 }
00105             }
00106         }
00107         return self::$instance[$parserType];
00108     }
00109 }
00110 
00111 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_xmlparserfactory.php'])) {
00112     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/parser/class.tx_em_parser_xmlparserfactory.php']);
00113 }
00114 
00115 ?>