Completed
Branch develop (96e38e)
by
unknown
28:00
created
swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -15,162 +15,162 @@
 block discarded – undo
15 15
  */
16 16
 abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_InputByteStream, Swift_Filterable
17 17
 {
18
-    /**
19
-     * Write sequence.
20
-     */
21
-    protected $sequence = 0;
22
-
23
-    /**
24
-     * StreamFilters.
25
-     *
26
-     * @var Swift_StreamFilter[]
27
-     */
28
-    private $filters = [];
29
-
30
-    /**
31
-     * A buffer for writing.
32
-     */
33
-    private $writeBuffer = '';
34
-
35
-    /**
36
-     * Bound streams.
37
-     *
38
-     * @var Swift_InputByteStream[]
39
-     */
40
-    private $mirrors = [];
41
-
42
-    /**
43
-     * Commit the given bytes to the storage medium immediately.
44
-     *
45
-     * @param string $bytes
46
-     */
47
-    abstract protected function doCommit($bytes);
48
-
49
-    /**
50
-     * Flush any buffers/content with immediate effect.
51
-     */
52
-    abstract protected function flush();
53
-
54
-    /**
55
-     * Add a StreamFilter to this InputByteStream.
56
-     *
57
-     * @param string $key
58
-     */
59
-    public function addFilter(Swift_StreamFilter $filter, $key)
60
-    {
61
-        $this->filters[$key] = $filter;
62
-    }
63
-
64
-    /**
65
-     * Remove an already present StreamFilter based on its $key.
66
-     *
67
-     * @param string $key
68
-     */
69
-    public function removeFilter($key)
70
-    {
71
-        unset($this->filters[$key]);
72
-    }
73
-
74
-    /**
75
-     * Writes $bytes to the end of the stream.
76
-     *
77
-     * @param string $bytes
78
-     *
79
-     * @throws Swift_IoException
80
-     *
81
-     * @return int
82
-     */
83
-    public function write($bytes)
84
-    {
85
-        $this->writeBuffer .= $bytes;
86
-        foreach ($this->filters as $filter) {
87
-            if ($filter->shouldBuffer($this->writeBuffer)) {
88
-                return;
89
-            }
90
-        }
91
-        $this->doWrite($this->writeBuffer);
92
-
93
-        return ++$this->sequence;
94
-    }
95
-
96
-    /**
97
-     * For any bytes that are currently buffered inside the stream, force them
98
-     * off the buffer.
99
-     *
100
-     * @throws Swift_IoException
101
-     */
102
-    public function commit()
103
-    {
104
-        $this->doWrite($this->writeBuffer);
105
-    }
106
-
107
-    /**
108
-     * Attach $is to this stream.
109
-     *
110
-     * The stream acts as an observer, receiving all data that is written.
111
-     * All {@link write()} and {@link flushBuffers()} operations will be mirrored.
112
-     */
113
-    public function bind(Swift_InputByteStream $is)
114
-    {
115
-        $this->mirrors[] = $is;
116
-    }
117
-
118
-    /**
119
-     * Remove an already bound stream.
120
-     *
121
-     * If $is is not bound, no errors will be raised.
122
-     * If the stream currently has any buffered data it will be written to $is
123
-     * before unbinding occurs.
124
-     */
125
-    public function unbind(Swift_InputByteStream $is)
126
-    {
127
-        foreach ($this->mirrors as $k => $stream) {
128
-            if ($is === $stream) {
129
-                if ('' !== $this->writeBuffer) {
130
-                    $stream->write($this->writeBuffer);
131
-                }
132
-                unset($this->mirrors[$k]);
133
-            }
134
-        }
135
-    }
136
-
137
-    /**
138
-     * Flush the contents of the stream (empty it) and set the internal pointer
139
-     * to the beginning.
140
-     *
141
-     * @throws Swift_IoException
142
-     */
143
-    public function flushBuffers()
144
-    {
145
-        if ('' !== $this->writeBuffer) {
146
-            $this->doWrite($this->writeBuffer);
147
-        }
148
-        $this->flush();
149
-
150
-        foreach ($this->mirrors as $stream) {
151
-            $stream->flushBuffers();
152
-        }
153
-    }
154
-
155
-    /** Run $bytes through all filters */
156
-    private function filter($bytes)
157
-    {
158
-        foreach ($this->filters as $filter) {
159
-            $bytes = $filter->filter($bytes);
160
-        }
161
-
162
-        return $bytes;
163
-    }
164
-
165
-    /** Just write the bytes to the stream */
166
-    private function doWrite($bytes)
167
-    {
168
-        $this->doCommit($this->filter($bytes));
169
-
170
-        foreach ($this->mirrors as $stream) {
171
-            $stream->write($bytes);
172
-        }
173
-
174
-        $this->writeBuffer = '';
175
-    }
18
+	/**
19
+	 * Write sequence.
20
+	 */
21
+	protected $sequence = 0;
22
+
23
+	/**
24
+	 * StreamFilters.
25
+	 *
26
+	 * @var Swift_StreamFilter[]
27
+	 */
28
+	private $filters = [];
29
+
30
+	/**
31
+	 * A buffer for writing.
32
+	 */
33
+	private $writeBuffer = '';
34
+
35
+	/**
36
+	 * Bound streams.
37
+	 *
38
+	 * @var Swift_InputByteStream[]
39
+	 */
40
+	private $mirrors = [];
41
+
42
+	/**
43
+	 * Commit the given bytes to the storage medium immediately.
44
+	 *
45
+	 * @param string $bytes
46
+	 */
47
+	abstract protected function doCommit($bytes);
48
+
49
+	/**
50
+	 * Flush any buffers/content with immediate effect.
51
+	 */
52
+	abstract protected function flush();
53
+
54
+	/**
55
+	 * Add a StreamFilter to this InputByteStream.
56
+	 *
57
+	 * @param string $key
58
+	 */
59
+	public function addFilter(Swift_StreamFilter $filter, $key)
60
+	{
61
+		$this->filters[$key] = $filter;
62
+	}
63
+
64
+	/**
65
+	 * Remove an already present StreamFilter based on its $key.
66
+	 *
67
+	 * @param string $key
68
+	 */
69
+	public function removeFilter($key)
70
+	{
71
+		unset($this->filters[$key]);
72
+	}
73
+
74
+	/**
75
+	 * Writes $bytes to the end of the stream.
76
+	 *
77
+	 * @param string $bytes
78
+	 *
79
+	 * @throws Swift_IoException
80
+	 *
81
+	 * @return int
82
+	 */
83
+	public function write($bytes)
84
+	{
85
+		$this->writeBuffer .= $bytes;
86
+		foreach ($this->filters as $filter) {
87
+			if ($filter->shouldBuffer($this->writeBuffer)) {
88
+				return;
89
+			}
90
+		}
91
+		$this->doWrite($this->writeBuffer);
92
+
93
+		return ++$this->sequence;
94
+	}
95
+
96
+	/**
97
+	 * For any bytes that are currently buffered inside the stream, force them
98
+	 * off the buffer.
99
+	 *
100
+	 * @throws Swift_IoException
101
+	 */
102
+	public function commit()
103
+	{
104
+		$this->doWrite($this->writeBuffer);
105
+	}
106
+
107
+	/**
108
+	 * Attach $is to this stream.
109
+	 *
110
+	 * The stream acts as an observer, receiving all data that is written.
111
+	 * All {@link write()} and {@link flushBuffers()} operations will be mirrored.
112
+	 */
113
+	public function bind(Swift_InputByteStream $is)
114
+	{
115
+		$this->mirrors[] = $is;
116
+	}
117
+
118
+	/**
119
+	 * Remove an already bound stream.
120
+	 *
121
+	 * If $is is not bound, no errors will be raised.
122
+	 * If the stream currently has any buffered data it will be written to $is
123
+	 * before unbinding occurs.
124
+	 */
125
+	public function unbind(Swift_InputByteStream $is)
126
+	{
127
+		foreach ($this->mirrors as $k => $stream) {
128
+			if ($is === $stream) {
129
+				if ('' !== $this->writeBuffer) {
130
+					$stream->write($this->writeBuffer);
131
+				}
132
+				unset($this->mirrors[$k]);
133
+			}
134
+		}
135
+	}
136
+
137
+	/**
138
+	 * Flush the contents of the stream (empty it) and set the internal pointer
139
+	 * to the beginning.
140
+	 *
141
+	 * @throws Swift_IoException
142
+	 */
143
+	public function flushBuffers()
144
+	{
145
+		if ('' !== $this->writeBuffer) {
146
+			$this->doWrite($this->writeBuffer);
147
+		}
148
+		$this->flush();
149
+
150
+		foreach ($this->mirrors as $stream) {
151
+			$stream->flushBuffers();
152
+		}
153
+	}
154
+
155
+	/** Run $bytes through all filters */
156
+	private function filter($bytes)
157
+	{
158
+		foreach ($this->filters as $filter) {
159
+			$bytes = $filter->filter($bytes);
160
+		}
161
+
162
+		return $bytes;
163
+	}
164
+
165
+	/** Just write the bytes to the stream */
166
+	private function doWrite($bytes)
167
+	{
168
+		$this->doCommit($this->filter($bytes));
169
+
170
+		foreach ($this->mirrors as $stream) {
171
+			$stream->write($bytes);
172
+		}
173
+
174
+		$this->writeBuffer = '';
175
+	}
176 176
 }
