1debc440417156fbcd109c339c78b045933ac159
[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-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 * 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 */
40 class MirrorListUtility implements \SplObserver {
41
42 /**
43 * Keeps instance of a XML parser.
44 *
45 * @var \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser
46 */
47 protected $parser;
48
49 /**
50 * Keeps mirrors' details.
51 *
52 * @var array
53 */
54 protected $arrTmpMirrors = array();
55
56 /**
57 * Class constructor.
58 *
59 * Method retrieves and initializes extension XML parser instance
60 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
61 */
62 public function __construct() {
63 // TODO catch parser exception
64 $this->parser = \TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory::getParserInstance('mirror');
65 if (is_object($this->parser)) {
66 $this->parser->attach($this);
67 } else {
68 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(get_class($this) . ': No XML parser available.', 1342640390);
69 }
70 }
71
72 /**
73 * Method collects mirrors' details and returns instance of
74 * Tx_Extensionmanager_Domain_Model_Mirrors with retrieved details.
75 *
76 * @param string $localMirrorListFile absolute path to local mirror xml.gz file
77 * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors
78 */
79 public function getMirrors($localMirrorListFile) {
80 $zlibStream = 'compress.zlib://';
81 $this->parser->parseXml($zlibStream . $localMirrorListFile);
82 /** @var $objRepositoryMirrors \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors */
83 $objRepositoryMirrors = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Mirrors');
84 $objRepositoryMirrors->setMirrors($this->arrTmpMirrors);
85 $this->arrTmpMirrors = array();
86 return $objRepositoryMirrors;
87 }
88
89 /**
90 * Method receives an update from a subject.
91 *
92 * @param \SplSubject $subject a subject notifying this observer
93 * @return void
94 */
95 public function update(\SplSubject $subject) {
96 // TODO mirrorxml_abstract_parser
97 if (is_subclass_of($subject, 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\AbstractXmlParser')) {
98 $this->arrTmpMirrors[] = $subject->getAll();
99 }
100 }
101
102 }