ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Exporter.php
Go to the documentation of this file.
1<?php
3
4use Exception;
6
10abstract class Exporter
11{
15 private static $exporters;
21 final public static function getExporters($onlyForPublicUse = false)
22 {
23 if (!isset(self::$exporters)) {
24 $exporters = array();
25 $m = null;
26 foreach (scandir(__DIR__) as $f) {
27 if (preg_match('/^(\w+)\.php$/', $f, $m)) {
28 if ($f !== basename(__FILE__)) {
29 $exporters[strtolower($m[1])] = $m[1];
30 }
31 }
32 }
33 self::$exporters = $exporters;
34 }
35 if ($onlyForPublicUse) {
36 $result = array();
37 foreach (self::$exporters as $handle => $class) {
38 if (call_user_func(self::getExporterClassName($handle).'::isForPublicUse') === true) {
39 $result[$handle] = $class;
40 }
41 }
42 } else {
44 }
45
46 return $result;
47 }
54 final public static function getExporterDescription($exporterHandle)
55 {
57 if (!isset($exporters[$exporterHandle])) {
58 throw new Exception("Invalid exporter handle: '$exporterHandle'");
59 }
60
61 return call_user_func(self::getExporterClassName($exporterHandle).'::getDescription');
62 }
68 final public static function getExporterClassName($exporterHandle)
69 {
70 return __NAMESPACE__.'\\'.ucfirst(strtolower($exporterHandle));
71 }
77 protected static function toStringDo($languages)
78 {
79 throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__);
80 }
86 final public static function toString($languages, $options = null)
87 {
88 if (isset($options) && is_array($options)) {
89 if (isset($options['us-ascii']) && $options['us-ascii']) {
90 $asciiList = array();
91 foreach ($languages as $language) {
92 $asciiList[] = $language->getUSAsciiClone();
93 }
94 $languages = $asciiList;
95 }
96 }
97
98 return static::toStringDo($languages);
99 }
105 final public static function toFile($languages, $filename, $options = null)
106 {
107 $data = self::toString($languages, $options);
108 if (@file_put_contents($filename, $data) === false) {
109 throw new Exception("Error writing data to '$filename'");
110 }
111 }
116 public static function isForPublicUse()
117 {
118 return true;
119 }
124 public static function getDescription()
125 {
126 throw new Exception(get_called_class().' does not implement the method '.__FUNCTION__);
127 }
128}
$result
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
Base class for all the exporters.
Definition: Exporter.php:11
static getExporters($onlyForPublicUse=false)
Return the list of all the available exporters.
Definition: Exporter.php:21
static isForPublicUse()
Is this exporter for public use?
Definition: Exporter.php:116
static getExporterClassName($exporterHandle)
Returns the fully qualified class name of a exporter given its handle.
Definition: Exporter.php:68
static toString($languages, $options=null)
Convert a list of Language instances to string.
Definition: Exporter.php:86
static toFile($languages, $filename, $options=null)
Save the Language instances to a file.
Definition: Exporter.php:105
static getDescription()
Return a short description of the exporter.
Definition: Exporter.php:124
static getExporterDescription($exporterHandle)
Return the description of a specific exporter.
Definition: Exporter.php:54
static toStringDo($languages)
Convert a list of Language instances to string.
Definition: Exporter.php:77
Main class to convert the plural rules of a language from CLDR to gettext.
Definition: Language.php:10