1: <?php
2:
3: 4: 5: 6: 7: 8: 9:
10:
11: 12: 13: 14: 15: 16:
17: class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift_CharacterReaderFactory
18: {
19: 20: 21: 22: 23:
24: private static $_map = array();
25:
26: 27: 28: 29: 30:
31: private static $_loaded = array();
32:
33: 34: 35:
36: public function __construct()
37: {
38: $this->init();
39: }
40:
41: public function __wakeup()
42: {
43: $this->init();
44: }
45:
46: public function init()
47: {
48: if (count(self::$_map) > 0) {
49: return;
50: }
51:
52: $prefix = 'Swift_CharacterReader_';
53:
54: $singleByte = array(
55: 'class' => $prefix . 'GenericFixedWidthReader',
56: 'constructor' => array(1)
57: );
58:
59: $doubleByte = array(
60: 'class' => $prefix . 'GenericFixedWidthReader',
61: 'constructor' => array(2)
62: );
63:
64: $fourBytes = array(
65: 'class' => $prefix . 'GenericFixedWidthReader',
66: 'constructor' => array(4)
67: );
68:
69:
70: self::$_map['utf-?8'] = array(
71: 'class' => $prefix . 'Utf8Reader',
72: 'constructor' => array()
73: );
74:
75:
76: self::$_map['(us-)?ascii'] = $singleByte;
77: self::$_map['(iso|iec)-?8859-?[0-9]+'] = $singleByte;
78: self::$_map['windows-?125[0-9]'] = $singleByte;
79: self::$_map['cp-?[0-9]+'] = $singleByte;
80: self::$_map['ansi'] = $singleByte;
81: self::$_map['macintosh'] = $singleByte;
82: self::$_map['koi-?7'] = $singleByte;
83: self::$_map['koi-?8-?.+'] = $singleByte;
84: self::$_map['mik'] = $singleByte;
85: self::$_map['(cork|t1)'] = $singleByte;
86: self::$_map['v?iscii'] = $singleByte;
87:
88:
89: self::$_map['(ucs-?2|utf-?16)'] = $doubleByte;
90:
91:
92: self::$_map['(ucs-?4|utf-?32)'] = $fourBytes;
93:
94:
95: self::$_map['.*'] = $singleByte;
96: }
97:
98: 99: 100: 101: 102:
103: public function getReaderFor($charset)
104: {
105: $charset = trim(strtolower($charset));
106: foreach (self::$_map as $pattern => $spec) {
107: $re = '/^' . $pattern . '$/D';
108: if (preg_match($re, $charset)) {
109: if (!array_key_exists($pattern, self::$_loaded)) {
110: $reflector = new ReflectionClass($spec['class']);
111: if ($reflector->getConstructor()) {
112: $reader = $reflector->newInstanceArgs($spec['constructor']);
113: } else {
114: $reader = $reflector->newInstance();
115: }
116: self::$_loaded[$pattern] = $reader;
117: }
118:
119: return self::$_loaded[$pattern];
120: }
121: }
122: }
123: }
124: