ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Enviro Class Reference

Helper class to handle command line options. More...

+ Collaboration diagram for Enviro:

Static Public Member Functions

static initialize ()
 Parse the command line options. More...
 
static showSyntax ()
 Write out the syntax. More...
 
static echoErr ($str)
 Print a string to stderr. More...
 
static reduce ($languages)
 Reduce a language list to the minimum common denominator. More...
 
static initialize ()
 Parse the command line options. More...
 
static showSyntax ()
 Write out the syntax. More...
 
static echoErr ($str)
 Print a string to stderr. More...
 
static reduce ($languages)
 Reduce a language list to the minimum common denominator. More...
 

Static Public Attributes

static $outputUSAscii
 
static $outputFormat
 
static $outputFilename
 
static $languages
 
static $reduce
 

Detailed Description

Helper class to handle command line options.

Definition at line 51 of file export-plural-rules.php.

Member Function Documentation

◆ echoErr() [1/2]

static Enviro::echoErr (   $str)
static

Print a string to stderr.

Parameters
string$strThe string to be printed out.

Definition at line 183 of file export-plural-rules.php.

184 {
185 $hStdErr = @fopen('php://stderr', 'a');
186 if ($hStdErr === false) {
187 echo $str;
188 } else {
189 fwrite($hStdErr, $str);
190 fclose($hStdErr);
191 }
192 }

Referenced by initialize(), and showSyntax().

+ Here is the caller graph for this function:

◆ echoErr() [2/2]

static Enviro::echoErr (   $str)
static

Print a string to stderr.

Parameters
string$strThe string to be printed out.

Definition at line 183 of file export-plural-rules.php.

184 {
185 $hStdErr = @fopen('php://stderr', 'a');
186 if ($hStdErr === false) {
187 echo $str;
188 } else {
189 fwrite($hStdErr, $str);
190 fclose($hStdErr);
191 }
192 }

◆ initialize() [1/2]

static Enviro::initialize ( )
static

Parse the command line options.

Definition at line 81 of file export-plural-rules.php.

82 {
83 global $argv;
84 self::$outputUSAscii = false;
85 self::$outputFormat = null;
86 self::$outputFilename = null;
87 self::$languages = null;
88 self::$reduce = null;
89 $exporters = Exporter::getExporters();
90 if (isset($argv) && is_array($argv)) {
91 foreach ($argv as $argi => $arg) {
92 if ($argi === 0) {
93 continue;
94 }
95 if (is_string($arg)) {
96 $argLC = trim(strtolower($arg));
97 switch ($argLC) {
98 case '--us-ascii':
99 self::$outputUSAscii = true;
100 break;
101 case '--reduce=yes':
102 self::$reduce = true;
103 break;
104 case '--reduce=no':
105 self::$reduce = false;
106 break;
107 default:
108 if (preg_match('/^--output=.+$/', $argLC)) {
109 if (isset(self::$outputFilename)) {
110 self::echoErr("The output file name has been specified more than once!\n");
112 die(3);
113 }
114 list(, self::$outputFilename) = explode('=', $arg, 2);
115 self::$outputFilename = trim(self::$outputFilename);
116 } elseif (preg_match('/^--languages?=.+$/', $argLC)) {
117 list(, $s) = explode('=', $arg, 2);
118 $list = explode(',', $s);
119 if (is_array(self::$languages)) {
120 self::$languages = array_merge(self::$languages, $list);
121 } else {
122 self::$languages = $list;
123 }
124 } elseif (isset($exporters[$argLC])) {
125 if (isset(self::$outputFormat)) {
126 self::echoErr("The output format has been specified more than once!\n");
128 die(3);
129 }
130 self::$outputFormat = $argLC;
131 } else {
132 self::echoErr("Unknown option: $arg\n");
134 die(2);
135 }
136 break;
137 }
138 }
139 }
140 }
141 if (!isset(self::$outputFormat)) {
143 die(1);
144 }
145 if (isset(self::$languages)) {
146 self::$languages = array_values(array_unique(self::$languages));
147 }
148 if (!isset(self::$reduce)) {
149 self::$reduce = isset(self::$languages) ? false : true;
150 }
151 }
static echoErr($str)
Print a string to stderr.
static showSyntax()
Write out the syntax.
$s
Definition: pwgen.php:45
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
global $argv
Definition: svg-scanner.php:41

References $argv, $list, $s, echoErr(), and showSyntax().

+ Here is the call graph for this function:

◆ initialize() [2/2]

static Enviro::initialize ( )
static

Parse the command line options.

Definition at line 81 of file export-plural-rules.php.

