mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-09 19:18:22 +01:00
swiftmailer
This commit is contained in:
@@ -18,38 +18,38 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
/**
|
||||
* Write sequence.
|
||||
*/
|
||||
protected $_sequence = 0;
|
||||
protected $sequence = 0;
|
||||
|
||||
/**
|
||||
* StreamFilters.
|
||||
*
|
||||
* @var Swift_StreamFilter[]
|
||||
*/
|
||||
private $_filters = array();
|
||||
private $filters = array();
|
||||
|
||||
/**
|
||||
* A buffer for writing.
|
||||
*/
|
||||
private $_writeBuffer = '';
|
||||
private $writeBuffer = '';
|
||||
|
||||
/**
|
||||
* Bound streams.
|
||||
*
|
||||
* @var Swift_InputByteStream[]
|
||||
*/
|
||||
private $_mirrors = array();
|
||||
private $mirrors = array();
|
||||
|
||||
/**
|
||||
* Commit the given bytes to the storage medium immediately.
|
||||
*
|
||||
* @param string $bytes
|
||||
*/
|
||||
abstract protected function _commit($bytes);
|
||||
abstract protected function doCommit($bytes);
|
||||
|
||||
/**
|
||||
* Flush any buffers/content with immediate effect.
|
||||
*/
|
||||
abstract protected function _flush();
|
||||
abstract protected function flush();
|
||||
|
||||
/**
|
||||
* Add a StreamFilter to this InputByteStream.
|
||||
@@ -59,7 +59,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function addFilter(Swift_StreamFilter $filter, $key)
|
||||
{
|
||||
$this->_filters[$key] = $filter;
|
||||
$this->filters[$key] = $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function removeFilter($key)
|
||||
{
|
||||
unset($this->_filters[$key]);
|
||||
unset($this->filters[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,15 +83,15 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function write($bytes)
|
||||
{
|
||||
$this->_writeBuffer .= $bytes;
|
||||
foreach ($this->_filters as $filter) {
|
||||
if ($filter->shouldBuffer($this->_writeBuffer)) {
|
||||
$this->writeBuffer .= $bytes;
|
||||
foreach ($this->filters as $filter) {
|
||||
if ($filter->shouldBuffer($this->writeBuffer)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
$this->doWrite($this->writeBuffer);
|
||||
|
||||
return ++$this->_sequence;
|
||||
return ++$this->sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function commit()
|
||||
{
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
$this->doWrite($this->writeBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function bind(Swift_InputByteStream $is)
|
||||
{
|
||||
$this->_mirrors[] = $is;
|
||||
$this->mirrors[] = $is;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,12 +129,12 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function unbind(Swift_InputByteStream $is)
|
||||
{
|
||||
foreach ($this->_mirrors as $k => $stream) {
|
||||
foreach ($this->mirrors as $k => $stream) {
|
||||
if ($is === $stream) {
|
||||
if ($this->_writeBuffer !== '') {
|
||||
$stream->write($this->_writeBuffer);
|
||||
if ($this->writeBuffer !== '') {
|
||||
$stream->write($this->writeBuffer);
|
||||
}
|
||||
unset($this->_mirrors[$k]);
|
||||
unset($this->mirrors[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,20 +147,20 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
*/
|
||||
public function flushBuffers()
|
||||
{
|
||||
if ($this->_writeBuffer !== '') {
|
||||
$this->_doWrite($this->_writeBuffer);
|
||||
if ($this->writeBuffer !== '') {
|
||||
$this->doWrite($this->writeBuffer);
|
||||
}
|
||||
$this->_flush();
|
||||
$this->flush();
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->flushBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
/** Run $bytes through all filters */
|
||||
private function _filter($bytes)
|
||||
private function filter($bytes)
|
||||
{
|
||||
foreach ($this->_filters as $filter) {
|
||||
foreach ($this->filters as $filter) {
|
||||
$bytes = $filter->filter($bytes);
|
||||
}
|
||||
|
||||
@@ -168,14 +168,14 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I
|
||||
}
|
||||
|
||||
/** Just write the bytes to the stream */
|
||||
private function _doWrite($bytes)
|
||||
private function doWrite($bytes)
|
||||
{
|
||||
$this->_commit($this->_filter($bytes));
|
||||
$this->doCommit($this->filter($bytes));
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->write($bytes);
|
||||
}
|
||||
|
||||
$this->_writeBuffer = '';
|
||||
$this->writeBuffer = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
/**
|
||||
* Allows reading and writing of bytes to and from an array.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_OutputByteStream
|
||||
{
|
||||
@@ -20,28 +20,28 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_array = array();
|
||||
private $array = array();
|
||||
|
||||
/**
|
||||
* The size of the stack.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_arraySize = 0;
|
||||
private $arraySize = 0;
|
||||
|
||||
/**
|
||||
* The internal pointer offset.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/**
|
||||
* Bound streams.
|
||||
*
|
||||
* @var Swift_InputByteStream[]
|
||||
*/
|
||||
private $_mirrors = array();
|
||||
private $mirrors = array();
|
||||
|
||||
/**
|
||||
* Create a new ArrayByteStream.
|
||||
@@ -53,12 +53,12 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
public function __construct($stack = null)
|
||||
{
|
||||
if (is_array($stack)) {
|
||||
$this->_array = $stack;
|
||||
$this->_arraySize = count($stack);
|
||||
$this->array = $stack;
|
||||
$this->arraySize = count($stack);
|
||||
} elseif (is_string($stack)) {
|
||||
$this->write($stack);
|
||||
} else {
|
||||
$this->_array = array();
|
||||
$this->array = array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +76,16 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
if ($this->_offset == $this->_arraySize) {
|
||||
if ($this->offset == $this->arraySize) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't use array slice
|
||||
$end = $length + $this->_offset;
|
||||
$end = $this->_arraySize < $end ? $this->_arraySize : $end;
|
||||
$end = $length + $this->offset;
|
||||
$end = $this->arraySize < $end ? $this->arraySize : $end;
|
||||
$ret = '';
|
||||
for (; $this->_offset < $end; ++$this->_offset) {
|
||||
$ret .= $this->_array[$this->_offset];
|
||||
for (; $this->offset < $end; ++$this->offset) {
|
||||
$ret .= $this->array[$this->offset];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
@@ -100,11 +100,11 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
{
|
||||
$to_add = str_split($bytes);
|
||||
foreach ($to_add as $value) {
|
||||
$this->_array[] = $value;
|
||||
$this->array[] = $value;
|
||||
}
|
||||
$this->_arraySize = count($this->_array);
|
||||
$this->arraySize = count($this->array);
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->write($bytes);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function bind(Swift_InputByteStream $is)
|
||||
{
|
||||
$this->_mirrors[] = $is;
|
||||
$this->mirrors[] = $is;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,9 +140,9 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function unbind(Swift_InputByteStream $is)
|
||||
{
|
||||
foreach ($this->_mirrors as $k => $stream) {
|
||||
foreach ($this->mirrors as $k => $stream) {
|
||||
if ($is === $stream) {
|
||||
unset($this->_mirrors[$k]);
|
||||
unset($this->mirrors[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,13 +156,13 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function setReadPointer($byteOffset)
|
||||
{
|
||||
if ($byteOffset > $this->_arraySize) {
|
||||
$byteOffset = $this->_arraySize;
|
||||
if ($byteOffset > $this->arraySize) {
|
||||
$byteOffset = $this->arraySize;
|
||||
} elseif ($byteOffset < 0) {
|
||||
$byteOffset = 0;
|
||||
}
|
||||
|
||||
$this->_offset = $byteOffset;
|
||||
$this->offset = $byteOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,11 +171,11 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
|
||||
*/
|
||||
public function flushBuffers()
|
||||
{
|
||||
$this->_offset = 0;
|
||||
$this->_array = array();
|
||||
$this->_arraySize = 0;
|
||||
$this->offset = 0;
|
||||
$this->array = array();
|
||||
$this->arraySize = 0;
|
||||
|
||||
foreach ($this->_mirrors as $stream) {
|
||||
foreach ($this->mirrors as $stream) {
|
||||
$stream->flushBuffers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,30 +11,27 @@
|
||||
/**
|
||||
* Allows reading and writing of bytes to and from a file.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream
|
||||
{
|
||||
/** The internal pointer offset */
|
||||
private $_offset = 0;
|
||||
private $offset = 0;
|
||||
|
||||
/** The path to the file */
|
||||
private $_path;
|
||||
private $path;
|
||||
|
||||
/** The mode this file is opened in for writing */
|
||||
private $_mode;
|
||||
private $mode;
|
||||
|
||||
/** A lazy-loaded resource handle for reading the file */
|
||||
private $_reader;
|
||||
private $reader;
|
||||
|
||||
/** A lazy-loaded resource handle for writing the file */
|
||||
private $_writer;
|
||||
|
||||
/** If magic_quotes_runtime is on, this will be true */
|
||||
private $_quotes = false;
|
||||
private $writer;
|
||||
|
||||
/** If stream is seekable true/false, or null if not known */
|
||||
private $_seekable = null;
|
||||
private $seekable = null;
|
||||
|
||||
/**
|
||||
* Create a new FileByteStream for $path.
|
||||
@@ -47,12 +44,8 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
if (empty($path)) {
|
||||
throw new Swift_IoException('The path cannot be empty');
|
||||
}
|
||||
$this->_path = $path;
|
||||
$this->_mode = $writable ? 'w+b' : 'rb';
|
||||
|
||||
if (function_exists('get_magic_quotes_runtime') && @get_magic_quotes_runtime() == 1) {
|
||||
$this->_quotes = true;
|
||||
}
|
||||
$this->path = $path;
|
||||
$this->mode = $writable ? 'w+b' : 'rb';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +55,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,27 +68,21 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @throws Swift_IoException
|
||||
*
|
||||
* @return string|bool
|
||||
*
|
||||
* @throws Swift_IoException
|
||||
*/
|
||||
public function read($length)
|
||||
{
|
||||
$fp = $this->_getReadHandle();
|
||||
$fp = $this->getReadHandle();
|
||||
if (!feof($fp)) {
|
||||
if ($this->_quotes) {
|
||||
ini_set('magic_quotes_runtime', 0);
|
||||
}
|
||||
$bytes = fread($fp, $length);
|
||||
if ($this->_quotes) {
|
||||
ini_set('magic_quotes_runtime', 1);
|
||||
}
|
||||
$this->_offset = ftell($fp);
|
||||
$this->offset = ftell($fp);
|
||||
|
||||
// If we read one byte after reaching the end of the file
|
||||
// feof() will return false and an empty string is returned
|
||||
if ($bytes === '' && feof($fp)) {
|
||||
$this->_resetReadHandle();
|
||||
$this->resetReadHandle();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -103,7 +90,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
$this->_resetReadHandle();
|
||||
$this->resetReadHandle();
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -117,93 +104,93 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
*/
|
||||
public function setReadPointer($byteOffset)
|
||||
{
|
||||
if (isset($this->_reader)) {
|
||||
$this->_seekReadStreamToPosition($byteOffset);
|
||||
if (isset($this->reader)) {
|
||||
$this->seekReadStreamToPosition($byteOffset);
|
||||
}
|
||||
$this->_offset = $byteOffset;
|
||||
$this->offset = $byteOffset;
|
||||
}
|
||||
|
||||
/** Just write the bytes to the file */
|
||||
protected function _commit($bytes)
|
||||
protected function doCommit($bytes)
|
||||
{
|
||||
fwrite($this->_getWriteHandle(), $bytes);
|
||||
$this->_resetReadHandle();
|
||||
fwrite($this->getWriteHandle(), $bytes);
|
||||
$this->resetReadHandle();
|
||||
}
|
||||
|
||||
/** Not used */
|
||||
protected function _flush()
|
||||
protected function flush()
|
||||
{
|
||||
}
|
||||
|
||||
/** Get the resource for reading */
|
||||
private function _getReadHandle()
|
||||
private function getReadHandle()
|
||||
{
|
||||
if (!isset($this->_reader)) {
|
||||
if (!$this->_reader = fopen($this->_path, 'rb')) {
|
||||
throw new Swift_IoException(
|
||||
'Unable to open file for reading ['.$this->_path.']'
|
||||
);
|
||||
if (!isset($this->reader)) {
|
||||
$pointer = @fopen($this->path, 'rb');
|
||||
if (!$pointer) {
|
||||
throw new Swift_IoException('Unable to open file for reading ['.$this->path.']');
|
||||
}
|
||||
if ($this->_offset != 0) {
|
||||
$this->_getReadStreamSeekableStatus();
|
||||
$this->_seekReadStreamToPosition($this->_offset);
|
||||
$this->reader = $pointer;
|
||||
if ($this->offset != 0) {
|
||||
$this->getReadStreamSeekableStatus();
|
||||
$this->seekReadStreamToPosition($this->offset);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_reader;
|
||||
return $this->reader;
|
||||
}
|
||||
|
||||
/** Get the resource for writing */
|
||||
private function _getWriteHandle()
|
||||
private function getWriteHandle()
|
||||
{
|
||||
if (!isset($this->_writer)) {
|
||||
if (!$this->_writer = fopen($this->_path, $this->_mode)) {
|
||||
if (!isset($this->writer)) {
|
||||
if (!$this->writer = fopen($this->path, $this->mode)) {
|
||||
throw new Swift_IoException(
|
||||
'Unable to open file for writing ['.$this->_path.']'
|
||||
'Unable to open file for writing ['.$this->path.']'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_writer;
|
||||
return $this->writer;
|
||||
}
|
||||
|
||||
/** Force a reload of the resource for reading */
|
||||
private function _resetReadHandle()
|
||||
private function resetReadHandle()
|
||||
{
|
||||
if (isset($this->_reader)) {
|
||||
fclose($this->_reader);
|
||||
$this->_reader = null;
|
||||
if (isset($this->reader)) {
|
||||
fclose($this->reader);
|
||||
$this->reader = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if ReadOnly Stream is seekable */
|
||||
private function _getReadStreamSeekableStatus()
|
||||
private function getReadStreamSeekableStatus()
|
||||
{
|
||||
$metas = stream_get_meta_data($this->_reader);
|
||||
$this->_seekable = $metas['seekable'];
|
||||
$metas = stream_get_meta_data($this->reader);
|
||||
$this->seekable = $metas['seekable'];
|
||||
}
|
||||
|
||||
/** Streams in a readOnly stream ensuring copy if needed */
|
||||
private function _seekReadStreamToPosition($offset)
|
||||
private function seekReadStreamToPosition($offset)
|
||||
{
|
||||
if ($this->_seekable === null) {
|
||||
$this->_getReadStreamSeekableStatus();
|
||||
if ($this->seekable === null) {
|
||||
$this->getReadStreamSeekableStatus();
|
||||
}
|
||||
if ($this->_seekable === false) {
|
||||
$currentPos = ftell($this->_reader);
|
||||
if ($this->seekable === false) {
|
||||
$currentPos = ftell($this->reader);
|
||||
if ($currentPos < $offset) {
|
||||
$toDiscard = $offset - $currentPos;
|
||||
fread($this->_reader, $toDiscard);
|
||||
fread($this->reader, $toDiscard);
|
||||
|
||||
return;
|
||||
}
|
||||
$this->_copyReadStream();
|
||||
$this->copyReadStream();
|
||||
}
|
||||
fseek($this->_reader, $offset, SEEK_SET);
|
||||
fseek($this->reader, $offset, SEEK_SET);
|
||||
}
|
||||
|
||||
/** Copy a readOnly Stream to ensure seekability */
|
||||
private function _copyReadStream()
|
||||
private function copyReadStream()
|
||||
{
|
||||
if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
|
||||
/* We have opened a php:// Stream Should work without problem */
|
||||
@@ -212,11 +199,11 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
} else {
|
||||
throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
|
||||
}
|
||||
$currentPos = ftell($this->_reader);
|
||||
fclose($this->_reader);
|
||||
$source = fopen($this->_path, 'rb');
|
||||
$currentPos = ftell($this->reader);
|
||||
fclose($this->reader);
|
||||
$source = fopen($this->path, 'rb');
|
||||
if (!$source) {
|
||||
throw new Swift_IoException('Unable to open file for copying ['.$this->_path.']');
|
||||
throw new Swift_IoException('Unable to open file for copying ['.$this->path.']');
|
||||
}
|
||||
fseek($tmpFile, 0, SEEK_SET);
|
||||
while (!feof($source)) {
|
||||
@@ -224,6 +211,6 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
|
||||
}
|
||||
fseek($tmpFile, $currentPos, SEEK_SET);
|
||||
fclose($source);
|
||||
$this->_reader = $tmpFile;
|
||||
$this->reader = $tmpFile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user