33700f4c6ca71b49ceb18de5744a721c9509c7b1
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Importer / MirrorListUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Importer;
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 * Module: Extension manager - Mirror list importer
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 */
33 /**
34 * Importer object for mirror list.
35 *
36 * @author Marcus Krause <marcus#exp2010@t3sec.info>
37 * @author Steffen Kamper <info@sk-typo3.de>
38 * @since 2010-02-10
39 * @package Extension Manager
40 * @subpackage Utility/Importer
41 */
42 class MirrorListUtility implements SplObserver {
43
44 /**
45 * Keeps instance of a XML parser.
46 *
47 * @var \TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlAbstractParser
48 */
49 protected $parser;
50
51 /**
52 * Keeps mirrors' details.
53 *
54 * @var array
55 */
56 protected $arrTmpMirrors = array();
57
58 /**
59 * Class constructor.
60 *
61 * Method retrieves and initializes extension XML parser instance.
62 *
63 * @throws tx_em_XmlException
64 */
65 public function __construct() {
66 // TODO catch parser exception
67 $this->parser = \TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory::getParserInstance('mirror');
68 if (is_object($this->parser)) {
69 $this->parser->attach($this);
70 } else {
71 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(get_class($this) . ': No XML parser available.', 1342640390);
72 }
73 }
74
75 /**
76 * Method collects mirrors' details and returns instance of
77 * Tx_Extensionmanager_Domain_Model_Mirrors with retrieved details.
78 *
79 * @param string $localMirrorListFile absolute path to local mirror xml.gz file
80 * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors
81 */
82 public function getMirrors($localMirrorListFile) {
83 $zlibStream = 'compress.zlib://';
84 $this->parser->parseXml($zlibStream . $localMirrorListFile);
85 /** @var $objRepositoryMirrors \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors */
86 $objRepositoryMirrors = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Mirrors');
87 $objRepositoryMirrors->setMirrors($this->arrTmpMirrors);
88 $this->arrTmpMirrors = array();
89 return $objRepositoryMirrors;
90 }
91
92 /**
93 * Method receives an update from a subject.
94 *
95 * @param SplSubject $subject a subject notifying this observer
96 * @return void
97 */
98 public function update(\SplSubject $subject) {
99 // TODO mirrorxml_abstract_parser
100 if (is_subclass_of($subject, 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\XmlAbstractParser')) {
101 $this->arrTmpMirrors[] = $subject->getAll();
102 }
103 }
104
105 }
106
107
108 ?>