Please login to merge, or discard this patch.
includes/swiftmailer/lib/classes/Swift/ByteStream/ArrayByteStream.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -15,164 +15,164 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_OutputByteStream
17 17
 {
18
-    /**
19
-     * The internal stack of bytes.
20
-     *
21
-     * @var string[]
22
-     */
23
-    private $array = [];
24
-
25
-    /**
26
-     * The size of the stack.
27
-     *
28
-     * @var int
29
-     */
30
-    private $arraySize = 0;
31
-
32
-    /**
33
-     * The internal pointer offset.
34
-     *
35
-     * @var int
36
-     */
37
-    private $offset = 0;
38
-
39
-    /**
40
-     * Bound streams.
41
-     *
42
-     * @var Swift_InputByteStream[]
43
-     */
44
-    private $mirrors = [];
45
-
46
-    /**
47
-     * Create a new ArrayByteStream.
48
-     *
49
-     * If $stack is given the stream will be populated with the bytes it contains.
50
-     *
51
-     * @param mixed $stack of bytes in string or array form, optional
52
-     */
53
-    public function __construct($stack = null)
54
-    {
55
-        if (\is_array($stack)) {
56
-            $this->array = $stack;
57
-            $this->arraySize = \count($stack);
58
-        } elseif (\is_string($stack)) {
59
-            $this->write($stack);
60
-        } else {
61
-            $this->array = [];
62
-        }
63
-    }
64
-
65
-    /**
66
-     * Reads $length bytes from the stream into a string and moves the pointer
67
-     * through the stream by $length.
68
-     *
69
-     * If less bytes exist than are requested the
70
-     * remaining bytes are given instead. If no bytes are remaining at all, boolean
71
-     * false is returned.
72
-     *
73
-     * @param int $length
74
-     *
75
-     * @return string
76
-     */
77
-    public function read($length)
78
-    {
79
-        if ($this->offset == $this->arraySize) {
80
-            return false;
81
-        }
82
-
83
-        // Don't use array slice
84
-        $end = $length + $this->offset;
85
-        $end = $this->arraySize < $end ? $this->arraySize : $end;
86
-        $ret = '';
87
-        for (; $this->offset < $end; ++$this->offset) {
88
-            $ret .= $this->array[$this->offset];
89
-        }
90
-
91
-        return $ret;
92
-    }
93
-
94
-    /**
95
-     * Writes $bytes to the end of the stream.
96
-     *
97
-     * @param string $bytes
98
-     */
99
-    public function write($bytes)
100
-    {
101
-        $to_add = str_split($bytes);
102
-        foreach ($to_add as $value) {
103
-            $this->array[] = $value;
104
-        }
105
-        $this->arraySize = \count($this->array);
106
-
107
-        foreach ($this->mirrors as $stream) {
108
-            $stream->write($bytes);
109
-        }
110
-    }
111
-
112
-    /**
113
-     * Not used.
114
-     */
115
-    public function commit()
116
-    {
117
-    }
118
-
119
-    /**
120
-     * Attach $is to this stream.
121
-     *
122
-     * The stream acts as an observer, receiving all data that is written.
123
-     * All {@link write()} and {@link flushBuffers()} operations will be mirrored.
124
-     */
125
-    public function bind(Swift_InputByteStream $is)
126
-    {
127
-        $this->mirrors[] = $is;
128
-    }
129
-
130
-    /**
131
-     * Remove an already bound stream.
132
-     *
133
-     * If $is is not bound, no errors will be raised.
134
-     * If the stream currently has any buffered data it will be written to $is
135
-     * before unbinding occurs.
136
-     */
137
-    public function unbind(Swift_InputByteStream $is)
138
-    {
139
-        foreach ($this->mirrors as $k => $stream) {
140
-            if ($is === $stream) {
141
-                unset($this->mirrors[$k]);
142
-            }
143
-        }
144
-    }
145
-
146
-    /**
147
-     * Move the internal read pointer to $byteOffset in the stream.
148
-     *
149
-     * @param int $byteOffset
150
-     *
151
-     * @return bool
152
-     */
153
-    public function setReadPointer($byteOffset)
154
-    {
155
-        if ($byteOffset > $this->arraySize) {
156
-            $byteOffset = $this->arraySize;
157
-        } elseif ($byteOffset < 0) {
158
-            $byteOffset = 0;
159
-        }
160
-
161
-        $this->offset = $byteOffset;
162
-    }
163
-
164
-    /**
165
-     * Flush the contents of the stream (empty it) and set the internal pointer
166
-     * to the beginning.
167
-     */
168
-    public function flushBuffers()
169
-    {
170
-        $this->offset = 0;
171
-        $this->array = [];
172
-        $this->arraySize = 0;
173
-
174
-        foreach ($this->mirrors as $stream) {
175
-            $stream->flushBuffers();
176
-        }
177
-    }
18
+	/**
19
+	 * The internal stack of bytes.
20
+	 *
21
+	 * @var string[]
22
+	 */
23
+	private $array = [];
24
+
25
+	/**
26
+	 * The size of the stack.
27
+	 *
28
+	 * @var int
29
+	 */
30
+	private $arraySize = 0;
31
+
32
+	/**
33
+	 * The internal pointer offset.
34
+	 *
35
+	 * @var int
36
+	 */
37
+	private $offset = 0;
38
+
39
+	/**
40
+	 * Bound streams.
41
+	 *
42
+	 * @var Swift_InputByteStream[]
43
+	 */
44
+	private $mirrors = [];
45
+
46
+	/**
47
+	 * Create a new ArrayByteStream.
48
+	 *
49
+	 * If $stack is given the stream will be populated with the bytes it contains.
50
+	 *
51
+	 * @param mixed $stack of bytes in string or array form, optional
52
+	 */
53
+	public function __construct($stack = null)
54
+	{
55
+		if (\is_array($stack)) {
56
+			$this->array = $stack;
57
+			$this->arraySize = \count($stack);
58
+		} elseif (\is_string($stack)) {
59
+			$this->write($stack);
60
+		} else {
61
+			$this->array = [];
62
+		}
63
+	}
64
+
65
+	/**
66
+	 * Reads $length bytes from the stream into a string and moves the pointer
67
+	 * through the stream by $length.
68
+	 *
69
+	 * If less bytes exist than are requested the
70
+	 * remaining bytes are given instead. If no bytes are remaining at all, boolean
71
+	 * false is returned.
72
+	 *
73
+	 * @param int $length
74
+	 *
75
+	 * @return string
76
+	 */
77
+	public function read($length)
78
+	{
79
+		if ($this->offset == $this->arraySize) {
80
+			return false;
81
+		}
82
+
83
+		// Don't use array slice
84
+		$end = $length + $this->offset;
85
+		$end = $this->arraySize < $end ? $this->arraySize : $end;
86
+		$ret = '';
87
+		for (; $this->offset < $end; ++$this->offset) {
88
+			$ret .= $this->array[$this->offset];
89
+		}
90
+
91
+		return $ret;
92
+	}
93
+
94
+	/**
95
+	 * Writes $bytes to the end of the stream.
96
+	 *
97
+	 * @param string $bytes
98
+	 */
99
+	public function write($bytes)
100
+	{
101
+		$to_add = str_split($bytes);
102
+		foreach ($to_add as $value) {
103
+			$this->array[] = $value;
104
+		}
105
+		$this->arraySize = \count($this->array);
106
+
107
+		foreach ($this->mirrors as $stream) {
108
+			$stream->write($bytes);
109
+		}
110
+	}
111
+
112
+	/**
113
+	 * Not used.
114
+	 */
115
+	public function commit()
116
+	{
117
+	}
118
+
119
+	/**
120
+	 * Attach $is to this stream.
121
+	 *
122
+	 * The stream acts as an observer, receiving all data that is written.
123
+	 * All {@link write()} and {@link flushBuffers()} operations will be mirrored.
124
+	 */
125
+	public function bind(Swift_InputByteStream $is)
126
+	{
127
+		$this->mirrors[] = $is;
128
+	}
129
+
130
+	/**
131
+	 * Remove an already bound stream.
132
+	 *
133
+	 * If $is is not bound, no errors will be raised.
134
+	 * If the stream currently has any buffered data it will be written to $is
135
+	 * before unbinding occurs.
136
+	 */
137
+	public function unbind(Swift_InputByteStream $is)
138
+	{
139
+		foreach ($this->mirrors as $k => $stream) {
140
+			if ($is === $stream) {
141
+				unset($this->mirrors[$k]);
142
+			}
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * Move the internal read pointer to $byteOffset in the stream.
148
+	 *
149
+	 * @param int $byteOffset
150
+	 *
151
+	 * @return bool
152
+	 */
153
+	public function setReadPointer($byteOffset)
154
+	{
155
+		if ($byteOffset > $this->arraySize) {
156
+			$byteOffset = $this->arraySize;
157
+		} elseif ($byteOffset < 0) {
158
+			$byteOffset = 0;
159
+		}
160
+
161
+		$this->offset = $byteOffset;
162
+	}
163
+
164
+	/**
165
+	 * Flush the contents of the stream (empty it) and set the internal pointer
166
+	 * to the beginning.
167
+	 */
168
+	public function flushBuffers()
169
+	{
170
+		$this->offset = 0;
171
+		$this->array = [];
172
+		$this->arraySize = 0;
173
+
174
+		foreach ($this->mirrors as $stream) {
175
+			$stream->flushBuffers();
176
+		}
177
+	}
178 178
 }
Please login to merge, or discard this patch.
swiftmailer/lib/classes/Swift/ByteStream/TemporaryFileByteStream.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -13,40 +13,40 @@
 block discarded – undo
13 13
  */
14 14
 class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByteStream
15 15
 {
16
-    public function __construct()
17
-    {
18
-        $filePath = tempnam(sys_get_temp_dir(), 'FileByteStream');
19
-
20
-        if (false === $filePath) {
21
-            throw new Swift_IoException('Failed to retrieve temporary file name.');
22
-        }
23
-
24
-        parent::__construct($filePath, true);
25
-    }
26
-
27
-    public function getContent()
28
-    {
29
-        if (false === ($content = file_get_contents($this->getPath()))) {
30
-            throw new Swift_IoException('Failed to get temporary file content.');
31
-        }
32
-
33
-        return $content;
34
-    }
35
-
36
-    public function __destruct()
37
-    {
38
-        if (file_exists($this->getPath())) {
39
-            @unlink($this->getPath());
40
-        }
41
-    }
42
-
43
-    public function __sleep()
44
-    {
45
-        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
46
-    }
47
-
48
-    public function __wakeup()
49
-    {
50
-        throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
51
-    }
16
+	public function __construct()
17
+	{
18
+		$filePath = tempnam(sys_get_temp_dir(), 'FileByteStream');
19
+
20
+		if (false === $filePath) {
21
+			throw new Swift_IoException('Failed to retrieve temporary file name.');
22
+		}
23
+
24
+		parent::__construct($filePath, true);
25
+	}
26
+
27
+	public function getContent()
28
+	{
29
+		if (false === ($content = file_get_contents($this->getPath()))) {
30
+			throw new Swift_IoException('Failed to get temporary file content.');
31
+		}
32
+
33
+		return $content;
34
+	}
35
+
36
+	public function __destruct()
37
+	{
38
+		if (file_exists($this->getPath())) {
39
+			@unlink($this->getPath());
40
+		}
41
+	}
42
+
43
+	public function __sleep()
44
+	{
45
+		throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
46
+	}
47
+
48
+	public function __wakeup()
49
+	{
50
+		throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -15,200 +15,200 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream
17 17
 {
18
-    /** The internal pointer offset */
19
-    private $offset = 0;
20
-
21
-    /** The path to the file */
22
-    private $path;
23
-
24
-    /** The mode this file is opened in for writing */
25
-    private $mode;
26
-
27
-    /** A lazy-loaded resource handle for reading the file */
28
-    private $reader;
29
-
30
-    /** A lazy-loaded resource handle for writing the file */
31
-    private $writer;
32
-
33
-    /** If stream is seekable true/false, or null if not known */
34
-    private $seekable = null;
35
-
36
-    /**
37
-     * Create a new FileByteStream for $path.
38
-     *
39
-     * @param string $path
40
-     * @param bool   $writable if true
41
-     */
42
-    public function __construct($path, $writable = false)
43
-    {
44
-        if (empty($path)) {
45
-            throw new Swift_IoException('The path cannot be empty');
46
-        }
47
-        $this->path = $path;
48
-        $this->mode = $writable ? 'w+b' : 'rb';
49
-    }
50
-
51
-    /**
52
-     * Get the complete path to the file.
53
-     *
54
-     * @return string
55
-     */
56
-    public function getPath()
57
-    {
58
-        return $this->path;
59
-    }
60
-
61
-    /**
62
-     * Reads $length bytes from the stream into a string and moves the pointer
63
-     * through the stream by $length.
64
-     *
65
-     * If less bytes exist than are requested the
66
-     * remaining bytes are given instead. If no bytes are remaining at all, boolean
67
-     * false is returned.
68
-     *
69
-     * @param int $length
70
-     *
71
-     * @return string|bool
72
-     *
73
-     * @throws Swift_IoException
74
-     */
75
-    public function read($length)
76
-    {
77
-        $fp = $this->getReadHandle();
78
-        if (!feof($fp)) {
79
-            $bytes = fread($fp, $length);
80
-            $this->offset = ftell($fp);
81
-
82
-            // If we read one byte after reaching the end of the file
83
-            // feof() will return false and an empty string is returned
84
-            if ((false === $bytes || '' === $bytes) && feof($fp)) {
85
-                $this->resetReadHandle();
86
-
87
-                return false;
88
-            }
89
-
90
-            return $bytes;
91
-        }
92
-
93
-        $this->resetReadHandle();
94
-
95
-        return false;
96
-    }
97
-
98
-    /**
99
-     * Move the internal read pointer to $byteOffset in the stream.
100
-     *
101
-     * @param int $byteOffset
102
-     *
103
-     * @return bool
104
-     */
105
-    public function setReadPointer($byteOffset)
106
-    {
107
-        if (isset($this->reader)) {
108
-            $this->seekReadStreamToPosition($byteOffset);
109
-        }
110
-        $this->offset = $byteOffset;
111
-    }
112
-
113
-    /** Just write the bytes to the file */
114
-    protected function doCommit($bytes)
115
-    {
116
-        fwrite($this->getWriteHandle(), $bytes);
117
-        $this->resetReadHandle();
118
-    }
119
-
120
-    /** Not used */
121
-    protected function flush()
122
-    {
123
-    }
124
-
125
-    /** Get the resource for reading */
126
-    private function getReadHandle()
127
-    {
128
-        if (!isset($this->reader)) {
129
-            $pointer = @fopen($this->path, 'rb');
130
-            if (!$pointer) {
131
-                throw new Swift_IoException('Unable to open file for reading ['.$this->path.']');
132
-            }
133
-            $this->reader = $pointer;
134
-            if (0 != $this->offset) {
135
-                $this->getReadStreamSeekableStatus();
136
-                $this->seekReadStreamToPosition($this->offset);
137
-            }
138
-        }
139
-
140
-        return $this->reader;
141
-    }
142
-
143
-    /** Get the resource for writing */
144
-    private function getWriteHandle()
145
-    {
146
-        if (!isset($this->writer)) {
147
-            if (!$this->writer = fopen($this->path, $this->mode)) {
148
-                throw new Swift_IoException('Unable to open file for writing ['.$this->path.']');
149
-            }
150
-        }
151
-
152
-        return $this->writer;
153
-    }
154
-
155
-    /** Force a reload of the resource for reading */
156
-    private function resetReadHandle()
157
-    {
158
-        if (isset($this->reader)) {
159
-            fclose($this->reader);
160
-            $this->reader = null;
161
-        }
162
-    }
163
-
164
-    /** Check if ReadOnly Stream is seekable */
165
-    private function getReadStreamSeekableStatus()
166
-    {
167
-        $metas = stream_get_meta_data($this->reader);
168
-        $this->seekable = $metas['seekable'];
169
-    }
170
-
171
-    /** Streams in a readOnly stream ensuring copy if needed */
172
-    private function seekReadStreamToPosition($offset)
173
-    {
174
-        if (null === $this->seekable) {
175
-            $this->getReadStreamSeekableStatus();
176
-        }
177
-        if (false === $this->seekable) {
178
-            $currentPos = ftell($this->reader);
179
-            if ($currentPos < $offset) {
180
-                $toDiscard = $offset - $currentPos;
181
-                fread($this->reader, $toDiscard);
182
-
183
-                return;
184
-            }
185
-            $this->copyReadStream();
186
-        }
187
-        fseek($this->reader, $offset, SEEK_SET);
188
-    }
189
-
190
-    /** Copy a readOnly Stream to ensure seekability */
191
-    private function copyReadStream()
192
-    {
193
-        if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
194
-            /* We have opened a php:// Stream Should work without problem */
195
-        } elseif (\function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile())) {
196
-            /* We have opened a tmpfile */
197
-        } else {
198
-            throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
199
-        }
200
-        $currentPos = ftell($this->reader);
201
-        fclose($this->reader);
202
-        $source = fopen($this->path, 'rb');
203
-        if (!$source) {
204
-            throw new Swift_IoException('Unable to open file for copying ['.$this->path.']');
205
-        }
206
-        fseek($tmpFile, 0, SEEK_SET);
207
-        while (!feof($source)) {
208
-            fwrite($tmpFile, fread($source, 4096));
209
-        }
210
-        fseek($tmpFile, $currentPos, SEEK_SET);
211
-        fclose($source);
212
-        $this->reader = $tmpFile;
213
-    }
18
+	/** The internal pointer offset */
19
+	private $offset = 0;
20
+
21
+	/** The path to the file */
22
+	private $path;
23
+
24
+	/** The mode this file is opened in for writing */
25
+	private $mode;
26
+
27
+	/** A lazy-loaded resource handle for reading the file */
28
+	private $reader;
29
+
30
+	/** A lazy-loaded resource handle for writing the file */
31
+	private $writer;
32
+
33
+	/** If stream is seekable true/false, or null if not known */
34
+	private $seekable = null;
35
+
36
+	/**
37
+	 * Create a new FileByteStream for $path.
38
+	 *
39
+	 * @param string $path
40
+	 * @param bool   $writable if true
41
+	 */
42
+	public function __construct($path, $writable = false)
43
+	{
44
+		if (empty($path)) {
45
+			throw new Swift_IoException('The path cannot be empty');
46
+		}
47
+		$this->path = $path;
48
+		$this->mode = $writable ? 'w+b' : 'rb';
49
+	}
50
+
51
+	/**
52
+	 * Get the complete path to the file.
53
+	 *
54
+	 * @return string
55
+	 */
56
+	public function getPath()
57
+	{
58
+		return $this->path;
59
+	}
60
+
61
+	/**
62
+	 * Reads $length bytes from the stream into a string and moves the pointer
63
+	 * through the stream by $length.
64
+	 *
65
+	 * If less bytes exist than are requested the
66
+	 * remaining bytes are given instead. If no bytes are remaining at all, boolean
67
+	 * false is returned.
68
+	 *
69
+	 * @param int $length
70
+	 *
71
+	 * @return string|bool
72
+	 *
73
+	 * @throws Swift_IoException
74
+	 */
75
+	public function read($length)
76
+	{
77
+		$fp = $this->getReadHandle();
78
+		if (!feof($fp)) {
79
+			$bytes = fread($fp, $length);
80
+			$this->offset = ftell($fp);
81
+
82
+			// If we read one byte after reaching the end of the file
83
+			// feof() will return false and an empty string is returned
84
+			if ((false === $bytes || '' === $bytes) && feof($fp)) {
85
+				$this->resetReadHandle();
86
+
87
+				return false;
88
+			}
89
+
90
+			return $bytes;
91
+		}
92
+
93
+		$this->resetReadHandle();
94
+
95
+		return false;
96
+	}
97
+
98
+	/**
99
+	 * Move the internal read pointer to $byteOffset in the stream.
100
+	 *
101
+	 * @param int $byteOffset
102
+	 *
103
+	 * @return bool
104
+	 */
105
+	public function setReadPointer($byteOffset)
106
+	{
107
+		if (isset($this->reader)) {
108
+			$this->seekReadStreamToPosition($byteOffset);
109
+		}
110
+		$this->offset = $byteOffset;
111
+	}
112
+
113
+	/** Just write the bytes to the file */
114
+	protected function doCommit($bytes)
115
+	{
116
+		fwrite($this->getWriteHandle(), $bytes);
117
+		$this->resetReadHandle();
118
+	}
119
+
120
+	/** Not used */
121
+	protected function flush()
122
+	{
123
+	}
124
+
125
+	/** Get the resource for reading */
126
+	private function getReadHandle()
127
+	{
128
+		if (!isset($this->reader)) {
129
+			$pointer = @fopen($this->path, 'rb');
130
+			if (!$pointer) {
131
+				throw new Swift_IoException('Unable to open file for reading ['.$this->path.']');
132
+			}
133
+			$this->reader = $pointer;
134
+			if (0 != $this->offset) {
135
+				$this->getReadStreamSeekableStatus();
136
+				$this->seekReadStreamToPosition($this->offset);
137
+			}
138
+		}
139
+
140
+		return $this->reader;
141
+	}
142
+
143
+	/** Get the resource for writing */
144
+	private function getWriteHandle()
145
+	{
146
+		if (!isset($this->writer)) {
147
+			if (!$this->writer = fopen($this->path, $this->mode)) {
148
+				throw new Swift_IoException('Unable to open file for writing ['.$this->path.']');
149
+			}
150
+		}
151
+
152
+		return $this->writer;
153
+	}
154
+
155
+	/** Force a reload of the resource for reading */
156
+	private function resetReadHandle()
157
+	{
158
+		if (isset($this->reader)) {
159
+			fclose($this->reader);
160
+			$this->reader = null;
161
+		}
162
+	}
163
+
164
+	/** Check if ReadOnly Stream is seekable */
165
+	private function getReadStreamSeekableStatus()
166
+	{
167
+		$metas = stream_get_meta_data($this->reader);
168
+		$this->seekable = $metas['seekable'];
169
+	}
170
+
171
+	/** Streams in a readOnly stream ensuring copy if needed */
172
+	private function seekReadStreamToPosition($offset)
173
+	{
174
+		if (null === $this->seekable) {
175
+			$this->getReadStreamSeekableStatus();
176
+		}
177
+		if (false === $this->seekable) {
178
+			$currentPos = ftell($this->reader);
179
+			if ($currentPos < $offset) {
180
+				$toDiscard = $offset - $currentPos;
181
+				fread($this->reader, $toDiscard);
182
+
183
+				return;
184
+			}
185
+			$this->copyReadStream();
186
+		}
187
+		fseek($this->reader, $offset, SEEK_SET);
188
+	}
189
+
190
+	/** Copy a readOnly Stream to ensure seekability */
191
+	private function copyReadStream()
192
+	{
193
+		if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
194
+			/* We have opened a php:// Stream Should work without problem */
195
+		} elseif (\function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile())) {
196
+			/* We have opened a tmpfile */
197
+		} else {
198
+			throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');
199
+		}
200
+		$currentPos = ftell($this->reader);
201
+		fclose($this->reader);
202
+		$source = fopen($this->path, 'rb');
203
+		if (!$source) {
204
+			throw new Swift_IoException('Unable to open file for copying ['.$this->path.']');
205
+		}
206
+		fseek($tmpFile, 0, SEEK_SET);
207
+		while (!feof($source)) {
208
+			fwrite($tmpFile, fread($source, 4096));
209
+		}
210
+		fseek($tmpFile, $currentPos, SEEK_SET);
211
+		fclose($source);
212
+		$this->reader = $tmpFile;
213
+	}
214 214
 }
