ConverterFactory Class Reference
[Lib]
Generic Converter Factory. More...
Static Public Member Functions |
|
static | create ($type) |
Create a converter for given type. |
|
static | create_chain ($arr_converters) |
Creates a chain of converters, that is a set
of converters that get executed one after the other. |
|
static | decode ($value, $type, $params=false) |
Decode teyt with converter of given type.
|
|
static | encode ($value, $type, $params=false) |
Encode teyt with converter of given type.
|
|
static | register_converter ($type, IConverter $converter) |
Register a converter. |
|
Public Attributes |
|
const | CALLBACK = 'callback' |
const | HTML = 'html' |
const | HTML_EX = 'htmlex' |
const | MIMEHEADER = 'mimeheader' |
const | NONE = 'none' |
Detailed Description
Generic Converter Factory.
Definition at line 8 of file converter.cls.php.
Member Function Documentation
static ConverterFactory::create | ( | $ | type | ) | [static] |
Create a converter for given type.
- Parameters:
-
string $type The type of converter to create
- Returns:
- IConverter
Definition at line 28 of file converter.cls.php.
00028 { 00029 $ret = false; 00030 switch ($type) { 00031 case self::HTML: 00032 require_once dirname(__FILE__) . '/converters/html.converter.php'; 00033 $ret = new ConverterHtml(); 00034 break; 00035 case self::HTML_EX: 00036 require_once dirname(__FILE__) . '/converters/htmlex.converter.php'; 00037 $ret = new ConverterHtmlEx(); 00038 break; 00039 case self::MIMEHEADER: 00040 require_once dirname(__FILE__) . '/converters/mimeheader.converter.php'; 00041 $ret = new ConverterMimeHeader(); 00042 break; 00043 case self::CALLBACK: 00044 require_once dirname(__FILE__) . '/converters/callback.converter.php'; 00045 $ret = new ConverterCallback(); 00046 break; 00047 case self::NONE: 00048 require_once dirname(__FILE__) . '/converters/none.converter.php'; 00049 $ret = new ConverterNone(); 00050 break; 00051 default: 00052 $ret = Arr::get_item(self::$registered_converters, $type, false); 00053 break; 00054 } 00055 return $ret; 00056 }
static ConverterFactory::create_chain | ( | $ | arr_converters | ) | [static] |
Creates a chain of converters, that is a set of converters that get executed one after the other.
- Since:
- 0.5.1
You may pass an array that contains either key-value pairs where the key is the name of a converter and the value is its parameters, or a simple array, whereas the value is the name of a converter or an instance of IConverter. This also can be mixed.
$chain = ConverterFactory::create_chain( ConverterFactory::HTML_EX => array('h' => 3), CONVERTER_TIDY, new FancyConverter('some', 'parameters') );
- Returns:
- IConverter
Definition at line 120 of file converter.cls.php.
00120 { 00121 require_once dirname(__FILE__) . '/converters/chain.converter.php'; 00122 $ret = new ConverterChain(); 00123 00124 foreach($arr_converters as $name_or_index => $params_or_name) { 00125 $converter = false; 00126 $params = false; 00127 if ($params_or_name instanceof IConverter) { 00128 $converter = $params_or_name; 00129 } 00130 else { 00131 $has_index = is_numeric($name_or_index); 00132 $name = ($has_index) ? $params_or_name : $name_or_index; 00133 $params = ($has_index) ? false : $params_or_name; 00134 00135 $converter = self::create($name); 00136 if (!$converter instanceof IConverter) { 00137 throw new Exception("Unknown Covnerter $name"); 00138 } 00139 } 00140 $ret->append($converter, $params); 00141 } 00142 00143 return $ret; 00144 }
static ConverterFactory::decode | ( | $ | value, | |
$ | type, | |||
$ | params = false |
|||
) | [static] |
Decode teyt with converter of given type.
- Parameters:
-
string $value Text to decode string $type Type of conversion
- Returns:
- string Converted text
Definition at line 80 of file converter.cls.php.
00080 { 00081 $converter = self::create($type); 00082 if ($converter) { 00083 return $converter->decode($value, $params); 00084 } 00085 return false; 00086 }
static ConverterFactory::encode | ( | $ | value, | |
$ | type, | |||
$ | params = false |
|||
) | [static] |
Encode teyt with converter of given type.
- Parameters:
-
string $value Text to encode string $type Type of conversion
- Returns:
- string Converted text
Definition at line 65 of file converter.cls.php.
00065 { 00066 $converter = self::create($type); 00067 if ($converter) { 00068 return $converter->encode($value, $params); 00069 } 00070 return false; 00071 }
static ConverterFactory::register_converter | ( | $ | type, | |
IConverter $ | converter | |||
) | [static] |
Register a converter.
- Parameters:
-
string $type Type of conversion IConverter $converter
- Returns:
- void
Definition at line 95 of file converter.cls.php.
Member Data Documentation
const ConverterFactory::CALLBACK = 'callback' |
Definition at line 11 of file converter.cls.php.
const ConverterFactory::HTML = 'html' |
Definition at line 9 of file converter.cls.php.
const ConverterFactory::HTML_EX = 'htmlex' |
Definition at line 10 of file converter.cls.php.
const ConverterFactory::MIMEHEADER = 'mimeheader' |
Definition at line 12 of file converter.cls.php.
const ConverterFactory::NONE = 'none' |
Definition at line 13 of file converter.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/lib/helpers/converter.cls.php