82 {
83 global $argv;
84 self::$outputUSAscii = false;
85 self::$outputFormat = null;
86 self::$outputFilename = null;
87 self::$languages = null;
88 self::$reduce = null;
89 $exporters = Exporter::getExporters();
90 if (isset($argv) && is_array($argv)) {
91 foreach ($argv as $argi => $arg) {
92 if ($argi === 0) {
93 continue;
94 }
95 if (is_string($arg)) {
96 $argLC = trim(strtolower($arg));
97 switch ($argLC) {
98 case '--us-ascii':
99 self::$outputUSAscii = true;
100 break;
101 case '--reduce=yes':
102 self::$reduce = true;
103 break;
104 case '--reduce=no':
105 self::$reduce = false;
106 break;
107 default:
108 if (preg_match('/^--output=.+$/', $argLC)) {
109 if (isset(self::$outputFilename)) {
110 self::echoErr("The output file name has been specified more than once!\n");
112 die(3);
113 }
114 list(, self::$outputFilename) = explode('=', $arg, 2);
115 self::$outputFilename = trim(self::$outputFilename);
116 } elseif (preg_match('/^--languages?=.+$/', $argLC)) {
117 list(, $s) = explode('=', $arg, 2);
118 $list = explode(',', $s);
119 if (is_array(self::$languages)) {
120 self::$languages = array_merge(self::$languages, $list);
121 } else {
122 self::$languages = $list;
123 }
124 } elseif (isset($exporters[$argLC])) {
125 if (isset(self::$outputFormat)) {
126 self::echoErr("The output format has been specified more than once!\n");
128 die(3);
129 }
130 self::$outputFormat = $argLC;
131 } else {
132 self::echoErr("Unknown option: $arg\n");
134 die(2);
135 }
136 break;
137 }
138 }
139 }
140 }
141 if (!isset(self::$outputFormat)) {
143 die(1);
144 }
145 if (isset(self::$languages)) {
146 self::$languages = array_values(array_unique(self::$languages));
147 }
148 if (!isset(self::$reduce)) {
149 self::$reduce = isset(self::$languages) ? false : true;
150 }
151 }

References $argv, $list, $s, echoErr(), and showSyntax().

+ Here is the call graph for this function:

◆ reduce() [1/2]

static Enviro::reduce (   $languages)
static

Reduce a language list to the minimum common denominator.

Parameters
Language[]$languages
Returns
Language[]

Definition at line 198 of file export-plural-rules.php.

199 {
200 for ($numChunks = 3; $numChunks >= 2; $numChunks--) {
201 $filtered = array();
202 foreach ($languages as $language) {
203 $chunks = explode('_', $language->id);
204 $compatibleFound = false;
205 if (count($chunks) === $numChunks) {
206 $categoriesHash = serialize($language->categories);
207 $otherIds = array();
208 $otherIds[] = $chunks[0];
209 for ($k = 2; $k < $numChunks; $k++) {
210 $otherIds[] = $chunks[0].'_'.$chunks[$numChunks - 1];
211 }
212
213 foreach ($languages as $check) {
214 foreach ($otherIds as $otherId) {
215 if (($check->id === $otherId) && ($check->formula === $language->formula) && (serialize($check->categories) === $categoriesHash)) {
216 $compatibleFound = true;
217 break;
218 }
219 }
220 if ($compatibleFound === true) {
221 break;
222 }
223 }
224 }
225 if (!$compatibleFound) {
226 $filtered[] = $language;
227 }
228 }
229 $languages = $filtered;
230 }
231
232 return $languages;
233 }
static $languages

References $languages.

◆ reduce() [2/2]

static Enviro::reduce (   $languages)
static

Reduce a language list to the minimum common denominator.

Parameters
Language[]$languages
Returns
Language[]

Definition at line 198 of file export-plural-rules.php.

199 {
200 for ($numChunks = 3; $numChunks >= 2; $numChunks--) {
201 $filtered = array();
202 foreach ($languages as $language) {
203 $chunks = explode('_', $language->id);
204 $compatibleFound = false;
205 if (count($chunks) === $numChunks) {
206 $categoriesHash = serialize($language->categories);
207 $otherIds = array();
208 $otherIds[] = $chunks[0];
209 for ($k = 2; $k < $numChunks; $k++) {
210 $otherIds[] = $chunks[0].'_'.$chunks[$numChunks - 1];
211 }
212
213 foreach ($languages as $check) {
214 foreach ($otherIds as $otherId) {
215 if (($check->id === $otherId) && ($check->formula === $language->formula) && (serialize($check->categories) === $categoriesHash)) {
216 $compatibleFound = true;
217 break;
218 }
219 }
220 if ($compatibleFound === true) {
221 break;
222 }
223 }
224 }
225 if (!$compatibleFound) {
226 $filtered[] = $language;
227 }
228 }
229 $languages = $filtered;
230 }
231
232 return $languages;
233 }

