Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /*
  4:  * This file is part of SwiftMailer.
  5:  * (c) 2004-2009 Chris Corbyn
  6:  *
  7:  * For the full copyright and license information, please view the LICENSE
  8:  * file that was distributed with this source code.
  9:  */
 10: 
 11: /**
 12:  * A CharacterStream implementation which stores characters in an internal array.
 13:  * @package Swift
 14:  * @subpackage CharacterStream
 15:  * @author Chris Corbyn
 16:  */
 17: class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream
 18: {
 19:     /** A map of byte values and their respective characters */
 20:     private static $_charMap;
 21: 
 22:     /** A map of characters and their derivative byte values */
 23:     private static $_byteMap;
 24: 
 25:     /** The char reader (lazy-loaded) for the current charset */
 26:     private $_charReader;
 27: 
 28:     /** A factory for creatiing CharacterReader instances */
 29:     private $_charReaderFactory;
 30: 
 31:     /** The character set this stream is using */
 32:     private $_charset;
 33: 
 34:     /** Array of characters */
 35:     private $_array = array();
 36: 
 37:     /** Size of the array of character */
 38:     private $_array_size = array();
 39: 
 40:     /** The current character offset in the stream */
 41:     private $_offset = 0;
 42: 
 43:     /**
 44:      * Create a new CharacterStream with the given $chars, if set.
 45:      * @param Swift_CharacterReaderFactory $factory for loading validators
 46:      * @param string                       $charset used in the stream
 47:      */
 48:     public function __construct(Swift_CharacterReaderFactory $factory, $charset)
 49:     {
 50:         self::_initializeMaps();
 51:         $this->setCharacterReaderFactory($factory);
 52:         $this->setCharacterSet($charset);
 53:     }
 54: 
 55:     /**
 56:      * Set the character set used in this CharacterStream.
 57:      * @param string $charset
 58:      */
 59:     public function setCharacterSet($charset)
 60:     {
 61:         $this->_charset = $charset;
 62:         $this->_charReader = null;
 63:     }
 64: 
 65:     /**
 66:      * Set the CharacterReaderFactory for multi charset support.
 67:      * @param Swift_CharacterReaderFactory $factory
 68:      */
 69:     public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
 70:     {
 71:         $this->_charReaderFactory = $factory;
 72:     }
 73: 
 74:     /**
 75:      * Overwrite this character stream using the byte sequence in the byte stream.
 76:      * @param Swift_OutputByteStream $os output stream to read from
 77:      */
 78:     public function importByteStream(Swift_OutputByteStream $os)
 79:     {
 80:         if (!isset($this->_charReader)) {
 81:             $this->_charReader = $this->_charReaderFactory
 82:                 ->getReaderFor($this->_charset);
 83:         }
 84: 
 85:         $startLength = $this->_charReader->getInitialByteSize();
 86:         while (false !== $bytes = $os->read($startLength)) {
 87:             $c = array();
 88:             for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
 89:                 $c[] = self::$_byteMap[$bytes[$i]];
 90:             }
 91:             $size = count($c);
 92:             $need = $this->_charReader
 93:                 ->validateByteSequence($c, $size);
 94:             if ($need > 0 &&
 95:                 false !== $bytes = $os->read($need))
 96:             {
 97:                 for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
 98:                     $c[] = self::$_byteMap[$bytes[$i]];
 99:                 }
100:             }
101:             $this->_array[] = $c;
102:             ++$this->_array_size;
103:         }
104:     }
105: 
106:     /**
107:      * Import a string a bytes into this CharacterStream, overwriting any existing
108:      * data in the stream.
109:      * @param string $string
110:      */
111:     public function importString($string)
112:     {
113:         $this->flushContents();
114:         $this->write($string);
115:     }
116: 
117:     /**
118:      * Read $length characters from the stream and move the internal pointer
119:      * $length further into the stream.
120:      * @param  int    $length
121:      * @return string
122:      */
123:     public function read($length)
124:     {
125:         if ($this->_offset == $this->_array_size) {
126:             return false;
127:         }
128: 
129:         // Don't use array slice
130:         $arrays = array();
131:         $end = $length + $this->_offset;
132:         for ($i = $this->_offset; $i < $end; ++$i) {
133:             if (!isset($this->_array[$i])) {
134:                 break;
135:             }
136:             $arrays[] = $this->_array[$i];
137:         }
138:         $this->_offset += $i - $this->_offset; // Limit function calls
139:         $chars = false;
140:         foreach ($arrays as $array) {
141:             $chars .= implode('', array_map('chr', $array));
142:         }
143: 
144:         return $chars;
145:     }
146: 
147:     /**
148:      * Read $length characters from the stream and return a 1-dimensional array
149:      * containing there octet values.
150:      * @param  int   $length
151:      * @return int[]
152:      */
153:     public function readBytes($length)
154:     {
155:         if ($this->_offset == $this->_array_size) {
156:             return false;
157:         }
158:         $arrays = array();
159:         $end = $length + $this->_offset;
160:         for ($i = $this->_offset; $i < $end; ++$i) {
161:             if (!isset($this->_array[$i])) {
162:                 break;
163:             }
164:             $arrays[] = $this->_array[$i];
165:         }
166:         $this->_offset += ($i - $this->_offset); // Limit function calls
167: 
168:         return call_user_func_array('array_merge', $arrays);
169:     }
170: 
171:     /**
172:      * Write $chars to the end of the stream.
173:      * @param string $chars
174:      */
175:     public function write($chars)
176:     {
177:         if (!isset($this->_charReader)) {
178:             $this->_charReader = $this->_charReaderFactory->getReaderFor(
179:                 $this->_charset);
180:         }
181: 
182:         $startLength = $this->_charReader->getInitialByteSize();
183: 
184:         $fp = fopen('php://memory', 'w+b');
185:         fwrite($fp, $chars);
186:         unset($chars);
187:         fseek($fp, 0, SEEK_SET);
188: 
189:         $buffer = array(0);
190:         $buf_pos = 1;
191:         $buf_len = 1;
192:         $has_datas = true;
193:         do {
194:             $bytes = array();
195:             // Buffer Filing
196:             if ($buf_len - $buf_pos < $startLength) {
197:                 $buf = array_splice($buffer, $buf_pos);
198:                 $new = $this->_reloadBuffer($fp, 100);
199:                 if ($new) {
200:                     $buffer = array_merge($buf, $new);
201:                     $buf_len = count($buffer);
202:                     $buf_pos = 0;
203:                 } else {
204:                     $has_datas = false;
205:                 }
206:             }
207:             if ($buf_len - $buf_pos > 0) {
208:                 $size = 0;
209:                 for ($i = 0; $i < $startLength && isset($buffer[$buf_pos]); ++$i) {
210:                     ++$size;
211:                     $bytes[] = $buffer[$buf_pos++];
212:                 }
213:                 $need = $this->_charReader->validateByteSequence(
214:                     $bytes, $size);
215:                 if ($need > 0) {
216:                     if ($buf_len - $buf_pos < $need) {
217:                         $new = $this->_reloadBuffer($fp, $need);
218: 
219:                         if ($new) {
220:                             $buffer = array_merge($buffer, $new);
221:                             $buf_len = count($buffer);
222:                         }
223:                     }
224:                     for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) {
225:                         $bytes[] = $buffer[$buf_pos++];
226:                     }
227:                 }
228:                 $this->_array[] = $bytes;
229:                 ++$this->_array_size;
230:             }
231:         } while ($has_datas);
232: 
233:         fclose($fp);
234:     }
235: 
236:     /**
237:      * Move the internal pointer to $charOffset in the stream.
238:      * @param int $charOffset
239:      */
240:     public function setPointer($charOffset)
241:     {
242:         if ($charOffset > $this->_array_size) {
243:             $charOffset = $this->_array_size;
244:         } elseif ($charOffset < 0) {
245:             $charOffset = 0;
246:         }
247:         $this->_offset = $charOffset;
248:     }
249: 
250:     /**
251:      * Empty the stream and reset the internal pointer.
252:      */
253:     public function flushContents()
254:     {
255:         $this->_offset = 0;
256:         $this->_array = array();
257:         $this->_array_size = 0;
258:     }
259: 
260:     private function _reloadBuffer($fp, $len)
261:     {
262:         if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) {
263:             $buf = array();
264:             for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
265:                 $buf[] = self::$_byteMap[$bytes[$i]];
266:             }
267: 
268:             return $buf;
269:         }
270: 
271:         return false;
272:     }
273: 
274:     private static function _initializeMaps()
275:     {
276:         if (!isset(self::$_charMap)) {
277:             self::$_charMap = array();
278:             for ($byte = 0; $byte < 256; ++$byte) {
279:                 self::$_charMap[$byte] = chr($byte);
280:             }
281:             self::$_byteMap = array_flip(self::$_charMap);
282:         }
283:     }
284: }
285: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen