ae4fb5507f0605c4b585f68ac385ed9a2bef7d8e
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / Parser / AbstractXmlParser.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
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 * Abstract parser for EM related TYPO3 xml files.
29 *
30 * @author Marcus Krause <marcus#exp2010@t3sec.info>
31 * @author Steffen Kamper <info@sk-typo3.de>
32 * @since 2010-02-09
33 */
34 abstract class AbstractXmlParser implements \SplSubject {
35
36 /**
37 * Keeps XML parser instance.
38 *
39 * @var mixed
40 */
41 protected $objXml;
42
43 /**
44 * Keeps name of required PHP extension
45 * for this class to work properly.
46 *
47 * @var string
48 */
49 protected $requiredPhpExtensions;
50
51 /**
52 * Keeps list of attached observers.
53 *
54 * @var \SplObserver[]
55 */
56 protected $observers = array();
57
58 /**
59 * Method attaches an observer.
60 *
61 * @param \SplObserver $observer an observer to attach
62 * @return void
63 * @see $observers, detach(), notify()
64 */
65 public function attach(\SplObserver $observer) {
66 $this->observers[] = $observer;
67 }
68
69 /**
70 * Method detaches an attached observer
71 *
72 * @param \SplObserver $observer an observer to detach
73 * @return void
74 * @see $observers, attach(), notify()
75 */
76 public function detach(\SplObserver $observer) {
77 $key = array_search($observer, $this->observers, TRUE);
78 if ($key !== FALSE) {
79 unset($this->observers[$key]);
80 }
81 }
82
83 /**
84 * Method notifies attached observers.
85 *
86 * @access public
87 * @return void
88 * @see $observers, attach(), detach()
89 */
90 public function notify() {
91 foreach ($this->observers as $observer) {
92 $observer->update($this);
93 }
94 }
95
96 /**
97 * Method determines if a necessary PHP extension is available.
98 *
99 * Method tries to load the extension if necessary and possible.
100 *
101 * @access public
102 * @return boolean TRUE, if PHP extension is available, otherwise FALSE
103 */
104 public function isAvailable() {
105 $isAvailable = TRUE;
106 if (!extension_loaded($this->requiredPhpExtensions)) {
107 $prefix = PHP_SHLIB_SUFFIX === 'dll' ? 'php_' : '';
108 if (!(((bool) ini_get('enable_dl') && !(bool) ini_get('safe_mode')) && function_exists('dl') && dl($prefix . $this->requiredPhpExtensions . PHP_SHLIB_SUFFIX))) {
109 $isAvailable = FALSE;
110 }
111 }
112 return $isAvailable;
113 }
114
115 /**
116 * Method parses an XML file.
117 *
118 * @param string $file GZIP stream resource
119 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException in case of XML parser errors
120 */
121 abstract public function parseXml($file);
122
123 /**
124 * Create required parser
125 *
126 * @return void
127 */
128 abstract protected function createParser();
129 }