Please login to merge, or discard this patch.
swiftmailer/lib/classes/Swift/StreamFilters/StringReplacementFilter.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,56 +15,56 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_StreamFilters_StringReplacementFilter implements Swift_StreamFilter
17 17
 {
18
-    /** The needle(s) to search for */
19
-    private $search;
18
+	/** The needle(s) to search for */
19
+	private $search;
20 20
 
21
-    /** The replacement(s) to make */
22
-    private $replace;
21
+	/** The replacement(s) to make */
22
+	private $replace;
23 23
 
24
-    /**
25
-     * Create a new StringReplacementFilter with $search and $replace.
26
-     *
27
-     * @param string|array $search
28
-     * @param string|array $replace
29
-     */
30
-    public function __construct($search, $replace)
31
-    {
32
-        $this->search = $search;
33
-        $this->replace = $replace;
34
-    }
24
+	/**
25
+	 * Create a new StringReplacementFilter with $search and $replace.
26
+	 *
27
+	 * @param string|array $search
28
+	 * @param string|array $replace
29
+	 */
30
+	public function __construct($search, $replace)
31
+	{
32
+		$this->search = $search;
33
+		$this->replace = $replace;
34
+	}
35 35
 
36
-    /**
37
-     * Returns true if based on the buffer passed more bytes should be buffered.
38
-     *
39
-     * @param string $buffer
40
-     *
41
-     * @return bool
42
-     */
43
-    public function shouldBuffer($buffer)
44
-    {
45
-        if ('' === $buffer) {
46
-            return false;
47
-        }
36
+	/**
37
+	 * Returns true if based on the buffer passed more bytes should be buffered.
38
+	 *
39
+	 * @param string $buffer
40
+	 *
41
+	 * @return bool
42
+	 */
43
+	public function shouldBuffer($buffer)
44
+	{
45
+		if ('' === $buffer) {
46
+			return false;
47
+		}
48 48
 
49
-        $endOfBuffer = substr($buffer, -1);
50
-        foreach ((array) $this->search as $needle) {
51
-            if (false !== strpos($needle, $endOfBuffer)) {
52
-                return true;
53
-            }
54
-        }
49
+		$endOfBuffer = substr($buffer, -1);
50
+		foreach ((array) $this->search as $needle) {
51
+			if (false !== strpos($needle, $endOfBuffer)) {
52
+				return true;
53
+			}
54
+		}
55 55
 
56
-        return false;
57
-    }
56
+		return false;
57
+	}
58 58
 
59
-    /**
60
-     * Perform the actual replacements on $buffer and return the result.
61
-     *
62
-     * @param string $buffer
63
-     *
64
-     * @return string
65
-     */
66
-    public function filter($buffer)
67
-    {
68
-        return str_replace($this->search, $this->replace, $buffer);
69
-    }
59
+	/**
60
+	 * Perform the actual replacements on $buffer and return the result.
61
+	 *
62
+	 * @param string $buffer
63
+	 *
64
+	 * @return string
65
+	 */
66
+	public function filter($buffer)
67
+	{
68
+		return str_replace($this->search, $this->replace, $buffer);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
swiftmailer/lib/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -17,150 +17,150 @@
 block discarded – undo
17 17
  */
18 18
 class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilter
19 19
 {
20
-    /** The replacement(s) to make */
21
-    private $replace;
20
+	/** The replacement(s) to make */
21
+	private $replace;
22 22
 
23
-    /** The Index for searching */
24
-    private $index;
23
+	/** The Index for searching */
24
+	private $index;
25 25
 
26
-    /** The Search Tree */
27
-    private $tree = [];
26
+	/** The Search Tree */
27
+	private $tree = [];
28 28
 
29
-    /**  Gives the size of the largest search */
30
-    private $treeMaxLen = 0;
29
+	/**  Gives the size of the largest search */
30
+	private $treeMaxLen = 0;
31 31
 
32
-    private $repSize;
32
+	private $repSize;
33 33
 
34
-    /**
35
-     * Create a new ByteArrayReplacementFilter with $search and $replace.
36
-     *
37
-     * @param array $search
38
-     * @param array $replace
39
-     */
40
-    public function __construct($search, $replace)
41
-    {
42
-        $this->index = [];
43
-        $this->tree = [];
44
-        $this->replace = [];
45
-        $this->repSize = [];
34
+	/**
35
+	 * Create a new ByteArrayReplacementFilter with $search and $replace.
36
+	 *
37
+	 * @param array $search
38
+	 * @param array $replace
39
+	 */
40
+	public function __construct($search, $replace)
41
+	{
42
+		$this->index = [];
43
+		$this->tree = [];
44
+		$this->replace = [];
45
+		$this->repSize = [];
46 46
 
47
-        $tree = null;
48
-        $i = null;
49
-        $last_size = $size = 0;
50
-        foreach ($search as $i => $search_element) {
51
-            if (null !== $tree) {
52
-                $tree[-1] = min(\count($replace) - 1, $i - 1);
53
-                $tree[-2] = $last_size;
54
-            }
55
-            $tree = &$this->tree;
56
-            if (\is_array($search_element)) {
57
-                foreach ($search_element as $k => $char) {
58
-                    $this->index[$char] = true;
59
-                    if (!isset($tree[$char])) {
60
-                        $tree[$char] = [];
61
-                    }
62
-                    $tree = &$tree[$char];
63
-                }
64
-                $last_size = $k + 1;
65
-                $size = max($size, $last_size);
66
-            } else {
67
-                $last_size = 1;
68
-                if (!isset($tree[$search_element])) {
69
-                    $tree[$search_element] = [];
70
-                }
71
-                $tree = &$tree[$search_element];
72
-                $size = max($last_size, $size);
73
-                $this->index[$search_element] = true;
74
-            }
75
-        }
76
-        if (null !== $i) {
77
-            $tree[-1] = min(\count($replace) - 1, $i);
78
-            $tree[-2] = $last_size;
79
-            $this->treeMaxLen = $size;
80
-        }
81
-        foreach ($replace as $rep) {
82
-            if (!\is_array($rep)) {
83
-                $rep = [$rep];
84
-            }
85
-            $this->replace[] = $rep;
86
-        }
87
-        for ($i = \count($this->replace) - 1; $i >= 0; --$i) {
88
-            $this->replace[$i] = $rep = $this->filter($this->replace[$i], $i);
89
-            $this->repSize[$i] = \count($rep);
90
-        }
91
-    }
47
+		$tree = null;
48
+		$i = null;
49
+		$last_size = $size = 0;
50
+		foreach ($search as $i => $search_element) {
51
+			if (null !== $tree) {
52
+				$tree[-1] = min(\count($replace) - 1, $i - 1);
53
+				$tree[-2] = $last_size;
54
+			}
55
+			$tree = &$this->tree;
56
+			if (\is_array($search_element)) {
57
+				foreach ($search_element as $k => $char) {
58
+					$this->index[$char] = true;
59
+					if (!isset($tree[$char])) {
60
+						$tree[$char] = [];
61
+					}
62
+					$tree = &$tree[$char];
63
+				}
64
+				$last_size = $k + 1;
65
+				$size = max($size, $last_size);
66
+			} else {
67
+				$last_size = 1;
68
+				if (!isset($tree[$search_element])) {
69
+					$tree[$search_element] = [];
70
+				}
71
+				$tree = &$tree[$search_element];
72
+				$size = max($last_size, $size);
73
+				$this->index[$search_element] = true;
74
+			}
75
+		}
76
+		if (null !== $i) {
77
+			$tree[-1] = min(\count($replace) - 1, $i);
78
+			$tree[-2] = $last_size;
79
+			$this->treeMaxLen = $size;
80
+		}
81
+		foreach ($replace as $rep) {
82
+			if (!\is_array($rep)) {
83
+				$rep = [$rep];
84
+			}
85
+			$this->replace[] = $rep;
86
+		}
87
+		for ($i = \count($this->replace) - 1; $i >= 0; --$i) {
88
+			$this->replace[$i] = $rep = $this->filter($this->replace[$i], $i);
89
+			$this->repSize[$i] = \count($rep);
90
+		}
91
+	}
92 92
 
93
-    /**
94
-     * Returns true if based on the buffer passed more bytes should be buffered.
95
-     *
96
-     * @param array $buffer
97
-     *
98
-     * @return bool
99
-     */
100
-    public function shouldBuffer($buffer)
101
-    {
102
-        $endOfBuffer = end($buffer);
93
+	/**
94
+	 * Returns true if based on the buffer passed more bytes should be buffered.
95
+	 *
96
+	 * @param array $buffer
97
+	 *
98
+	 * @return bool
99
+	 */
100
+	public function shouldBuffer($buffer)
101
+	{
102
+		$endOfBuffer = end($buffer);
103 103
 
104
-        return isset($this->index[$endOfBuffer]);
105
-    }
104
+		return isset($this->index[$endOfBuffer]);
105
+	}
106 106
 
107
-    /**
108
-     * Perform the actual replacements on $buffer and return the result.
109
-     *
110
-     * @param array $buffer
111
-     * @param int   $minReplaces
112
-     *
113
-     * @return array
114
-     */
115
-    public function filter($buffer, $minReplaces = -1)
116
-    {
117
-        if (0 == $this->treeMaxLen) {
118
-            return $buffer;
119
-        }
107
+	/**
108
+	 * Perform the actual replacements on $buffer and return the result.
109
+	 *
110
+	 * @param array $buffer
111
+	 * @param int   $minReplaces
112
+	 *
113
+	 * @return array
114
+	 */
115
+	public function filter($buffer, $minReplaces = -1)
116
+	{
117
+		if (0 == $this->treeMaxLen) {
118
+			return $buffer;
119
+		}
120 120
 
121
-        $newBuffer = [];
122
-        $buf_size = \count($buffer);
123
-        $last_size = 0;
124
-        for ($i = 0; $i < $buf_size; ++$i) {
125
-            $search_pos = $this->tree;
126
-            $last_found = PHP_INT_MAX;
127
-            // We try to find if the next byte is part of a search pattern
128
-            for ($j = 0; $j <= $this->treeMaxLen; ++$j) {
129
-                // We have a new byte for a search pattern
130
-                if (isset($buffer[$p = $i + $j]) && isset($search_pos[$buffer[$p]])) {
131
-                    $search_pos = $search_pos[$buffer[$p]];
132
-                    // We have a complete pattern, save, in case we don't find a better match later
133
-                    if (isset($search_pos[-1]) && $search_pos[-1] < $last_found
134
-                        && $search_pos[-1] > $minReplaces) {
135
-                        $last_found = $search_pos[-1];
136
-                        $last_size = $search_pos[-2];
137
-                    }
138
-                }
139
-                // We got a complete pattern
140
-                elseif (PHP_INT_MAX !== $last_found) {
141
-                    // Adding replacement datas to output buffer
142
-                    $rep_size = $this->repSize[$last_found];
143
-                    for ($j = 0; $j < $rep_size; ++$j) {
144
-                        $newBuffer[] = $this->replace[$last_found][$j];
145
-                    }
146
-                    // We Move cursor forward
147
-                    $i += $last_size - 1;
148
-                    // Edge Case, last position in buffer
149
-                    if ($i >= $buf_size) {
150
-                        $newBuffer[] = $buffer[$i];
151
-                    }
121
+		$newBuffer = [];
122
+		$buf_size = \count($buffer);
123
+		$last_size = 0;
124
+		for ($i = 0; $i < $buf_size; ++$i) {
125
+			$search_pos = $this->tree;
126
+			$last_found = PHP_INT_MAX;
127
+			// We try to find if the next byte is part of a search pattern
128
+			for ($j = 0; $j <= $this->treeMaxLen; ++$j) {
129
+				// We have a new byte for a search pattern
130
+				if (isset($buffer[$p = $i + $j]) && isset($search_pos[$buffer[$p]])) {
131
+					$search_pos = $search_pos[$buffer[$p]];
132
+					// We have a complete pattern, save, in case we don't find a better match later
133
+					if (isset($search_pos[-1]) && $search_pos[-1] < $last_found
134
+						&& $search_pos[-1] > $minReplaces) {
135
+						$last_found = $search_pos[-1];
136
+						$last_size = $search_pos[-2];
137
+					}
138
+				}
139
+				// We got a complete pattern
140
+				elseif (PHP_INT_MAX !== $last_found) {
141
+					// Adding replacement datas to output buffer
142
+					$rep_size = $this->repSize[$last_found];
143
+					for ($j = 0; $j < $rep_size; ++$j) {
144
+						$newBuffer[] = $this->replace[$last_found][$j];
145
+					}
146
+					// We Move cursor forward
147
+					$i += $last_size - 1;
148
+					// Edge Case, last position in buffer
149
+					if ($i >= $buf_size) {
150
+						$newBuffer[] = $buffer[$i];
151
+					}
152 152
 
153
-                    // We start the next loop
154
-                    continue 2;
155
-                } else {
156
-                    // this byte is not in a pattern and we haven't found another pattern
157
-                    break;
158
-                }
159
-            }
160
-            // Normal byte, move it to output buffer
161
-            $newBuffer[] = $buffer[$i];
162
-        }
153
+					// We start the next loop
154
+					continue 2;
155
+				} else {
156
+					// this byte is not in a pattern and we haven't found another pattern
157
+					break;
158
+				}
159
+			}
160
+			// Normal byte, move it to output buffer
161
+			$newBuffer[] = $buffer[$i];
162
+		}
163 163
 
164
-        return $newBuffer;
165
-    }
164
+		return $newBuffer;
165
+	}
166 166
 }
Please login to merge, or discard this patch.
lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_StreamFilters_StringReplacementFilterFactory implements Swift_ReplacementFilterFactory
17 17
 {
18
-    /** Lazy-loaded filters */
19
-    private $filters = [];
18
+	/** Lazy-loaded filters */
19
+	private $filters = [];
20 20
 
21
-    /**
22
-     * Create a new StreamFilter to replace $search with $replace in a string.
23
-     *
24
-     * @param string $search
25
-     * @param string $replace
26
-     *
27
-     * @return Swift_StreamFilter
28
-     */
29
-    public function createFilter($search, $replace)
30
-    {
31
-        if (!isset($this->filters[$search][$replace])) {
32
-            if (!isset($this->filters[$search])) {
33
-                $this->filters[$search] = [];
34
-            }
21
+	/**
22
+	 * Create a new StreamFilter to replace $search with $replace in a string.
23
+	 *
24
+	 * @param string $search
25
+	 * @param string $replace
26
+	 *
27
+	 * @return Swift_StreamFilter
28
+	 */
29
+	public function createFilter($search, $replace)
30
+	{
31
+		if (!isset($this->filters[$search][$replace])) {
32
+			if (!isset($this->filters[$search])) {
33
+				$this->filters[$search] = [];
34
+			}
35 35
 
36
-            if (!isset($this->filters[$search][$replace])) {
37
-                $this->filters[$search][$replace] = [];
38
-            }
36
+			if (!isset($this->filters[$search][$replace])) {
37
+				$this->filters[$search][$replace] = [];
38
+			}
39 39
 
40
-            $this->filters[$search][$replace] = new Swift_StreamFilters_StringReplacementFilter($search, $replace);
41
-        }
40
+			$this->filters[$search][$replace] = new Swift_StreamFilters_StringReplacementFilter($search, $replace);
41
+		}
42 42
 
43
-        return $this->filters[$search][$replace];
44
-    }
43
+		return $this->filters[$search][$replace];
44
+	}
45 45
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Filterable.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,17 +15,17 @@
 block discarded – undo
15 15
  */
16 16
 interface Swift_Filterable
17 17
 {
18
-    /**
19
-     * Add a new StreamFilter, referenced by $key.
20
-     *
21
-     * @param string $key
22
-     */
23
-    public function addFilter(Swift_StreamFilter $filter, $key);
18
+	/**
19
+	 * Add a new StreamFilter, referenced by $key.
20
+	 *
21
+	 * @param string $key
22
+	 */
23
+	public function addFilter(Swift_StreamFilter $filter, $key);
24 24
 
25
-    /**
26
-     * Remove an existing filter using $key.
27
-     *
28
-     * @param string $key
29
-     */
30
-    public function removeFilter($key);
25
+	/**
26
+	 * Remove an existing filter using $key.
27
+	 *
28
+	 * @param string $key
29
+	 */
30
+	public function removeFilter($key);
31 31
 }
Please login to merge, or discard this patch.
htdocs/includes/swiftmailer/lib/classes/Swift/Message.php 1 patch
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -15,265 +15,265 @@
 block discarded – undo
15 15
  */
16 16
 class Swift_Message extends Swift_Mime_SimpleMessage
17 17
 {
18
-    /**
19
-     * @var Swift_Signers_HeaderSigner[]
20
-     */
21
-    private $headerSigners = [];
22
-
23
-    /**
24
-     * @var Swift_Signers_BodySigner[]
25
-     */
26
-    private $bodySigners = [];
27
-
28
-    /**
29
-     * @var array
30
-     */
31
-    private $savedMessage = [];
32
-
33
-    /**
34
-     * Create a new Message.
35
-     *
36
-     * Details may be optionally passed into the constructor.
37
-     *
38
-     * @param string $subject
39
-     * @param string $body
40
-     * @param string $contentType
41
-     * @param string $charset
42
-     */
43
-    public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
44
-    {
45
-        \call_user_func_array(
46
-            [$this, 'Swift_Mime_SimpleMessage::__construct'],
47
-            Swift_DependencyContainer::getInstance()
48
-                ->createDependenciesFor('mime.message')
49
-            );
50
-
51
-        if (!isset($charset)) {
52
-            $charset = Swift_DependencyContainer::getInstance()
53
-                ->lookup('properties.charset');
54
-        }
55
-        $this->setSubject($subject);
56
-        $this->setBody($body);
57
-        $this->setCharset($charset);
58
-        if ($contentType) {
59
-            $this->setContentType($contentType);
60
-        }
61
-    }
62
-
63
-    /**
64
-     * Add a MimePart to this Message.
65
-     *
66
-     * @param string|Swift_OutputByteStream $body
67
-     * @param string                        $contentType
68
-     * @param string                        $charset
69
-     *
70
-     * @return $this
71
-     */
72
-    public function addPart($body, $contentType = null, $charset = null)
73
-    {
74
-        return $this->attach((new Swift_MimePart($body, $contentType, $charset))->setEncoder($this->getEncoder()));
75
-    }
76
-
77
-    /**
78
-     * Attach a new signature handler to the message.
79
-     *
80
-     * @return $this
81
-     */
82
-    public function attachSigner(Swift_Signer $signer)
83
-    {
84
-        if ($signer instanceof Swift_Signers_HeaderSigner) {
85
-            $this->headerSigners[] = $signer;
86
-        } elseif ($signer instanceof Swift_Signers_BodySigner) {
87
-            $this->bodySigners[] = $signer;
88
-        }
89
-
90
-        return $this;
91
-    }
92
-
93
-    /**
94
-     * Detach a signature handler from a message.
95
-     *
96
-     * @return $this
97
-     */
98
-    public function detachSigner(Swift_Signer $signer)
99
-    {
100
-        if ($signer instanceof Swift_Signers_HeaderSigner) {
101
-            foreach ($this->headerSigners as $k => $headerSigner) {
102
-                if ($headerSigner === $signer) {
103
-                    unset($this->headerSigners[$k]);
104
-
105
-                    return $this;
106
-                }
107
-            }
108
-        } elseif ($signer instanceof Swift_Signers_BodySigner) {
109
-            foreach ($this->bodySigners as $k => $bodySigner) {
110
-                if ($bodySigner === $signer) {
111
-                    unset($this->bodySigners[$k]);
112
-
113
-                    return $this;
114
-                }
115
-            }
116
-        }
117
-
118
-        return $this;
119
-    }
120
-
121
-    /**
122
-     * Clear all signature handlers attached to the message.
123
-     *
124
-     * @return $this
125
-     */
126
-    public function clearSigners()
127
-    {
128
-        $this->headerSigners = [];
129
-        $this->bodySigners = [];
130
-
131
-        return $this;
132
-    }
133
-
134
-    /**
135
-     * Get this message as a complete string.
136
-     *
137
-     * @return string
138
-     */
139
-    public function toString()
140
-    {
141
-        if (empty($this->headerSigners) && empty($this->bodySigners)) {
142
-            return parent::toString();
143
-        }
144
-
145
-        $this->saveMessage();
146
-
147
-        $this->doSign();
148
-
149
-        $string = parent::toString();
150
-
151
-        $this->restoreMessage();
152
-
153
-        return $string;
154
-    }
155
-
156
-    /**
157
-     * Write this message to a {@link Swift_InputByteStream}.
158
-     */
159
-    public function toByteStream(Swift_InputByteStream $is)
160
-    {
161
-        if (empty($this->headerSigners) && empty($this->bodySigners)) {
162
-            parent::toByteStream($is);
163
-
164
-            return;
165
-        }
166
-
167
-        $this->saveMessage();
168
-
169
-        $this->doSign();
170
-
171
-        parent::toByteStream($is);
172
-
173
-        $this->restoreMessage();
174
-    }
175
-
176
-    public function __wakeup()
177
-    {
178
-        Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
179
-    }
180
-
181
-    /**
182
-     * loops through signers and apply the signatures.
183
-     */
184
-    protected function doSign()
185
-    {
186
-        foreach ($this->bodySigners as $signer) {
187
-            $altered = $signer->getAlteredHeaders();
188
-            $this->saveHeaders($altered);
189
-            $signer->signMessage($this);
190
-        }
191
-
192
-        foreach ($this->headerSigners as $signer) {
193
-            $altered = $signer->getAlteredHeaders();
194
-            $this->saveHeaders($altered);
195
-            $signer->reset();
196
-
197
-            $signer->setHeaders($this->getHeaders());
198
-
199
-            $signer->startBody();
200
-            $this->bodyToByteStream($signer);
201
-            $signer->endBody();
202
-
203
-            $signer->addSignature($this->getHeaders());
204
-        }
205
-    }
206
-
207
-    /**
208
-     * save the message before any signature is applied.
209
-     */
210
-    protected function saveMessage()
211
-    {
212
-        $this->savedMessage = ['headers' => []];
213
-        $this->savedMessage['body'] = $this->getBody();
214
-        $this->savedMessage['children'] = $this->getChildren();
215
-        if (\count($this->savedMessage['children']) > 0 && '' != $this->getBody()) {
216
-            $this->setChildren(array_merge([$this->becomeMimePart()], $this->savedMessage['children']));
217
-            $this->setBody('');
218
-        }
219
-    }
220
-
221
-    /**
222
-     * save the original headers.
223
-     */
224
-    protected function saveHeaders(array $altered)
225
-    {
226
-        foreach ($altered as $head) {
227
-            $lc = strtolower($head ?? '');
228
-
229
-            if (!isset($this->savedMessage['headers'][$lc])) {
230
-                $this->savedMessage['headers'][$lc] = $this->getHeaders()->getAll($head);
231
-            }
232
-        }
233
-    }
234
-
235
-    /**
236
-     * Remove or restore altered headers.
237
-     */
238
-    protected function restoreHeaders()
239
-    {
240
-        foreach ($this->savedMessage['headers'] as $name => $savedValue) {
241
-            $headers = $this->getHeaders()->getAll($name);
242
-
243
-            foreach ($headers as $key => $value) {
244
-                if (!isset($savedValue[$key])) {
245
-                    $this->getHeaders()->remove($name, $key);
246
-                }
247
-            }
248
-        }
249
-    }
250
-
251
-    /**
252
-     * Restore message body.
253
-     */
254
-    protected function restoreMessage()
255
-    {
256
-        $this->setBody($this->savedMessage['body']);
257
-        $this->setChildren($this->savedMessage['children']);
258
-
259
-        $this->restoreHeaders();
260
-        $this->savedMessage = [];
261
-    }
262
-
263
-    /**
264
-     * Clone Message Signers.
265
-     *
266
-     * @see Swift_Mime_SimpleMimeEntity::__clone()
267
-     */
268
-    public function __clone()
269
-    {
270
-        parent::__clone();
271
-        foreach ($this->bodySigners as $key => $bodySigner) {
272
-            $this->bodySigners[$key] = clone $bodySigner;
273
-        }
274
-
275
-        foreach ($this->headerSigners as $key => $headerSigner) {
276
-            $this->headerSigners[$key] = clone $headerSigner;
277
-        }
278
-    }
18
+	/**
19
+	 * @var Swift_Signers_HeaderSigner[]
20
+	 */
21
+	private $headerSigners = [];
22
+
23
+	/**
24
+	 * @var Swift_Signers_BodySigner[]
25
+	 */
26
+	private $bodySigners = [];
27
+
28
+	/**
29
+	 * @var array
30
+	 */
31
+	private $savedMessage = [];
32
+
33
+	/**
34
+	 * Create a new Message.
35
+	 *
36
+	 * Details may be optionally passed into the constructor.
37
+	 *
38
+	 * @param string $subject
39
+	 * @param string $body
40
+	 * @param string $contentType
41
+	 * @param string $charset
42
+	 */
43
+	public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
44
+	{
45
+		\call_user_func_array(
46
+			[$this, 'Swift_Mime_SimpleMessage::__construct'],
47
+			Swift_DependencyContainer::getInstance()
48
+				->createDependenciesFor('mime.message')
49
+			);
50
+
51
+		if (!isset($charset)) {
52
+			$charset = Swift_DependencyContainer::getInstance()
53
+				->lookup('properties.charset');
54
+		}
55
+		$this->setSubject($subject);
56
+		$this->setBody($body);
57
+		$this->setCharset($charset);
58
+		if ($contentType) {
59
+			$this->setContentType($contentType);
60
+		}
61
+	}
62
+
63
+	/**
64
+	 * Add a MimePart to this Message.
65
+	 *
66
+	 * @param string|Swift_OutputByteStream $body
67
+	 * @param string                        $contentType
68
+	 * @param string                        $charset
69
+	 *
70
+	 * @return $this
71
+	 */
72
+	public function addPart($body, $contentType = null, $charset = null)
73
+	{
74
+		return $this->attach((new Swift_MimePart($body, $contentType, $charset))->setEncoder($this->getEncoder()));
75
+	}
76
+
77
+	/**
78
+	 * Attach a new signature handler to the message.
79
+	 *
80
+	 * @return $this
81
+	 */
82
+	public function attachSigner(Swift_Signer $signer)
83
+	{
84
+		if ($signer instanceof Swift_Signers_HeaderSigner) {
85
+			$this->headerSigners[] = $signer;
86
+		} elseif ($signer instanceof Swift_Signers_BodySigner) {
87
+			$this->bodySigners[] = $signer;
88
+		}
89
+
90
+		return $this;
91
+	}
92
+
93
+	/**
94
+	 * Detach a signature handler from a message.
95
+	 *
96
+	 * @return $this
97
+	 */
98
+	public function detachSigner(Swift_Signer $signer)
99
+	{
100
+		if ($signer instanceof Swift_Signers_HeaderSigner) {
101
+			foreach ($this->headerSigners as $k => $headerSigner) {
102
+				if ($headerSigner === $signer) {
103
+					unset($this->headerSigners[$k]);
104
+
105
+					return $this;
106
+				}
107
+			}
108
+		} elseif ($signer instanceof Swift_Signers_BodySigner) {
109
+			foreach ($this->bodySigners as $k => $bodySigner) {
110
+				if ($bodySigner === $signer) {
111
+					unset($this->bodySigners[$k]);
112
+
113
+					return $this;
114
+				}
115
+			}
116
+		}
117
+
118
+		return $this;
119
+	}
120
+
121
+	/**
122
+	 * Clear all signature handlers attached to the message.
123
+	 *
124
+	 * @return $this
125
+	 */
126
+	public function clearSigners()
127
+	{
128
+		$this->headerSigners = [];
129
+		$this->bodySigners = [];
130
+
131
+		return $this;
132
+	}
133
+
134
+	/**
135
+	 * Get this message as a complete string.
136
+	 *
137
+	 * @return string
138
+	 */
139
+	public function toString()
140
+	{
141
+		if (empty($this->headerSigners) && empty($this->bodySigners)) {
142
+			return parent::toString();
143
+		}
144
+
145
+		$this->saveMessage();
146
+
147
+		$this->doSign();
148
+
149
+		$string = parent::toString();
150
+
151
+		$this->restoreMessage();
152
+
153
+		return $string;
154
+	}
155
+
156
+	/**
157
+	 * Write this message to a {@link Swift_InputByteStream}.
158
+	 */
159
+	public function toByteStream(Swift_InputByteStream $is)
160
+	{
161
+		if (empty($this->headerSigners) && empty($this->bodySigners)) {
162
+			parent::toByteStream($is);
163
+
164
+			return;
165
+		}
166
+
167
+		$this->saveMessage();
168
+
169
+		$this->doSign();
170
+
171
+		parent::toByteStream($is);
172
+
173
+		$this->restoreMessage();
174
+	}
175
+
176
+	public function __wakeup()
177
+	{
178
+		Swift_DependencyContainer::getInstance()->createDependenciesFor('mime.message');
179
+	}
180
+
181
+	/**
182
+	 * loops through signers and apply the signatures.
183
+	 */
184
+	protected function doSign()
185
+	{
186
+		foreach ($this->bodySigners as $signer) {
187
+			$altered = $signer->getAlteredHeaders();
188
+			$this->saveHeaders($altered);
189
+			$signer->signMessage($this);
190
+		}
191
+
192
+		foreach ($this->headerSigners as $signer) {
193
+			$altered = $signer->getAlteredHeaders();
194
+			$this->saveHeaders($altered);
195
+			$signer->reset();
196
+
197
+			$signer->setHeaders($this->getHeaders());
198
+
199
+			$signer->startBody();
200
+			$this->bodyToByteStream($signer);
201
+			$signer->endBody();
202
+
203
+			$signer->addSignature($this->getHeaders());
204
+		}
205
+	}
206
+
207
+	/**
208
+	 * save the message before any signature is applied.
209
+	 */
210
+	protected function saveMessage()
211
+	{
212
+		$this->savedMessage = ['headers' => []];
213
+		$this->savedMessage['body'] = $this->getBody();
214
+		$this->savedMessage['children'] = $this->getChildren();
215
+		if (\count($this->savedMessage['children']) > 0 && '' != $this->getBody()) {
216
+			$this->setChildren(array_merge([$this->becomeMimePart()], $this->savedMessage['children']));
217
+			$this->setBody('');
218
+		}
219
+	}
220
+
221
+	/**
222
+	 * save the original headers.
223
+	 */
224
+	protected function saveHeaders(array $altered)
225
+	{
226
+		foreach ($altered as $head) {
227
+			$lc = strtolower($head ?? '');
228
+
229
+			if (!isset($this->savedMessage['headers'][$lc])) {
230
+				$this->savedMessage['headers'][$lc] = $this->getHeaders()->getAll($head);
231
+			}
232
+		}
233
+	}
234
+
235
+	/**
236
+	 * Remove or restore altered headers.
237
+	 */
238
+	protected function restoreHeaders()
239
+	{
240
+		foreach ($this->savedMessage['headers'] as $name => $savedValue) {
241
+			$headers = $this->getHeaders()->getAll($name);
242
+
243
+			foreach ($headers as $key => $value) {
244
+				if (!isset($savedValue[$key])) {
245
+					$this->getHeaders()->remove($name, $key);
246
+				}
247
+			}
248
+		}
249
+	}
250
+
251
+	/**
252
+	 * Restore message body.
253
+	 */
254
+	protected function restoreMessage()
255
+	{
256
+		$this->setBody($this->savedMessage['body']);
257
+		$this->setChildren($this->savedMessage['children']);
258
+
259
+		$this->restoreHeaders();
260
+		$this->savedMessage = [];
261
+	}
262
+
263
+	/**
264
+	 * Clone Message Signers.
265
+	 *
266
+	 * @see Swift_Mime_SimpleMimeEntity::__clone()
267
+	 */
268
+	public function __clone()
269
+	{
270
+		parent::__clone();
271
+		foreach ($this->bodySigners as $key => $bodySigner) {
272
+			$this->bodySigners[$key] = clone $bodySigner;
273
+		}
274
+
275
+		foreach ($this->headerSigners as $key => $headerSigner) {
276
+			$this->headerSigners[$key] = clone $headerSigner;
277
+		}
278
+	}
279 279
 }
Please login to merge, or discard this patch.