PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
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 3.0.1, at vendor/gettext/languages/src/Exporter/Exporter.php

154 lines 4.3 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 if (isset($options['us-ascii']) && $options['us-ascii']) {
95 $asciiList = array();
96 foreach ($languages as $language) {
97 $asciiList[] = $language->getUSAsciiClone();
98 }
99 $languages = $asciiList;
100 }
101 }
102
103 return static::toStringDo($languages);
104 }
105
106 /**
107 * Save the Language instances to a file.
108 *
109 * @param \Gettext\Languages\Language[] $languages the Language instances to convert
110 * @param array|null $options
111 *
112 * @throws \Exception
113 */
114 final public static function toFile($languages, $filename, $options = null)
115 {
116 $data = self::toString($languages, $options);
117 if (@file_put_contents($filename, $data) === false) {
118 throw new Exception("Error writing data to '{$filename}'");
119 }
120 }
121
122 /**
123 * Is this exporter for public use?
124 *
125 * @return bool
126 */
127 public static function isForPublicUse()
128 {
129 return true;
130 }
131
132 /**
133 * Return a short description of the exporter.
134 *
135 * @return string
136 */
137 public static function getDescription()
138 {
139 throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__);
140 }
141
142 /**
143 * Convert a list of Language instances to string.
144 *
145 * @param \Gettext\Languages\Language[] $languages the Language instances to convert
146 *
147 * @return string
148 */
149 protected static function toStringDo($languages)
150 {
151 throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__);
152 }
153 }
154