References $languages.

◆ showSyntax() [1/2]

static Enviro::showSyntax ( )
static

Write out the syntax.

Definition at line 156 of file export-plural-rules.php.

157 {
158 $exporters = array_keys(Exporter::getExporters(true));
159 self::echoErr("Syntax: php ".basename(__FILE__)." [--us-ascii] [--languages=<LanguageId>[,<LanguageId>,...]] [--reduce=yes|no] [--output=<file name>] <".implode('|', $exporters).">\n");
160 self::echoErr("Where:\n");
161 self::echoErr("--us-ascii : if specified, the output will contain only US-ASCII characters.\n");
162 self::echoErr("--languages: (or --language) export only the specified language codes.\n");
163 self::echoErr(" Separate languages with commas; you can also use this argument\n");
164 self::echoErr(" more than once; it's case insensitive and accepts both '_' and\n");
165 self::echoErr(" '-' as locale chunks separator (eg we accept 'it_IT' as well as\n");
166 self::echoErr(" 'it-it').\n");
167 self::echoErr("--reduce : if set to yes the output won't contain languages with the same\n");
168 self::echoErr(" base language and rules.\n For instance nl_BE ('Flemish') will be\n");
169 self::echoErr(" omitted because it's the same as nl ('Dutch').\n");
170 self::echoErr(" Defaults to 'no' --languages is specified, to 'yes' otherwise.\n");
171 self::echoErr("--output : if specified, the output will be saved to <file name>. If not\n");
172 self::echoErr(" specified we'll output to standard output.\n");
173 self::echoErr("Output formats\n");
174 $len = max(array_map('strlen', $exporters));
175 foreach ($exporters as $exporter) {
176 self::echoErr(str_pad($exporter, $len).": ".Exporter::getExporterDescription($exporter)."\n");
177 }
178 }

References echoErr().

Referenced by initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ showSyntax() [2/2]

static Enviro::showSyntax ( )
static

Write out the syntax.

Definition at line 156 of file export-plural-rules.php.

157 {
158 $exporters = array_keys(Exporter::getExporters(true));
159 self::echoErr("Syntax: php ".basename(__FILE__)." [--us-ascii] [--languages=<LanguageId>[,<LanguageId>,...]] [--reduce=yes|no] [--output=<file name>] <".implode('|', $exporters).">\n");
160 self::echoErr("Where:\n");
161 self::echoErr("--us-ascii : if specified, the output will contain only US-ASCII characters.\n");
162 self::echoErr("--languages: (or --language) export only the specified language codes.\n");
163 self::echoErr(" Separate languages with commas; you can also use this argument\n");
164 self::echoErr(" more than once; it's case insensitive and accepts both '_' and\n");
165 self::echoErr(" '-' as locale chunks separator (eg we accept 'it_IT' as well as\n");
166 self::echoErr(" 'it-it').\n");
167 self::echoErr("--reduce : if set to yes the output won't contain languages with the same\n");
168 self::echoErr(" base language and rules.\n For instance nl_BE ('Flemish') will be\n");
169 self::echoErr(" omitted because it's the same as nl ('Dutch').\n");
170 self::echoErr(" Defaults to 'no' --languages is specified, to 'yes' otherwise.\n");
171 self::echoErr("--output : if specified, the output will be saved to <file name>. If not\n");
172 self::echoErr(" specified we'll output to standard output.\n");
173 self::echoErr("Output formats\n");
174 $len = max(array_map('strlen', $exporters));
175 foreach ($exporters as $exporter) {
176 self::echoErr(str_pad($exporter, $len).": ".Exporter::getExporterDescription($exporter)."\n");
177 }
178 }

References echoErr().

+ Here is the call graph for this function:

Field Documentation

◆ $languages

static Enviro::$languages
static

Definition at line 72 of file export-plural-rules.php.

Referenced by reduce().

◆ $outputFilename

static Enviro::$outputFilename
static

Definition at line 67 of file export-plural-rules.php.

◆ $outputFormat

static Enviro::$outputFormat
static

Definition at line 62 of file export-plural-rules.php.

◆ $outputUSAscii

static Enviro::$outputUSAscii
static

Definition at line 57 of file export-plural-rules.php.

◆ $reduce

static Enviro::$reduce
static

Definition at line 77 of file export-plural-rules.php.


The documentation for this class was generated from the following files: