Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / classes / import / class.tx_em_import_mirrorlistimporter.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Marcus Krause <marcus#exp2010@t3sec.info>
6 * Steffen Kamper <info@sk-typo3.de>
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25 /**
26 * class.tx_em_import_mirrorlistimporter.php
27 *
28 * Module: Extension manager - Mirror list importer
29 *
30 * $Id: class.tx_em_import_mirrorlistimporter.php 1982 2010-03-09 06:29:55Z mkrause $
31 *
32 * @author Marcus Krause <marcus#exp2010@t3sec.info>
33 * @author Steffen Kamper <info@sk-typo3.de>
34 */
35
36
37 /**
38 * Importer object for mirror list.
39 *
40 * @author Marcus Krause <marcus#exp2010@t3sec.info>
41 * @author Steffen Kamper <info@sk-typo3.de>
42 *
43 * @since 2010-02-10
44 * @package TYPO3
45 * @subpackage EM
46 */
47 class tx_em_Import_MirrorListImporter implements SplObserver {
48
49 /**
50 * Keeps instance of a XML parser.
51 *
52 * @var tx_em_Parser_MirrorXmlAbstractParser
53 */
54 protected $parser;
55
56 /**
57 * Keeps mirrors' details.
58 *
59 * @var array
60 */
61 protected $arrTmpMirrors = array();
62
63
64 /**
65 * Class constructor.
66 *
67 * Method retrieves and initializes extension XML parser instance.
68 *
69 * @access public
70 * @return void
71 * @throws tx_em_XmlException in case no valid parser instance is available
72 */
73 function __construct() {
74 // TODO catch parser exception
75 $this->parser = tx_em_Parser_XmlParserFactory::getParserInstance('mirror');
76 if (is_object($this->parser)) {
77 $this->parser->attach($this);
78 } else {
79 throw new tx_em_XmlException(get_class($this) . ': ' . 'No XML parser available.');
80 }
81 }
82
83 /**
84 * Method collects mirrors' details and returns instance of em_repository_mirrors
85 * with retrieved details.
86 *
87 * @access public
88 * @param string $localMirrorListFile bsolute path to (gzipped) local mirror list xml file
89 * @return em_repository_mirrors
90 */
91 public function getMirrors($localMirrorListFile) {
92 $zlibStream = 'compress.zlib://';
93
94 $this->parser->parseXML($zlibStream . $localMirrorListFile);
95 $objRepositoryMirrors = t3lib_div::makeInstance('tx_em_Repository_Mirrors');
96 $objRepositoryMirrors->setMirrors($this->arrTmpMirrors);
97 $this->arrTmpMirrors = array();
98 return $objRepositoryMirrors;
99 }
100
101 /**
102 * Method receives an update from a subject.
103 *
104 * @access public
105 * @param SplSubject $subject a subject notifying this observer
106 * @return void
107 */
108 public function update(SplSubject $subject) {
109 // TODO mirrorxml_abstract_parser
110 if (is_subclass_of($subject, 'tx_em_Parser_XmlAbstractParser')) {
111 $this->arrTmpMirrors[] = $subject->getAll();
112 }
113 }
114 }
115
116 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/import/class.tx_em_import_mirrorlistimporter.php'])) {
117 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/sysext/em/classes/import/class.tx_em_import_mirrorlistimporter.php']);
118 }
119
120 ?>