[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Importer / MirrorListUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Importer;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Module: Extension manager - Mirror list importer
18 *
19 * @author Marcus Krause <marcus#exp2010@t3sec.info>
20 * @author Steffen Kamper <info@sk-typo3.de>
21 */
22 /**
23 * Importer object for mirror list.
24 *
25 * @author Marcus Krause <marcus#exp2010@t3sec.info>
26 * @author Steffen Kamper <info@sk-typo3.de>
27 * @since 2010-02-10
28 */
29 class MirrorListUtility implements \SplObserver {
30
31 /**
32 * Keeps instance of a XML parser.
33 *
34 * @var \TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser
35 */
36 protected $parser;
37
38 /**
39 * Keeps mirrors' details.
40 *
41 * @var array
42 */
43 protected $arrTmpMirrors = array();
44
45 /**
46 * Class constructor.
47 *
48 * Method retrieves and initializes extension XML parser instance
49 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
50 */
51 public function __construct() {
52 // TODO catch parser exception
53 $this->parser = \TYPO3\CMS\Extensionmanager\Utility\Parser\XmlParserFactory::getParserInstance('mirror');
54 if (is_object($this->parser)) {
55 $this->parser->attach($this);
56 } else {
57 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(get_class($this) . ': No XML parser available.', 1342640390);
58 }
59 }
60
61 /**
62 * Method collects mirrors' details and returns instance of
63 * Tx_Extensionmanager_Domain_Model_Mirrors with retrieved details.
64 *
65 * @param string $localMirrorListFile absolute path to local mirror xml.gz file
66 * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors
67 */
68 public function getMirrors($localMirrorListFile) {
69 $zlibStream = 'compress.zlib://';
70 $this->parser->parseXml($zlibStream . $localMirrorListFile);
71 /** @var $objRepositoryMirrors \TYPO3\CMS\Extensionmanager\Domain\Model\Mirrors */
72 $objRepositoryMirrors = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Mirrors');
73 $objRepositoryMirrors->setMirrors($this->arrTmpMirrors);
74 $this->arrTmpMirrors = array();
75 return $objRepositoryMirrors;
76 }
77
78 /**
79 * Method receives an update from a subject.
80 *
81 * @param \SplSubject $subject a subject notifying this observer
82 * @return void
83 */
84 public function update(\SplSubject $subject) {
85 // TODO mirrorxml_abstract_parser
86 if (is_subclass_of($subject, 'TYPO3\\CMS\\Extensionmanager\\Utility\\Parser\\AbstractXmlParser')) {
87 $this->arrTmpMirrors[] = $subject->getAll();
88 }
89 }
90
91 }