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:  CharacterStream implementation using an array in Swift Mailer.
  5: 
  6:  This program is free software: you can redistribute it and/or modify
  7:  it under the terms of the GNU General Public License as published by
  8:  the Free Software Foundation, either version 3 of the License, or
  9:  (at your option) any later version.
 10: 
 11:  This program is distributed in the hope that it will be useful,
 12:  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13:  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14:  GNU General Public License for more details.
 15: 
 16:  You should have received a copy of the GNU General Public License
 17:  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 18: 
 19:  */
 20: 
 21: /**
 22:  * A CharacterStream implementation which stores characters in an internal array.
 23:  * @package Swift
 24:  * @subpackage CharacterStream
 25:  * @author Xavier De Cock <xdecock@gmail.com>
 26:  */
 27: 
 28: class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
 29: {
 30:     /**
 31:      * The char reader (lazy-loaded) for the current charset.
 32:      * @var Swift_CharacterReader
 33:      * @access private
 34:      */
 35:     private $_charReader;
 36: 
 37:     /**
 38:      * A factory for creatiing CharacterReader instances.
 39:      * @var Swift_CharacterReaderFactory
 40:      * @access private
 41:      */
 42:     private $_charReaderFactory;
 43: 
 44:     /**
 45:      * The character set this stream is using.
 46:      * @var string
 47:      * @access private
 48:      */
 49:     private $_charset;
 50: 
 51:     /**
 52:      * The datas stored as is
 53:      *
 54:      * @var string
 55:      */
 56:     private $_datas = "";
 57: 
 58:     /**
 59:      * Number of bytes in the stream
 60:      *
 61:      * @var int
 62:      */
 63:     private $_datasSize = 0;
 64: 
 65:     /**
 66:      * Map
 67:      *
 68:      * @var mixed
 69:      */
 70:     private $_map;
 71: 
 72:     /**
 73:      * Map Type
 74:      *
 75:      * @var int
 76:      */
 77:     private $_mapType = 0;
 78: 
 79:     /**
 80:      * Number of characters in the stream
 81:      *
 82:      * @var int
 83:      */
 84:     private $_charCount = 0;
 85: 
 86:     /**
 87:      * Position in the stream
 88:      *
 89:      * @var unknown_type
 90:      */
 91:     private $_currentPos = 0;
 92: 
 93:     /**
 94:      * The constructor
 95:      *
 96:      * @param Swift_CharacterReaderFactory $factory
 97:      * @param unknown_type                 $charset
 98:      */
 99:     public function __construct(Swift_CharacterReaderFactory $factory, $charset)
100:     {
101:         $this->setCharacterReaderFactory($factory);
102:         $this->setCharacterSet($charset);
103:     }
104: 
105:     /* -- Changing parameters of the stream -- */
106: 
107:     /**
108:      * Set the character set used in this CharacterStream.
109:      * @param string $charset
110:      */
111:     public function setCharacterSet($charset)
112:     {
113:         $this->_charset = $charset;
114:         $this->_charReader = null;
115:         $this->_mapType = 0;
116:     }
117: 
118:     /**
119:      * Set the CharacterReaderFactory for multi charset support.
120:      * @param Swift_CharacterReaderFactory $factory
121:      */
122:     public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
123:     {
124:         $this->_charReaderFactory = $factory;
125:     }
126: 
127:     /**
128:      * @see Swift_CharacterStream::flushContents()
129:      *
130:      */
131:     public function flushContents()
132:     {
133:         $this->_datas = null;
134:         $this->_map = null;
135:         $this->_charCount = 0;
136:         $this->_currentPos = 0;
137:         $this->_datasSize = 0;
138:     }
139: 
140:     /**
141:      * @see Swift_CharacterStream::importByteStream()
142:      *
143:      * @param Swift_OutputByteStream $os
144:      */
145:     public function importByteStream(Swift_OutputByteStream $os)
146:     {
147:         $this->flushContents();
148:         $blocks=512;
149:         $os->setReadPointer(0);
150:         while(false!==($read = $os->read($blocks)))
151:             $this->write($read);
152:     }
153: 
154:     /**
155:      * @see Swift_CharacterStream::importString()
156:      *
157:      * @param string $string
158:      */
159:     public function importString($string)
160:     {
161:         $this->flushContents();
162:         $this->write($string);
163:     }
164: 
165:     /**
166:      * @see Swift_CharacterStream::read()
167:      *
168:      * @param  int    $length
169:      * @return string
170:      */
171:     public function read($length)
172:     {
173:         if ($this->_currentPos>=$this->_charCount) {
174:           return false;
175:         }
176:         $ret=false;
177:         $length = ($this->_currentPos+$length > $this->_charCount)
178:           ? $this->_charCount - $this->_currentPos
179:           : $length;
180:           switch ($this->_mapType) {
181:             case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
182:                 $len = $length*$this->_map;
183:                 $ret = substr($this->_datas,
184:                         $this->_currentPos * $this->_map,
185:                         $len);
186:                 $this->_currentPos += $length;
187:                 break;
188: 
189:             case Swift_CharacterReader::MAP_TYPE_INVALID:
190:                 $end = $this->_currentPos + $length;
191:                 $end = $end > $this->_charCount
192:                     ?$this->_charCount
193:                     :$end;
194:                 $ret = '';
195:                 for (; $this->_currentPos < $length; ++$this->_currentPos) {
196:                     if (isset ($this->_map[$this->_currentPos])) {
197:                         $ret .= '?';
198:                     } else {
199:                         $ret .= $this->_datas[$this->_currentPos];
200:                     }
201:                 }
202:                 break;
203: 
204:             case Swift_CharacterReader::MAP_TYPE_POSITIONS:
205:                 $end = $this->_currentPos + $length;
206:                 $end = $end > $this->_charCount
207:                     ?$this->_charCount
208:                     :$end;
209:                 $ret = '';
210:                 $start = 0;
211:                 if ($this->_currentPos>0) {
212:                     $start = $this->_map['p'][$this->_currentPos-1];
213:                 }
214:                 $to = $start;
215:                 for (; $this->_currentPos < $end; ++$this->_currentPos) {
216:                     if (isset($this->_map['i'][$this->_currentPos])) {
217:                         $ret .= substr($this->_datas, $start, $to - $start).'?';
218:                         $start = $this->_map['p'][$this->_currentPos];
219:                     } else {
220:                         $to = $this->_map['p'][$this->_currentPos];
221:                     }
222:                 }
223:                 $ret .= substr($this->_datas, $start, $to - $start);
224:                 break;
225:         }
226: 
227:         return $ret;
228:     }
229: 
230:     /**
231:      * @see Swift_CharacterStream::readBytes()
232:      *
233:      * @param  int   $length
234:      * @return int[]
235:      */
236:     public function readBytes($length)
237:     {
238:         $read=$this->read($length);
239:         if ($read!==false) {
240:             $ret = array_map('ord', str_split($read, 1));
241: 
242:             return $ret;
243:         }
244: 
245:         return false;
246:     }
247: 
248:     /**
249:      * @see Swift_CharacterStream::setPointer()
250:      *
251:      * @param int $charOffset
252:      */
253:     public function setPointer($charOffset)
254:     {
255:         if ($this->_charCount<$charOffset) {
256:             $charOffset=$this->_charCount;
257:         }
258:         $this->_currentPos = $charOffset;
259:     }
260: 
261:     /**
262:      * @see Swift_CharacterStream::write()
263:      *
264:      * @param string $chars
265:      */
266:     public function write($chars)
267:     {
268:         if (!isset($this->_charReader)) {
269:             $this->_charReader = $this->_charReaderFactory->getReaderFor(
270:                 $this->_charset);
271:             $this->_map = array();
272:             $this->_mapType = $this->_charReader->getMapType();
273:         }
274:         $ignored='';
275:         $this->_datas .= $chars;
276:         $this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
277:         if ($ignored!==false) {
278:             $this->_datasSize=strlen($this->_datas)-strlen($ignored);
279:         } else {
280:             $this->_datasSize=strlen($this->_datas);
281:         }
282:     }
283: }
284: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen