forked from Wavyzz/dolibarr
swiftmailer
This commit is contained in:
@@ -16,28 +16,28 @@
|
||||
class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream
|
||||
{
|
||||
/** A map of byte values and their respective characters */
|
||||
private static $_charMap;
|
||||
private static $charMap;
|
||||
|
||||
/** A map of characters and their derivative byte values */
|
||||
private static $_byteMap;
|
||||
private static $byteMap;
|
||||
|
||||
/** The char reader (lazy-loaded) for the current charset */
|
||||
private $_charReader;
|
||||
private $charReader;
|
||||
|
||||
/** A factory for creating CharacterReader instances */
|
||||
private $_charReaderFactory;
|
||||
private $charReaderFactory;
|
||||
|
||||
/** The character set this stream is using */
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/** Array of characters */
|
||||
private $_array = array();
|
||||
private $array = array();
|
||||
|
||||
/** Size of the array of character */
|
||||
private $_array_size = array();
|
||||
private $array_size = array();
|
||||
|
||||
/** The current character offset in the stream */
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Create a new CharacterStream with the given $chars, if set.
|
||||
@@ -47,7 +47,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function __construct(Swift_CharacterReaderFactory $factory, $charset)
|
||||
{
|
||||
self::_initializeMaps();
|
||||
self::initializeMaps();
|
||||
$this->setCharacterReaderFactory($factory);
|
||||
$this->setCharacterSet($charset);
|
||||
}
|
||||
@@ -59,8 +59,8 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setCharacterSet($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_charReader = null;
|
||||
$this->charset = $charset;
|
||||
$this->charReader = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
|
||||
{
|
||||
$this->_charReaderFactory = $factory;
|
||||
$this->charReaderFactory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,28 +80,28 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function importByteStream(Swift_OutputByteStream $os)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory
|
||||
->getReaderFor($this->_charset);
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory
|
||||
->getReaderFor($this->charset);
|
||||
}
|
||||
|
||||
$startLength = $this->_charReader->getInitialByteSize();
|
||||
$startLength = $this->charReader->getInitialByteSize();
|
||||
while (false !== $bytes = $os->read($startLength)) {
|
||||
$c = array();
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$c[] = self::$_byteMap[$bytes[$i]];
|
||||
$c[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
$size = count($c);
|
||||
$need = $this->_charReader
|
||||
$need = $this->charReader
|
||||
->validateByteSequence($c, $size);
|
||||
if ($need > 0 &&
|
||||
false !== $bytes = $os->read($need)) {
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$c[] = self::$_byteMap[$bytes[$i]];
|
||||
$c[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
}
|
||||
$this->_array[] = $c;
|
||||
++$this->_array_size;
|
||||
$this->array[] = $c;
|
||||
++$this->array_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,20 +127,20 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_offset == $this->_array_size) {
|
||||
if ($this->offset == $this->array_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use array slice
|
||||
$arrays = array();
|
||||
$end = $length + $this->_offset;
|
||||
for ($i = $this->_offset; $i < $end; ++$i) {
|
||||
if (!isset($this->_array[$i])) {
|
||||
$end = $length + $this->offset;
|
||||
for ($i = $this->offset; $i < $end; ++$i) {
|
||||
if (!isset($this->array[$i])) {
|
||||
break;
|
||||
}
|
||||
$arrays[] = $this->_array[$i];
|
||||
$arrays[] = $this->array[$i];
|
||||
}
|
||||
$this->_offset += $i - $this->_offset; // Limit function calls
|
||||
$this->offset += $i - $this->offset; // Limit function calls
|
||||
$chars = false;
|
||||
foreach ($arrays as $array) {
|
||||
$chars .= implode('', array_map('chr', $array));
|
||||
@@ -155,24 +155,24 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
if ($this->_offset == $this->_array_size) {
|
||||
if ($this->offset == $this->array_size) {
|
||||
return false;
|
||||
}
|
||||
$arrays = array();
|
||||
$end = $length + $this->_offset;
|
||||
for ($i = $this->_offset; $i < $end; ++$i) {
|
||||
if (!isset($this->_array[$i])) {
|
||||
$end = $length + $this->offset;
|
||||
for ($i = $this->offset; $i < $end; ++$i) {
|
||||
if (!isset($this->array[$i])) {
|
||||
break;
|
||||
}
|
||||
$arrays[] = $this->_array[$i];
|
||||
$arrays[] = $this->array[$i];
|
||||
}
|
||||
$this->_offset += ($i - $this->_offset); // Limit function calls
|
||||
$this->offset += ($i - $this->offset); // Limit function calls
|
||||
|
||||
return call_user_func_array('array_merge', $arrays);
|
||||
return array_merge(...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,12 +182,12 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function write($chars)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory->getReaderFor(
|
||||
$this->_charset);
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory->getReaderFor(
|
||||
$this->charset);
|
||||
}
|
||||
|
||||
$startLength = $this->_charReader->getInitialByteSize();
|
||||
$startLength = $this->charReader->getInitialByteSize();
|
||||
|
||||
$fp = fopen('php://memory', 'w+b');
|
||||
fwrite($fp, $chars);
|
||||
@@ -203,7 +203,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
// Buffer Filing
|
||||
if ($buf_len - $buf_pos < $startLength) {
|
||||
$buf = array_splice($buffer, $buf_pos);
|
||||
$new = $this->_reloadBuffer($fp, 100);
|
||||
$new = $this->reloadBuffer($fp, 100);
|
||||
if ($new) {
|
||||
$buffer = array_merge($buf, $new);
|
||||
$buf_len = count($buffer);
|
||||
@@ -218,11 +218,11 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
++$size;
|
||||
$bytes[] = $buffer[$buf_pos++];
|
||||
}
|
||||
$need = $this->_charReader->validateByteSequence(
|
||||
$need = $this->charReader->validateByteSequence(
|
||||
$bytes, $size);
|
||||
if ($need > 0) {
|
||||
if ($buf_len - $buf_pos < $need) {
|
||||
$new = $this->_reloadBuffer($fp, $need);
|
||||
$new = $this->reloadBuffer($fp, $need);
|
||||
|
||||
if ($new) {
|
||||
$buffer = array_merge($buffer, $new);
|
||||
@@ -233,8 +233,8 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
$bytes[] = $buffer[$buf_pos++];
|
||||
}
|
||||
}
|
||||
$this->_array[] = $bytes;
|
||||
++$this->_array_size;
|
||||
$this->array[] = $bytes;
|
||||
++$this->array_size;
|
||||
}
|
||||
} while ($has_datas);
|
||||
|
||||
@@ -248,12 +248,12 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function setPointer($charOffset)
|
||||
{
|
||||
if ($charOffset > $this->_array_size) {
|
||||
$charOffset = $this->_array_size;
|
||||
if ($charOffset > $this->array_size) {
|
||||
$charOffset = $this->array_size;
|
||||
} elseif ($charOffset < 0) {
|
||||
$charOffset = 0;
|
||||
}
|
||||
$this->_offset = $charOffset;
|
||||
$this->offset = $charOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,17 +261,17 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
*/
|
||||
public function flushContents()
|
||||
{
|
||||
$this->_offset = 0;
|
||||
$this->_array = array();
|
||||
$this->_array_size = 0;
|
||||
$this->offset = 0;
|
||||
$this->array = array();
|
||||
$this->array_size = 0;
|
||||
}
|
||||
|
||||
private function _reloadBuffer($fp, $len)
|
||||
private function reloadBuffer($fp, $len)
|
||||
{
|
||||
if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) {
|
||||
$buf = array();
|
||||
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
|
||||
$buf[] = self::$_byteMap[$bytes[$i]];
|
||||
$buf[] = self::$byteMap[$bytes[$i]];
|
||||
}
|
||||
|
||||
return $buf;
|
||||
@@ -280,14 +280,14 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function _initializeMaps()
|
||||
private static function initializeMaps()
|
||||
{
|
||||
if (!isset(self::$_charMap)) {
|
||||
self::$_charMap = array();
|
||||
if (!isset(self::$charMap)) {
|
||||
self::$charMap = array();
|
||||
for ($byte = 0; $byte < 256; ++$byte) {
|
||||
self::$_charMap[$byte] = chr($byte);
|
||||
self::$charMap[$byte] = chr($byte);
|
||||
}
|
||||
self::$_byteMap = array_flip(self::$_charMap);
|
||||
self::$byteMap = array_flip(self::$charMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
/**
|
||||
* A CharacterStream implementation which stores characters in an internal array.
|
||||
*
|
||||
* @author Xavier De Cock <xdecock@gmail.com>
|
||||
* @author Xavier De Cock <xdecock@gmail.com>
|
||||
*/
|
||||
class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
{
|
||||
@@ -20,63 +20,63 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*
|
||||
* @var Swift_CharacterReader
|
||||
*/
|
||||
private $_charReader;
|
||||
private $charReader;
|
||||
|
||||
/**
|
||||
* A factory for creating CharacterReader instances.
|
||||
*
|
||||
* @var Swift_CharacterReaderFactory
|
||||
*/
|
||||
private $_charReaderFactory;
|
||||
private $charReaderFactory;
|
||||
|
||||
/**
|
||||
* The character set this stream is using.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* The data's stored as-is.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_datas = '';
|
||||
private $datas = '';
|
||||
|
||||
/**
|
||||
* Number of bytes in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_datasSize = 0;
|
||||
private $datasSize = 0;
|
||||
|
||||
/**
|
||||
* Map.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_map;
|
||||
private $map;
|
||||
|
||||
/**
|
||||
* Map Type.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_mapType = 0;
|
||||
private $mapType = 0;
|
||||
|
||||
/**
|
||||
* Number of characters in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_charCount = 0;
|
||||
private $charCount = 0;
|
||||
|
||||
/**
|
||||
* Position in the stream.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_currentPos = 0;
|
||||
private $currentPos = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -99,9 +99,9 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setCharacterSet($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_charReader = null;
|
||||
$this->_mapType = 0;
|
||||
$this->charset = $charset;
|
||||
$this->charReader = null;
|
||||
$this->mapType = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +111,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory)
|
||||
{
|
||||
$this->_charReaderFactory = $factory;
|
||||
$this->charReaderFactory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,11 +119,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function flushContents()
|
||||
{
|
||||
$this->_datas = null;
|
||||
$this->_map = null;
|
||||
$this->_charCount = 0;
|
||||
$this->_currentPos = 0;
|
||||
$this->_datasSize = 0;
|
||||
$this->datas = null;
|
||||
$this->map = null;
|
||||
$this->charCount = 0;
|
||||
$this->currentPos = 0;
|
||||
$this->datasSize = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,49 +161,49 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_currentPos >= $this->_charCount) {
|
||||
if ($this->currentPos >= $this->charCount) {
|
||||
return false;
|
||||
}
|
||||
$ret = false;
|
||||
$length = $this->_currentPos + $length > $this->_charCount ? $this->_charCount - $this->_currentPos : $length;
|
||||
switch ($this->_mapType) {
|
||||
$length = ($this->currentPos + $length > $this->charCount) ? $this->charCount - $this->currentPos : $length;
|
||||
switch ($this->mapType) {
|
||||
case Swift_CharacterReader::MAP_TYPE_FIXED_LEN:
|
||||
$len = $length * $this->_map;
|
||||
$ret = substr($this->_datas,
|
||||
$this->_currentPos * $this->_map,
|
||||
$len = $length * $this->map;
|
||||
$ret = substr($this->datas,
|
||||
$this->currentPos * $this->map,
|
||||
$len);
|
||||
$this->_currentPos += $length;
|
||||
$this->currentPos += $length;
|
||||
break;
|
||||
|
||||
case Swift_CharacterReader::MAP_TYPE_INVALID:
|
||||
$ret = '';
|
||||
for (; $this->_currentPos < $length; ++$this->_currentPos) {
|
||||
if (isset($this->_map[$this->_currentPos])) {
|
||||
for (; $this->currentPos < $length; ++$this->currentPos) {
|
||||
if (isset($this->map[$this->currentPos])) {
|
||||
$ret .= '?';
|
||||
} else {
|
||||
$ret .= $this->_datas[$this->_currentPos];
|
||||
$ret .= $this->datas[$this->currentPos];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Swift_CharacterReader::MAP_TYPE_POSITIONS:
|
||||
$end = $this->_currentPos + $length;
|
||||
$end = $end > $this->_charCount ? $this->_charCount : $end;
|
||||
$end = $this->currentPos + $length;
|
||||
$end = $end > $this->charCount ? $this->charCount : $end;
|
||||
$ret = '';
|
||||
$start = 0;
|
||||
if ($this->_currentPos > 0) {
|
||||
$start = $this->_map['p'][$this->_currentPos - 1];
|
||||
if ($this->currentPos > 0) {
|
||||
$start = $this->map['p'][$this->currentPos - 1];
|
||||
}
|
||||
$to = $start;
|
||||
for (; $this->_currentPos < $end; ++$this->_currentPos) {
|
||||
if (isset($this->_map['i'][$this->_currentPos])) {
|
||||
$ret .= substr($this->_datas, $start, $to - $start).'?';
|
||||
$start = $this->_map['p'][$this->_currentPos];
|
||||
for (; $this->currentPos < $end; ++$this->currentPos) {
|
||||
if (isset($this->map['i'][$this->currentPos])) {
|
||||
$ret .= substr($this->datas, $start, $to - $start).'?';
|
||||
$start = $this->map['p'][$this->currentPos];
|
||||
} else {
|
||||
$to = $this->_map['p'][$this->_currentPos];
|
||||
$to = $this->map['p'][$this->currentPos];
|
||||
}
|
||||
}
|
||||
$ret .= substr($this->_datas, $start, $to - $start);
|
||||
$ret .= substr($this->datas, $start, $to - $start);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return integer[]
|
||||
* @return int[]
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
@@ -236,10 +236,10 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function setPointer($charOffset)
|
||||
{
|
||||
if ($this->_charCount < $charOffset) {
|
||||
$charOffset = $this->_charCount;
|
||||
if ($this->charCount < $charOffset) {
|
||||
$charOffset = $this->charCount;
|
||||
}
|
||||
$this->_currentPos = $charOffset;
|
||||
$this->currentPos = $charOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,19 +249,19 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream
|
||||
*/
|
||||
public function write($chars)
|
||||
{
|
||||
if (!isset($this->_charReader)) {
|
||||
$this->_charReader = $this->_charReaderFactory->getReaderFor(
|
||||
$this->_charset);
|
||||
$this->_map = array();
|
||||
$this->_mapType = $this->_charReader->getMapType();
|
||||
if (!isset($this->charReader)) {
|
||||
$this->charReader = $this->charReaderFactory->getReaderFor(
|
||||
$this->charset);
|
||||
$this->map = array();
|
||||
$this->mapType = $this->charReader->getMapType();
|
||||
}
|
||||
$ignored = '';
|
||||
$this->_datas .= $chars;
|
||||
$this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored);
|
||||
$this->datas .= $chars;
|
||||
$this->charCount += $this->charReader->getCharPositions(substr($this->datas, $this->datasSize), $this->datasSize, $this->map, $ignored);
|
||||
if ($ignored !== false) {
|
||||
$this->_datasSize = strlen($this->_datas) - strlen($ignored);
|
||||
$this->datasSize = strlen($this->datas) - strlen($ignored);
|
||||
} else {
|
||||
$this->_datasSize = strlen($this->_datas);
|
||||
$this->datasSize = strlen($this->datas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user