1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php namespace Gettext\Languages\Exporter;
use Exception; use Gettext\Languages\Language;
/** * Base class for all the exporters. */ abstract class Exporter { /** * @var array */ private static $exporters; /** * Return the list of all the available exporters. Keys are the exporter handles, values are the exporter class names. * @param bool $onlyForPublicUse If true, internal exporters will be omitted. * @return string[] */ final public static function getExporters($onlyForPublicUse = false) { if (!isset(self::$exporters)) { $exporters = array(); $m = null; foreach (scandir(__DIR__) as $f) { if (preg_match('/^(\w+)\.php$/', $f, $m)) { if ($f !== basename(__FILE__)) { $exporters[strtolower($m[1])] = $m[1]; } } } self::$exporters = $exporters; } if ($onlyForPublicUse) { $result = array(); foreach (self::$exporters as $handle => $class) { if (call_user_func(self::getExporterClassName($handle).'::isForPublicUse') === true) { $result[$handle] = $class; } } } else { $result = self::$exporters; }
return $result; } /** * Return the description of a specific exporter. * @param string $exporterHandle The handle of the exporter. * @throws Exception Throws an Exception if $exporterHandle is not valid. * @return string */ final public static function getExporterDescription($exporterHandle) { $exporters = self::getExporters(); if (!isset($exporters[$exporterHandle])) { throw new Exception("Invalid exporter handle: '$exporterHandle'"); }
return call_user_func(self::getExporterClassName($exporterHandle).'::getDescription'); } /** * Returns the fully qualified class name of a exporter given its handle. * @param string $exporterHandle The exporter class handle. * @return string */ final public static function getExporterClassName($exporterHandle) { return __NAMESPACE__.'\\'.ucfirst(strtolower($exporterHandle)); } /** * Convert a list of Language instances to string. * @param Language[] $languages The Language instances to convert. * @return string */ protected static function toStringDo($languages) { throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__); } /** * Convert a list of Language instances to string. * @param Language[] $languages The Language instances to convert. * @return string */ final public static function toString($languages, $options = null) { if (isset($options) && is_array($options)) { if (isset($options['us-ascii']) && $options['us-ascii']) { $asciiList = array(); foreach ($languages as $language) { $asciiList[] = $language->getUSAsciiClone(); } $languages = $asciiList; } }
return static::toStringDo($languages); } /** * Save the Language instances to a file. * @param Language[] $languages The Language instances to convert. * @throws Exception */ final public static function toFile($languages, $filename, $options = null) { $data = self::toString($languages, $options); if (@file_put_contents($filename, $data) === false) { throw new Exception("Error writing data to '$filename'"); } } /** * Is this exporter for public use? * @return bool */ public static function isForPublicUse() { return true; } /** * Return a short description of the exporter. * @return string */ public static function getDescription() { throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__); } }
|