PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / gettext / languages / src / Exporter / Exporter.php

Exporter.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at vendor/gettext/languages/src/Exporter/Exporter.php

169 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Gettext\Languages\Exporter;
4
5 use Exception;
6
7 /**
8 * Base class for all the exporters.
9 */
10 abstract class Exporter
11 {
12 /**
13 * @var array
14 */
15 private static $exporters;
16
17 /**
18 * Return the list of all the available exporters. Keys are the exporter handles, values are the exporter class names.
19 *
20 * @param bool $onlyForPublicUse if true, internal exporters will be omitted
21 *
22 * @return string[]
23 */
24 final public static function getExporters($onlyForPublicUse = false)
25 {
26 if (!isset(self::$exporters)) {
27 $exporters = array();
28 $m = null;
29 foreach (scandir(__DIR__) as $f) {
30 if (preg_match('/^(\w+)\.php$/', $f, $m)) {
31 if ($f !== basename(__FILE__)) {
32 $exporters[strtolower($m[1])] = $m[1];
33 }
34 }
35 }
36 self::$exporters = $exporters;
37 }
38 if ($onlyForPublicUse) {
39 $result = array();
40 foreach (self::$exporters as $handle => $class) {
41 if (call_user_func(self::getExporterClassName($handle) . '::isForPublicUse') === true) {
42 $result[$handle] = $class;
43 }
44 }
45 } else {
46 $result = self::$exporters;
47 }
48
49 return $result;
50 }
51
52 /**
53 * Return the description of a specific exporter.
54 *
55 * @param string $exporterHandle the handle of the exporter
56 *
57 * @throws \Exception throws an Exception if $exporterHandle is not valid
58 *
59 * @return string
60 */
61 final public static function getExporterDescription($exporterHandle)
62 {
63 $exporters = self::getExporters();
64 if (!isset($exporters[$exporterHandle])) {
65 throw new Exception("Invalid exporter handle: '{$exporterHandle}'");
66 }
67
68 return call_user_func(self::getExporterClassName($exporterHandle) . '::getDescription');
69 }
70
71 /**
72 * Returns the fully qualified class name of a exporter given its handle.
73 *
74 * @param string $exporterHandle the exporter class handle
75 *
76 * @return string
77 */
78 final public static function getExporterClassName($exporterHandle)
79 {
80 return __NAMESPACE__ . '\\' . ucfirst(strtolower($exporterHandle));
81 }
82
83 /**
84 * Convert a list of Language instances to string.
85 *
86 * @param \Gettext\Languages\Language[] $languages the Language instances to convert
87 * @param array|null $options
88 *
89 * @return string
90 */
91 final public static function toString($languages, $options = null)
92 {
93 if (!isset($options) || !is_array($options)) {
94 $options = array();
95 }
96 if (isset($options['us-ascii']) && $options['us-ascii']) {
97 $asciiList = array();
98 foreach ($languages as $language) {
99 $asciiList[] = $language->getUSAsciiClone();
100 }
101 $languages = $asciiList;
102 }
103
104 return static::toStringDoWithOptions($languages, $options);
105 }
106
107 /**
108 * Save the Language instances to a file.
109 *
110 * @param \Gettext\Languages\Language[] $languages the Language instances to convert
111 * @param array|null $options
112 *
113 * @throws \Exception
114 */
115 final public static function toFile($languages, $filename, $options = null)
116 {
117 $data = self::toString($languages, $options);
118 if (@file_put_contents($filename, $data) === false) {
119 throw new Exception("Error writing data to '{$filename}'");
120 }
121 }
122
123 /**
124 * Is this exporter for public use?
125 *
126 * @return bool
127 */
128 public static function isForPublicUse()
129 {
130 return true;
131 }
132
133 /**
134 * Does this exporter supports exporting formulas both with and without extra parenthesis?
135 *
136 * @return bool
137 */
138 public static function supportsFormulasWithAndWithoutParenthesis()
139 {
140 return false;
141 }
142
143 /**
144 * Return a short description of the exporter.
145 *
146 * @return string
147 */
148 public static function getDescription()
149 {
150 throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__);
151 }
152
153 /**
154 * Convert a list of Language instances to string.
155 *
156 * @param \Gettext\Languages\Language[] $languages the Language instances to convert
157 * @param array $options export options
158 *
159 * @return string
160 */
161 protected static function toStringDoWithOptions($languages, array $options)
162 {
163 if (method_exists(get_called_class(), 'toStringDo')) {
164 return static::toStringDo($languages);
165 }
166 throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__);
167 }
168 }
169