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