@@ -15,99 +15,99 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_KeyCache_NullKeyCache implements Swift_KeyCache |
17 | 17 | { |
18 | - /** |
|
19 | - * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
20 | - * |
|
21 | - * @see MODE_WRITE, MODE_APPEND |
|
22 | - * |
|
23 | - * @param string $nsKey |
|
24 | - * @param string $itemKey |
|
25 | - * @param string $string |
|
26 | - * @param int $mode |
|
27 | - */ |
|
28 | - public function setString($nsKey, $itemKey, $string, $mode) |
|
29 | - { |
|
30 | - } |
|
18 | + /** |
|
19 | + * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
20 | + * |
|
21 | + * @see MODE_WRITE, MODE_APPEND |
|
22 | + * |
|
23 | + * @param string $nsKey |
|
24 | + * @param string $itemKey |
|
25 | + * @param string $string |
|
26 | + * @param int $mode |
|
27 | + */ |
|
28 | + public function setString($nsKey, $itemKey, $string, $mode) |
|
29 | + { |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
34 | - * |
|
35 | - * @see MODE_WRITE, MODE_APPEND |
|
36 | - * |
|
37 | - * @param string $nsKey |
|
38 | - * @param string $itemKey |
|
39 | - * @param int $mode |
|
40 | - */ |
|
41 | - public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
42 | - { |
|
43 | - } |
|
32 | + /** |
|
33 | + * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
34 | + * |
|
35 | + * @see MODE_WRITE, MODE_APPEND |
|
36 | + * |
|
37 | + * @param string $nsKey |
|
38 | + * @param string $itemKey |
|
39 | + * @param int $mode |
|
40 | + */ |
|
41 | + public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
42 | + { |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Provides a ByteStream which when written to, writes data to $itemKey. |
|
47 | - * |
|
48 | - * NOTE: The stream will always write in append mode. |
|
49 | - * |
|
50 | - * @param string $nsKey |
|
51 | - * @param string $itemKey |
|
52 | - * |
|
53 | - * @return Swift_InputByteStream |
|
54 | - */ |
|
55 | - public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
56 | - { |
|
57 | - } |
|
45 | + /** |
|
46 | + * Provides a ByteStream which when written to, writes data to $itemKey. |
|
47 | + * |
|
48 | + * NOTE: The stream will always write in append mode. |
|
49 | + * |
|
50 | + * @param string $nsKey |
|
51 | + * @param string $itemKey |
|
52 | + * |
|
53 | + * @return Swift_InputByteStream |
|
54 | + */ |
|
55 | + public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
56 | + { |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Get data back out of the cache as a string. |
|
61 | - * |
|
62 | - * @param string $nsKey |
|
63 | - * @param string $itemKey |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getString($nsKey, $itemKey) |
|
68 | - { |
|
69 | - } |
|
59 | + /** |
|
60 | + * Get data back out of the cache as a string. |
|
61 | + * |
|
62 | + * @param string $nsKey |
|
63 | + * @param string $itemKey |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getString($nsKey, $itemKey) |
|
68 | + { |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get data back out of the cache as a ByteStream. |
|
73 | - * |
|
74 | - * @param string $nsKey |
|
75 | - * @param string $itemKey |
|
76 | - * @param Swift_InputByteStream $is to write the data to |
|
77 | - */ |
|
78 | - public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
79 | - { |
|
80 | - } |
|
71 | + /** |
|
72 | + * Get data back out of the cache as a ByteStream. |
|
73 | + * |
|
74 | + * @param string $nsKey |
|
75 | + * @param string $itemKey |
|
76 | + * @param Swift_InputByteStream $is to write the data to |
|
77 | + */ |
|
78 | + public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
79 | + { |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Check if the given $itemKey exists in the namespace $nsKey. |
|
84 | - * |
|
85 | - * @param string $nsKey |
|
86 | - * @param string $itemKey |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function hasKey($nsKey, $itemKey) |
|
91 | - { |
|
92 | - return false; |
|
93 | - } |
|
82 | + /** |
|
83 | + * Check if the given $itemKey exists in the namespace $nsKey. |
|
84 | + * |
|
85 | + * @param string $nsKey |
|
86 | + * @param string $itemKey |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function hasKey($nsKey, $itemKey) |
|
91 | + { |
|
92 | + return false; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
97 | - * |
|
98 | - * @param string $nsKey |
|
99 | - * @param string $itemKey |
|
100 | - */ |
|
101 | - public function clearKey($nsKey, $itemKey) |
|
102 | - { |
|
103 | - } |
|
95 | + /** |
|
96 | + * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
97 | + * |
|
98 | + * @param string $nsKey |
|
99 | + * @param string $itemKey |
|
100 | + */ |
|
101 | + public function clearKey($nsKey, $itemKey) |
|
102 | + { |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Clear all data in the namespace $nsKey if it exists. |
|
107 | - * |
|
108 | - * @param string $nsKey |
|
109 | - */ |
|
110 | - public function clearAll($nsKey) |
|
111 | - { |
|
112 | - } |
|
105 | + /** |
|
106 | + * Clear all data in the namespace $nsKey if it exists. |
|
107 | + * |
|
108 | + * @param string $nsKey |
|
109 | + */ |
|
110 | + public function clearAll($nsKey) |
|
111 | + { |
|
112 | + } |
|
113 | 113 | } |
@@ -15,183 +15,183 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache |
17 | 17 | { |
18 | - /** |
|
19 | - * Cache contents. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - private $contents = []; |
|
18 | + /** |
|
19 | + * Cache contents. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + private $contents = []; |
|
24 | 24 | |
25 | - /** |
|
26 | - * An InputStream for cloning. |
|
27 | - * |
|
28 | - * @var Swift_KeyCache_KeyCacheInputStream |
|
29 | - */ |
|
30 | - private $stream; |
|
25 | + /** |
|
26 | + * An InputStream for cloning. |
|
27 | + * |
|
28 | + * @var Swift_KeyCache_KeyCacheInputStream |
|
29 | + */ |
|
30 | + private $stream; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Create a new ArrayKeyCache with the given $stream for cloning to make |
|
34 | - * InputByteStreams. |
|
35 | - */ |
|
36 | - public function __construct(Swift_KeyCache_KeyCacheInputStream $stream) |
|
37 | - { |
|
38 | - $this->stream = $stream; |
|
39 | - } |
|
32 | + /** |
|
33 | + * Create a new ArrayKeyCache with the given $stream for cloning to make |
|
34 | + * InputByteStreams. |
|
35 | + */ |
|
36 | + public function __construct(Swift_KeyCache_KeyCacheInputStream $stream) |
|
37 | + { |
|
38 | + $this->stream = $stream; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
43 | - * |
|
44 | - * @see MODE_WRITE, MODE_APPEND |
|
45 | - * |
|
46 | - * @param string $nsKey |
|
47 | - * @param string $itemKey |
|
48 | - * @param string $string |
|
49 | - * @param int $mode |
|
50 | - */ |
|
51 | - public function setString($nsKey, $itemKey, $string, $mode) |
|
52 | - { |
|
53 | - $this->prepareCache($nsKey); |
|
54 | - switch ($mode) { |
|
55 | - case self::MODE_WRITE: |
|
56 | - $this->contents[$nsKey][$itemKey] = $string; |
|
57 | - break; |
|
58 | - case self::MODE_APPEND: |
|
59 | - if (!$this->hasKey($nsKey, $itemKey)) { |
|
60 | - $this->contents[$nsKey][$itemKey] = ''; |
|
61 | - } |
|
62 | - $this->contents[$nsKey][$itemKey] .= $string; |
|
63 | - break; |
|
64 | - default: |
|
65 | - throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
66 | - } |
|
67 | - } |
|
41 | + /** |
|
42 | + * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
43 | + * |
|
44 | + * @see MODE_WRITE, MODE_APPEND |
|
45 | + * |
|
46 | + * @param string $nsKey |
|
47 | + * @param string $itemKey |
|
48 | + * @param string $string |
|
49 | + * @param int $mode |
|
50 | + */ |
|
51 | + public function setString($nsKey, $itemKey, $string, $mode) |
|
52 | + { |
|
53 | + $this->prepareCache($nsKey); |
|
54 | + switch ($mode) { |
|
55 | + case self::MODE_WRITE: |
|
56 | + $this->contents[$nsKey][$itemKey] = $string; |
|
57 | + break; |
|
58 | + case self::MODE_APPEND: |
|
59 | + if (!$this->hasKey($nsKey, $itemKey)) { |
|
60 | + $this->contents[$nsKey][$itemKey] = ''; |
|
61 | + } |
|
62 | + $this->contents[$nsKey][$itemKey] .= $string; |
|
63 | + break; |
|
64 | + default: |
|
65 | + throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
71 | - * |
|
72 | - * @see MODE_WRITE, MODE_APPEND |
|
73 | - * |
|
74 | - * @param string $nsKey |
|
75 | - * @param string $itemKey |
|
76 | - * @param int $mode |
|
77 | - */ |
|
78 | - public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
79 | - { |
|
80 | - $this->prepareCache($nsKey); |
|
81 | - switch ($mode) { |
|
82 | - case self::MODE_WRITE: |
|
83 | - $this->clearKey($nsKey, $itemKey); |
|
84 | - // no break |
|
85 | - case self::MODE_APPEND: |
|
86 | - if (!$this->hasKey($nsKey, $itemKey)) { |
|
87 | - $this->contents[$nsKey][$itemKey] = ''; |
|
88 | - } |
|
89 | - while (false !== $bytes = $os->read(8192)) { |
|
90 | - $this->contents[$nsKey][$itemKey] .= $bytes; |
|
91 | - } |
|
92 | - break; |
|
93 | - default: |
|
94 | - throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
95 | - } |
|
96 | - } |
|
69 | + /** |
|
70 | + * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
71 | + * |
|
72 | + * @see MODE_WRITE, MODE_APPEND |
|
73 | + * |
|
74 | + * @param string $nsKey |
|
75 | + * @param string $itemKey |
|
76 | + * @param int $mode |
|
77 | + */ |
|
78 | + public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
79 | + { |
|
80 | + $this->prepareCache($nsKey); |
|
81 | + switch ($mode) { |
|
82 | + case self::MODE_WRITE: |
|
83 | + $this->clearKey($nsKey, $itemKey); |
|
84 | + // no break |
|
85 | + case self::MODE_APPEND: |
|
86 | + if (!$this->hasKey($nsKey, $itemKey)) { |
|
87 | + $this->contents[$nsKey][$itemKey] = ''; |
|
88 | + } |
|
89 | + while (false !== $bytes = $os->read(8192)) { |
|
90 | + $this->contents[$nsKey][$itemKey] .= $bytes; |
|
91 | + } |
|
92 | + break; |
|
93 | + default: |
|
94 | + throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Provides a ByteStream which when written to, writes data to $itemKey. |
|
100 | - * |
|
101 | - * NOTE: The stream will always write in append mode. |
|
102 | - * |
|
103 | - * @param string $nsKey |
|
104 | - * @param string $itemKey |
|
105 | - * |
|
106 | - * @return Swift_InputByteStream |
|
107 | - */ |
|
108 | - public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
109 | - { |
|
110 | - $is = clone $this->stream; |
|
111 | - $is->setKeyCache($this); |
|
112 | - $is->setNsKey($nsKey); |
|
113 | - $is->setItemKey($itemKey); |
|
114 | - if (isset($writeThrough)) { |
|
115 | - $is->setWriteThroughStream($writeThrough); |
|
116 | - } |
|
98 | + /** |
|
99 | + * Provides a ByteStream which when written to, writes data to $itemKey. |
|
100 | + * |
|
101 | + * NOTE: The stream will always write in append mode. |
|
102 | + * |
|
103 | + * @param string $nsKey |
|
104 | + * @param string $itemKey |
|
105 | + * |
|
106 | + * @return Swift_InputByteStream |
|
107 | + */ |
|
108 | + public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
109 | + { |
|
110 | + $is = clone $this->stream; |
|
111 | + $is->setKeyCache($this); |
|
112 | + $is->setNsKey($nsKey); |
|
113 | + $is->setItemKey($itemKey); |
|
114 | + if (isset($writeThrough)) { |
|
115 | + $is->setWriteThroughStream($writeThrough); |
|
116 | + } |
|
117 | 117 | |
118 | - return $is; |
|
119 | - } |
|
118 | + return $is; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Get data back out of the cache as a string. |
|
123 | - * |
|
124 | - * @param string $nsKey |
|
125 | - * @param string $itemKey |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getString($nsKey, $itemKey) |
|
130 | - { |
|
131 | - $this->prepareCache($nsKey); |
|
132 | - if ($this->hasKey($nsKey, $itemKey)) { |
|
133 | - return $this->contents[$nsKey][$itemKey]; |
|
134 | - } |
|
135 | - } |
|
121 | + /** |
|
122 | + * Get data back out of the cache as a string. |
|
123 | + * |
|
124 | + * @param string $nsKey |
|
125 | + * @param string $itemKey |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getString($nsKey, $itemKey) |
|
130 | + { |
|
131 | + $this->prepareCache($nsKey); |
|
132 | + if ($this->hasKey($nsKey, $itemKey)) { |
|
133 | + return $this->contents[$nsKey][$itemKey]; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Get data back out of the cache as a ByteStream. |
|
139 | - * |
|
140 | - * @param string $nsKey |
|
141 | - * @param string $itemKey |
|
142 | - * @param Swift_InputByteStream $is to write the data to |
|
143 | - */ |
|
144 | - public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
145 | - { |
|
146 | - $this->prepareCache($nsKey); |
|
147 | - $is->write($this->getString($nsKey, $itemKey)); |
|
148 | - } |
|
137 | + /** |
|
138 | + * Get data back out of the cache as a ByteStream. |
|
139 | + * |
|
140 | + * @param string $nsKey |
|
141 | + * @param string $itemKey |
|
142 | + * @param Swift_InputByteStream $is to write the data to |
|
143 | + */ |
|
144 | + public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
145 | + { |
|
146 | + $this->prepareCache($nsKey); |
|
147 | + $is->write($this->getString($nsKey, $itemKey)); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Check if the given $itemKey exists in the namespace $nsKey. |
|
152 | - * |
|
153 | - * @param string $nsKey |
|
154 | - * @param string $itemKey |
|
155 | - * |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - public function hasKey($nsKey, $itemKey) |
|
159 | - { |
|
160 | - $this->prepareCache($nsKey); |
|
150 | + /** |
|
151 | + * Check if the given $itemKey exists in the namespace $nsKey. |
|
152 | + * |
|
153 | + * @param string $nsKey |
|
154 | + * @param string $itemKey |
|
155 | + * |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + public function hasKey($nsKey, $itemKey) |
|
159 | + { |
|
160 | + $this->prepareCache($nsKey); |
|
161 | 161 | |
162 | - return \array_key_exists($itemKey, $this->contents[$nsKey]); |
|
163 | - } |
|
162 | + return \array_key_exists($itemKey, $this->contents[$nsKey]); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
167 | - * |
|
168 | - * @param string $nsKey |
|
169 | - * @param string $itemKey |
|
170 | - */ |
|
171 | - public function clearKey($nsKey, $itemKey) |
|
172 | - { |
|
173 | - unset($this->contents[$nsKey][$itemKey]); |
|
174 | - } |
|
165 | + /** |
|
166 | + * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
167 | + * |
|
168 | + * @param string $nsKey |
|
169 | + * @param string $itemKey |
|
170 | + */ |
|
171 | + public function clearKey($nsKey, $itemKey) |
|
172 | + { |
|
173 | + unset($this->contents[$nsKey][$itemKey]); |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Clear all data in the namespace $nsKey if it exists. |
|
178 | - * |
|
179 | - * @param string $nsKey |
|
180 | - */ |
|
181 | - public function clearAll($nsKey) |
|
182 | - { |
|
183 | - unset($this->contents[$nsKey]); |
|
184 | - } |
|
176 | + /** |
|
177 | + * Clear all data in the namespace $nsKey if it exists. |
|
178 | + * |
|
179 | + * @param string $nsKey |
|
180 | + */ |
|
181 | + public function clearAll($nsKey) |
|
182 | + { |
|
183 | + unset($this->contents[$nsKey]); |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Initialize the namespace of $nsKey if needed. |
|
188 | - * |
|
189 | - * @param string $nsKey |
|
190 | - */ |
|
191 | - private function prepareCache($nsKey) |
|
192 | - { |
|
193 | - if (!\array_key_exists($nsKey, $this->contents)) { |
|
194 | - $this->contents[$nsKey] = []; |
|
195 | - } |
|
196 | - } |
|
186 | + /** |
|
187 | + * Initialize the namespace of $nsKey if needed. |
|
188 | + * |
|
189 | + * @param string $nsKey |
|
190 | + */ |
|
191 | + private function prepareCache($nsKey) |
|
192 | + { |
|
193 | + if (!\array_key_exists($nsKey, $this->contents)) { |
|
194 | + $this->contents[$nsKey] = []; |
|
195 | + } |
|
196 | + } |
|
197 | 197 | } |
@@ -15,109 +15,109 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCacheInputStream |
17 | 17 | { |
18 | - /** The KeyCache being written to */ |
|
19 | - private $keyCache; |
|
18 | + /** The KeyCache being written to */ |
|
19 | + private $keyCache; |
|
20 | 20 | |
21 | - /** The nsKey of the KeyCache being written to */ |
|
22 | - private $nsKey; |
|
21 | + /** The nsKey of the KeyCache being written to */ |
|
22 | + private $nsKey; |
|
23 | 23 | |
24 | - /** The itemKey of the KeyCache being written to */ |
|
25 | - private $itemKey; |
|
24 | + /** The itemKey of the KeyCache being written to */ |
|
25 | + private $itemKey; |
|
26 | 26 | |
27 | - /** A stream to write through on each write() */ |
|
28 | - private $writeThrough = null; |
|
27 | + /** A stream to write through on each write() */ |
|
28 | + private $writeThrough = null; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Set the KeyCache to wrap. |
|
32 | - */ |
|
33 | - public function setKeyCache(Swift_KeyCache $keyCache) |
|
34 | - { |
|
35 | - $this->keyCache = $keyCache; |
|
36 | - } |
|
30 | + /** |
|
31 | + * Set the KeyCache to wrap. |
|
32 | + */ |
|
33 | + public function setKeyCache(Swift_KeyCache $keyCache) |
|
34 | + { |
|
35 | + $this->keyCache = $keyCache; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Specify a stream to write through for each write(). |
|
40 | - */ |
|
41 | - public function setWriteThroughStream(Swift_InputByteStream $is) |
|
42 | - { |
|
43 | - $this->writeThrough = $is; |
|
44 | - } |
|
38 | + /** |
|
39 | + * Specify a stream to write through for each write(). |
|
40 | + */ |
|
41 | + public function setWriteThroughStream(Swift_InputByteStream $is) |
|
42 | + { |
|
43 | + $this->writeThrough = $is; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Writes $bytes to the end of the stream. |
|
48 | - * |
|
49 | - * @param string $bytes |
|
50 | - * @param Swift_InputByteStream $is optional |
|
51 | - */ |
|
52 | - public function write($bytes, Swift_InputByteStream $is = null) |
|
53 | - { |
|
54 | - $this->keyCache->setString( |
|
55 | - $this->nsKey, $this->itemKey, $bytes, Swift_KeyCache::MODE_APPEND |
|
56 | - ); |
|
57 | - if (isset($is)) { |
|
58 | - $is->write($bytes); |
|
59 | - } |
|
60 | - if (isset($this->writeThrough)) { |
|
61 | - $this->writeThrough->write($bytes); |
|
62 | - } |
|
63 | - } |
|
46 | + /** |
|
47 | + * Writes $bytes to the end of the stream. |
|
48 | + * |
|
49 | + * @param string $bytes |
|
50 | + * @param Swift_InputByteStream $is optional |
|
51 | + */ |
|
52 | + public function write($bytes, Swift_InputByteStream $is = null) |
|
53 | + { |
|
54 | + $this->keyCache->setString( |
|
55 | + $this->nsKey, $this->itemKey, $bytes, Swift_KeyCache::MODE_APPEND |
|
56 | + ); |
|
57 | + if (isset($is)) { |
|
58 | + $is->write($bytes); |
|
59 | + } |
|
60 | + if (isset($this->writeThrough)) { |
|
61 | + $this->writeThrough->write($bytes); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Not used. |
|
67 | - */ |
|
68 | - public function commit() |
|
69 | - { |
|
70 | - } |
|
65 | + /** |
|
66 | + * Not used. |
|
67 | + */ |
|
68 | + public function commit() |
|
69 | + { |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Not used. |
|
74 | - */ |
|
75 | - public function bind(Swift_InputByteStream $is) |
|
76 | - { |
|
77 | - } |
|
72 | + /** |
|
73 | + * Not used. |
|
74 | + */ |
|
75 | + public function bind(Swift_InputByteStream $is) |
|
76 | + { |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Not used. |
|
81 | - */ |
|
82 | - public function unbind(Swift_InputByteStream $is) |
|
83 | - { |
|
84 | - } |
|
79 | + /** |
|
80 | + * Not used. |
|
81 | + */ |
|
82 | + public function unbind(Swift_InputByteStream $is) |
|
83 | + { |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Flush the contents of the stream (empty it) and set the internal pointer |
|
88 | - * to the beginning. |
|
89 | - */ |
|
90 | - public function flushBuffers() |
|
91 | - { |
|
92 | - $this->keyCache->clearKey($this->nsKey, $this->itemKey); |
|
93 | - } |
|
86 | + /** |
|
87 | + * Flush the contents of the stream (empty it) and set the internal pointer |
|
88 | + * to the beginning. |
|
89 | + */ |
|
90 | + public function flushBuffers() |
|
91 | + { |
|
92 | + $this->keyCache->clearKey($this->nsKey, $this->itemKey); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Set the nsKey which will be written to. |
|
97 | - * |
|
98 | - * @param string $nsKey |
|
99 | - */ |
|
100 | - public function setNsKey($nsKey) |
|
101 | - { |
|
102 | - $this->nsKey = $nsKey; |
|
103 | - } |
|
95 | + /** |
|
96 | + * Set the nsKey which will be written to. |
|
97 | + * |
|
98 | + * @param string $nsKey |
|
99 | + */ |
|
100 | + public function setNsKey($nsKey) |
|
101 | + { |
|
102 | + $this->nsKey = $nsKey; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Set the itemKey which will be written to. |
|
107 | - * |
|
108 | - * @param string $itemKey |
|
109 | - */ |
|
110 | - public function setItemKey($itemKey) |
|
111 | - { |
|
112 | - $this->itemKey = $itemKey; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Set the itemKey which will be written to. |
|
107 | + * |
|
108 | + * @param string $itemKey |
|
109 | + */ |
|
110 | + public function setItemKey($itemKey) |
|
111 | + { |
|
112 | + $this->itemKey = $itemKey; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Any implementation should be cloneable, allowing the clone to access a |
|
117 | - * separate $nsKey and $itemKey. |
|
118 | - */ |
|
119 | - public function __clone() |
|
120 | - { |
|
121 | - $this->writeThrough = null; |
|
122 | - } |
|
115 | + /** |
|
116 | + * Any implementation should be cloneable, allowing the clone to access a |
|
117 | + * separate $nsKey and $itemKey. |
|
118 | + */ |
|
119 | + public function __clone() |
|
120 | + { |
|
121 | + $this->writeThrough = null; |
|
122 | + } |
|
123 | 123 | } |
@@ -15,280 +15,280 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache |
17 | 17 | { |
18 | - /** Signal to place pointer at start of file */ |
|
19 | - const POSITION_START = 0; |
|
18 | + /** Signal to place pointer at start of file */ |
|
19 | + const POSITION_START = 0; |
|
20 | 20 | |
21 | - /** Signal to place pointer at end of file */ |
|
22 | - const POSITION_END = 1; |
|
21 | + /** Signal to place pointer at end of file */ |
|
22 | + const POSITION_END = 1; |
|
23 | 23 | |
24 | - /** Signal to leave pointer in whatever position it currently is */ |
|
25 | - const POSITION_CURRENT = 2; |
|
24 | + /** Signal to leave pointer in whatever position it currently is */ |
|
25 | + const POSITION_CURRENT = 2; |
|
26 | 26 | |
27 | - /** |
|
28 | - * An InputStream for cloning. |
|
29 | - * |
|
30 | - * @var Swift_KeyCache_KeyCacheInputStream |
|
31 | - */ |
|
32 | - private $stream; |
|
27 | + /** |
|
28 | + * An InputStream for cloning. |
|
29 | + * |
|
30 | + * @var Swift_KeyCache_KeyCacheInputStream |
|
31 | + */ |
|
32 | + private $stream; |
|
33 | 33 | |
34 | - /** |
|
35 | - * A path to write to. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $path; |
|
34 | + /** |
|
35 | + * A path to write to. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $path; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Stored keys. |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - private $keys = []; |
|
41 | + /** |
|
42 | + * Stored keys. |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + private $keys = []; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Create a new DiskKeyCache with the given $stream for cloning to make |
|
50 | - * InputByteStreams, and the given $path to save to. |
|
51 | - * |
|
52 | - * @param string $path to save to |
|
53 | - */ |
|
54 | - public function __construct(Swift_KeyCache_KeyCacheInputStream $stream, $path) |
|
55 | - { |
|
56 | - $this->stream = $stream; |
|
57 | - $this->path = $path; |
|
58 | - } |
|
48 | + /** |
|
49 | + * Create a new DiskKeyCache with the given $stream for cloning to make |
|
50 | + * InputByteStreams, and the given $path to save to. |
|
51 | + * |
|
52 | + * @param string $path to save to |
|
53 | + */ |
|
54 | + public function __construct(Swift_KeyCache_KeyCacheInputStream $stream, $path) |
|
55 | + { |
|
56 | + $this->stream = $stream; |
|
57 | + $this->path = $path; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
62 | - * |
|
63 | - * @see MODE_WRITE, MODE_APPEND |
|
64 | - * |
|
65 | - * @param string $nsKey |
|
66 | - * @param string $itemKey |
|
67 | - * @param string $string |
|
68 | - * @param int $mode |
|
69 | - * |
|
70 | - * @throws Swift_IoException |
|
71 | - */ |
|
72 | - public function setString($nsKey, $itemKey, $string, $mode) |
|
73 | - { |
|
74 | - $this->prepareCache($nsKey); |
|
75 | - switch ($mode) { |
|
76 | - case self::MODE_WRITE: |
|
77 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
78 | - break; |
|
79 | - case self::MODE_APPEND: |
|
80 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END); |
|
81 | - break; |
|
82 | - default: |
|
83 | - throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
84 | - break; |
|
85 | - } |
|
86 | - fwrite($fp, $string); |
|
87 | - $this->freeHandle($nsKey, $itemKey); |
|
88 | - } |
|
60 | + /** |
|
61 | + * Set a string into the cache under $itemKey for the namespace $nsKey. |
|
62 | + * |
|
63 | + * @see MODE_WRITE, MODE_APPEND |
|
64 | + * |
|
65 | + * @param string $nsKey |
|
66 | + * @param string $itemKey |
|
67 | + * @param string $string |
|
68 | + * @param int $mode |
|
69 | + * |
|
70 | + * @throws Swift_IoException |
|
71 | + */ |
|
72 | + public function setString($nsKey, $itemKey, $string, $mode) |
|
73 | + { |
|
74 | + $this->prepareCache($nsKey); |
|
75 | + switch ($mode) { |
|
76 | + case self::MODE_WRITE: |
|
77 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
78 | + break; |
|
79 | + case self::MODE_APPEND: |
|
80 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END); |
|
81 | + break; |
|
82 | + default: |
|
83 | + throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
84 | + break; |
|
85 | + } |
|
86 | + fwrite($fp, $string); |
|
87 | + $this->freeHandle($nsKey, $itemKey); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
92 | - * |
|
93 | - * @see MODE_WRITE, MODE_APPEND |
|
94 | - * |
|
95 | - * @param string $nsKey |
|
96 | - * @param string $itemKey |
|
97 | - * @param int $mode |
|
98 | - * |
|
99 | - * @throws Swift_IoException |
|
100 | - */ |
|
101 | - public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
102 | - { |
|
103 | - $this->prepareCache($nsKey); |
|
104 | - switch ($mode) { |
|
105 | - case self::MODE_WRITE: |
|
106 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
107 | - break; |
|
108 | - case self::MODE_APPEND: |
|
109 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END); |
|
110 | - break; |
|
111 | - default: |
|
112 | - throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
113 | - break; |
|
114 | - } |
|
115 | - while (false !== $bytes = $os->read(8192)) { |
|
116 | - fwrite($fp, $bytes); |
|
117 | - } |
|
118 | - $this->freeHandle($nsKey, $itemKey); |
|
119 | - } |
|
90 | + /** |
|
91 | + * Set a ByteStream into the cache under $itemKey for the namespace $nsKey. |
|
92 | + * |
|
93 | + * @see MODE_WRITE, MODE_APPEND |
|
94 | + * |
|
95 | + * @param string $nsKey |
|
96 | + * @param string $itemKey |
|
97 | + * @param int $mode |
|
98 | + * |
|
99 | + * @throws Swift_IoException |
|
100 | + */ |
|
101 | + public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode) |
|
102 | + { |
|
103 | + $this->prepareCache($nsKey); |
|
104 | + switch ($mode) { |
|
105 | + case self::MODE_WRITE: |
|
106 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
107 | + break; |
|
108 | + case self::MODE_APPEND: |
|
109 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END); |
|
110 | + break; |
|
111 | + default: |
|
112 | + throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey); |
|
113 | + break; |
|
114 | + } |
|
115 | + while (false !== $bytes = $os->read(8192)) { |
|
116 | + fwrite($fp, $bytes); |
|
117 | + } |
|
118 | + $this->freeHandle($nsKey, $itemKey); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Provides a ByteStream which when written to, writes data to $itemKey. |
|
123 | - * |
|
124 | - * NOTE: The stream will always write in append mode. |
|
125 | - * |
|
126 | - * @param string $nsKey |
|
127 | - * @param string $itemKey |
|
128 | - * |
|
129 | - * @return Swift_InputByteStream |
|
130 | - */ |
|
131 | - public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
132 | - { |
|
133 | - $is = clone $this->stream; |
|
134 | - $is->setKeyCache($this); |
|
135 | - $is->setNsKey($nsKey); |
|
136 | - $is->setItemKey($itemKey); |
|
137 | - if (isset($writeThrough)) { |
|
138 | - $is->setWriteThroughStream($writeThrough); |
|
139 | - } |
|
121 | + /** |
|
122 | + * Provides a ByteStream which when written to, writes data to $itemKey. |
|
123 | + * |
|
124 | + * NOTE: The stream will always write in append mode. |
|
125 | + * |
|
126 | + * @param string $nsKey |
|
127 | + * @param string $itemKey |
|
128 | + * |
|
129 | + * @return Swift_InputByteStream |
|
130 | + */ |
|
131 | + public function getInputByteStream($nsKey, $itemKey, Swift_InputByteStream $writeThrough = null) |
|
132 | + { |
|
133 | + $is = clone $this->stream; |
|
134 | + $is->setKeyCache($this); |
|
135 | + $is->setNsKey($nsKey); |
|
136 | + $is->setItemKey($itemKey); |
|
137 | + if (isset($writeThrough)) { |
|
138 | + $is->setWriteThroughStream($writeThrough); |
|
139 | + } |
|
140 | 140 | |
141 | - return $is; |
|
142 | - } |
|
141 | + return $is; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * Get data back out of the cache as a string. |
|
146 | - * |
|
147 | - * @param string $nsKey |
|
148 | - * @param string $itemKey |
|
149 | - * |
|
150 | - * @throws Swift_IoException |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function getString($nsKey, $itemKey) |
|
155 | - { |
|
156 | - $this->prepareCache($nsKey); |
|
157 | - if ($this->hasKey($nsKey, $itemKey)) { |
|
158 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
159 | - $str = ''; |
|
160 | - while (!feof($fp) && false !== $bytes = fread($fp, 8192)) { |
|
161 | - $str .= $bytes; |
|
162 | - } |
|
163 | - $this->freeHandle($nsKey, $itemKey); |
|
144 | + /** |
|
145 | + * Get data back out of the cache as a string. |
|
146 | + * |
|
147 | + * @param string $nsKey |
|
148 | + * @param string $itemKey |
|
149 | + * |
|
150 | + * @throws Swift_IoException |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function getString($nsKey, $itemKey) |
|
155 | + { |
|
156 | + $this->prepareCache($nsKey); |
|
157 | + if ($this->hasKey($nsKey, $itemKey)) { |
|
158 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
159 | + $str = ''; |
|
160 | + while (!feof($fp) && false !== $bytes = fread($fp, 8192)) { |
|
161 | + $str .= $bytes; |
|
162 | + } |
|
163 | + $this->freeHandle($nsKey, $itemKey); |
|
164 | 164 | |
165 | - return $str; |
|
166 | - } |
|
167 | - } |
|
165 | + return $str; |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Get data back out of the cache as a ByteStream. |
|
171 | - * |
|
172 | - * @param string $nsKey |
|
173 | - * @param string $itemKey |
|
174 | - * @param Swift_InputByteStream $is to write the data to |
|
175 | - */ |
|
176 | - public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
177 | - { |
|
178 | - if ($this->hasKey($nsKey, $itemKey)) { |
|
179 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
180 | - while (!feof($fp) && false !== $bytes = fread($fp, 8192)) { |
|
181 | - $is->write($bytes); |
|
182 | - } |
|
183 | - $this->freeHandle($nsKey, $itemKey); |
|
184 | - } |
|
185 | - } |
|
169 | + /** |
|
170 | + * Get data back out of the cache as a ByteStream. |
|
171 | + * |
|
172 | + * @param string $nsKey |
|
173 | + * @param string $itemKey |
|
174 | + * @param Swift_InputByteStream $is to write the data to |
|
175 | + */ |
|
176 | + public function exportToByteStream($nsKey, $itemKey, Swift_InputByteStream $is) |
|
177 | + { |
|
178 | + if ($this->hasKey($nsKey, $itemKey)) { |
|
179 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_START); |
|
180 | + while (!feof($fp) && false !== $bytes = fread($fp, 8192)) { |
|
181 | + $is->write($bytes); |
|
182 | + } |
|
183 | + $this->freeHandle($nsKey, $itemKey); |
|
184 | + } |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Check if the given $itemKey exists in the namespace $nsKey. |
|
189 | - * |
|
190 | - * @param string $nsKey |
|
191 | - * @param string $itemKey |
|
192 | - * |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function hasKey($nsKey, $itemKey) |
|
196 | - { |
|
197 | - return is_file($this->path.'/'.$nsKey.'/'.$itemKey); |
|
198 | - } |
|
187 | + /** |
|
188 | + * Check if the given $itemKey exists in the namespace $nsKey. |
|
189 | + * |
|
190 | + * @param string $nsKey |
|
191 | + * @param string $itemKey |
|
192 | + * |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function hasKey($nsKey, $itemKey) |
|
196 | + { |
|
197 | + return is_file($this->path.'/'.$nsKey.'/'.$itemKey); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
202 | - * |
|
203 | - * @param string $nsKey |
|
204 | - * @param string $itemKey |
|
205 | - */ |
|
206 | - public function clearKey($nsKey, $itemKey) |
|
207 | - { |
|
208 | - if ($this->hasKey($nsKey, $itemKey)) { |
|
209 | - $this->freeHandle($nsKey, $itemKey); |
|
210 | - unlink($this->path.'/'.$nsKey.'/'.$itemKey); |
|
211 | - } |
|
212 | - } |
|
200 | + /** |
|
201 | + * Clear data for $itemKey in the namespace $nsKey if it exists. |
|
202 | + * |
|
203 | + * @param string $nsKey |
|
204 | + * @param string $itemKey |
|
205 | + */ |
|
206 | + public function clearKey($nsKey, $itemKey) |
|
207 | + { |
|
208 | + if ($this->hasKey($nsKey, $itemKey)) { |
|
209 | + $this->freeHandle($nsKey, $itemKey); |
|
210 | + unlink($this->path.'/'.$nsKey.'/'.$itemKey); |
|
211 | + } |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Clear all data in the namespace $nsKey if it exists. |
|
216 | - * |
|
217 | - * @param string $nsKey |
|
218 | - */ |
|
219 | - public function clearAll($nsKey) |
|
220 | - { |
|
221 | - if (\array_key_exists($nsKey, $this->keys)) { |
|
222 | - foreach ($this->keys[$nsKey] as $itemKey => $null) { |
|
223 | - $this->clearKey($nsKey, $itemKey); |
|
224 | - } |
|
225 | - if (is_dir($this->path.'/'.$nsKey)) { |
|
226 | - rmdir($this->path.'/'.$nsKey); |
|
227 | - } |
|
228 | - unset($this->keys[$nsKey]); |
|
229 | - } |
|
230 | - } |
|
214 | + /** |
|
215 | + * Clear all data in the namespace $nsKey if it exists. |
|
216 | + * |
|
217 | + * @param string $nsKey |
|
218 | + */ |
|
219 | + public function clearAll($nsKey) |
|
220 | + { |
|
221 | + if (\array_key_exists($nsKey, $this->keys)) { |
|
222 | + foreach ($this->keys[$nsKey] as $itemKey => $null) { |
|
223 | + $this->clearKey($nsKey, $itemKey); |
|
224 | + } |
|
225 | + if (is_dir($this->path.'/'.$nsKey)) { |
|
226 | + rmdir($this->path.'/'.$nsKey); |
|
227 | + } |
|
228 | + unset($this->keys[$nsKey]); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Initialize the namespace of $nsKey if needed. |
|
234 | - * |
|
235 | - * @param string $nsKey |
|
236 | - */ |
|
237 | - private function prepareCache($nsKey) |
|
238 | - { |
|
239 | - $cacheDir = $this->path.'/'.$nsKey; |
|
240 | - if (!is_dir($cacheDir)) { |
|
241 | - if (!mkdir($cacheDir)) { |
|
242 | - throw new Swift_IoException('Failed to create cache directory '.$cacheDir); |
|
243 | - } |
|
244 | - $this->keys[$nsKey] = []; |
|
245 | - } |
|
246 | - } |
|
232 | + /** |
|
233 | + * Initialize the namespace of $nsKey if needed. |
|
234 | + * |
|
235 | + * @param string $nsKey |
|
236 | + */ |
|
237 | + private function prepareCache($nsKey) |
|
238 | + { |
|
239 | + $cacheDir = $this->path.'/'.$nsKey; |
|
240 | + if (!is_dir($cacheDir)) { |
|
241 | + if (!mkdir($cacheDir)) { |
|
242 | + throw new Swift_IoException('Failed to create cache directory '.$cacheDir); |
|
243 | + } |
|
244 | + $this->keys[$nsKey] = []; |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Get a file handle on the cache item. |
|
250 | - * |
|
251 | - * @param string $nsKey |
|
252 | - * @param string $itemKey |
|
253 | - * @param int $position |
|
254 | - * |
|
255 | - * @return resource |
|
256 | - */ |
|
257 | - private function getHandle($nsKey, $itemKey, $position) |
|
258 | - { |
|
259 | - if (!isset($this->keys[$nsKey][$itemKey])) { |
|
260 | - $openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b'; |
|
261 | - $fp = fopen($this->path.'/'.$nsKey.'/'.$itemKey, $openMode); |
|
262 | - $this->keys[$nsKey][$itemKey] = $fp; |
|
263 | - } |
|
264 | - if (self::POSITION_START == $position) { |
|
265 | - fseek($this->keys[$nsKey][$itemKey], 0, SEEK_SET); |
|
266 | - } elseif (self::POSITION_END == $position) { |
|
267 | - fseek($this->keys[$nsKey][$itemKey], 0, SEEK_END); |
|
268 | - } |
|
248 | + /** |
|
249 | + * Get a file handle on the cache item. |
|
250 | + * |
|
251 | + * @param string $nsKey |
|
252 | + * @param string $itemKey |
|
253 | + * @param int $position |
|
254 | + * |
|
255 | + * @return resource |
|
256 | + */ |
|
257 | + private function getHandle($nsKey, $itemKey, $position) |
|
258 | + { |
|
259 | + if (!isset($this->keys[$nsKey][$itemKey])) { |
|
260 | + $openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b'; |
|
261 | + $fp = fopen($this->path.'/'.$nsKey.'/'.$itemKey, $openMode); |
|
262 | + $this->keys[$nsKey][$itemKey] = $fp; |
|
263 | + } |
|
264 | + if (self::POSITION_START == $position) { |
|
265 | + fseek($this->keys[$nsKey][$itemKey], 0, SEEK_SET); |
|
266 | + } elseif (self::POSITION_END == $position) { |
|
267 | + fseek($this->keys[$nsKey][$itemKey], 0, SEEK_END); |
|
268 | + } |
|
269 | 269 | |
270 | - return $this->keys[$nsKey][$itemKey]; |
|
271 | - } |
|
270 | + return $this->keys[$nsKey][$itemKey]; |
|
271 | + } |
|
272 | 272 | |
273 | - private function freeHandle($nsKey, $itemKey) |
|
274 | - { |
|
275 | - $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_CURRENT); |
|
276 | - fclose($fp); |
|
277 | - $this->keys[$nsKey][$itemKey] = null; |
|
278 | - } |
|
273 | + private function freeHandle($nsKey, $itemKey) |
|
274 | + { |
|
275 | + $fp = $this->getHandle($nsKey, $itemKey, self::POSITION_CURRENT); |
|
276 | + fclose($fp); |
|
277 | + $this->keys[$nsKey][$itemKey] = null; |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Destructor. |
|
282 | - */ |
|
283 | - public function __destruct() |
|
284 | - { |
|
285 | - foreach ($this->keys as $nsKey => $null) { |
|
286 | - $this->clearAll($nsKey); |
|
287 | - } |
|
288 | - } |
|
280 | + /** |
|
281 | + * Destructor. |
|
282 | + */ |
|
283 | + public function __destruct() |
|
284 | + { |
|
285 | + foreach ($this->keys as $nsKey => $null) { |
|
286 | + $this->clearAll($nsKey); |
|
287 | + } |
|
288 | + } |
|
289 | 289 | |
290 | - public function __wakeup() |
|
291 | - { |
|
292 | - $this->keys = []; |
|
293 | - } |
|
290 | + public function __wakeup() |
|
291 | + { |
|
292 | + $this->keys = []; |
|
293 | + } |
|
294 | 294 | } |
@@ -15,39 +15,39 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile |
17 | 17 | { |
18 | - /** |
|
19 | - * Create a new EmbeddedFile. |
|
20 | - * |
|
21 | - * Details may be optionally provided to the constructor. |
|
22 | - * |
|
23 | - * @param string|Swift_OutputByteStream $data |
|
24 | - * @param string $filename |
|
25 | - * @param string $contentType |
|
26 | - */ |
|
27 | - public function __construct($data = null, $filename = null, $contentType = null) |
|
28 | - { |
|
29 | - \call_user_func_array( |
|
30 | - [$this, 'Swift_Mime_EmbeddedFile::__construct'], |
|
31 | - Swift_DependencyContainer::getInstance() |
|
32 | - ->createDependenciesFor('mime.embeddedfile') |
|
33 | - ); |
|
18 | + /** |
|
19 | + * Create a new EmbeddedFile. |
|
20 | + * |
|
21 | + * Details may be optionally provided to the constructor. |
|
22 | + * |
|
23 | + * @param string|Swift_OutputByteStream $data |
|
24 | + * @param string $filename |
|
25 | + * @param string $contentType |
|
26 | + */ |
|
27 | + public function __construct($data = null, $filename = null, $contentType = null) |
|
28 | + { |
|
29 | + \call_user_func_array( |
|
30 | + [$this, 'Swift_Mime_EmbeddedFile::__construct'], |
|
31 | + Swift_DependencyContainer::getInstance() |
|
32 | + ->createDependenciesFor('mime.embeddedfile') |
|
33 | + ); |
|
34 | 34 | |
35 | - $this->setBody($data); |
|
36 | - $this->setFilename($filename); |
|
37 | - if ($contentType) { |
|
38 | - $this->setContentType($contentType); |
|
39 | - } |
|
40 | - } |
|
35 | + $this->setBody($data); |
|
36 | + $this->setFilename($filename); |
|
37 | + if ($contentType) { |
|
38 | + $this->setContentType($contentType); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Create a new EmbeddedFile from a filesystem path. |
|
44 | - * |
|
45 | - * @param string $path |
|
46 | - * |
|
47 | - * @return Swift_Mime_EmbeddedFile |
|
48 | - */ |
|
49 | - public static function fromPath($path) |
|
50 | - { |
|
51 | - return (new self())->setFile(new Swift_ByteStream_FileByteStream($path)); |
|
52 | - } |
|
42 | + /** |
|
43 | + * Create a new EmbeddedFile from a filesystem path. |
|
44 | + * |
|
45 | + * @param string $path |
|
46 | + * |
|
47 | + * @return Swift_Mime_EmbeddedFile |
|
48 | + */ |
|
49 | + public static function fromPath($path) |
|
50 | + { |
|
51 | + return (new self())->setFile(new Swift_ByteStream_FileByteStream($path)); |
|
52 | + } |
|
53 | 53 | } |
@@ -15,84 +15,84 @@ |
||
15 | 15 | */ |
16 | 16 | class Swift_Mailer |
17 | 17 | { |
18 | - /** The Transport used to send messages */ |
|
19 | - private $transport; |
|
18 | + /** The Transport used to send messages */ |
|
19 | + private $transport; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Create a new Mailer using $transport for delivery. |
|
23 | - */ |
|
24 | - public function __construct(Swift_Transport $transport) |
|
25 | - { |
|
26 | - $this->transport = $transport; |
|
27 | - } |
|
21 | + /** |
|
22 | + * Create a new Mailer using $transport for delivery. |
|
23 | + */ |
|
24 | + public function __construct(Swift_Transport $transport) |
|
25 | + { |
|
26 | + $this->transport = $transport; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Create a new class instance of one of the message services. |
|
31 | - * |
|
32 | - * For example 'mimepart' would create a 'message.mimepart' instance |
|
33 | - * |
|
34 | - * @param string $service |
|
35 | - * |
|
36 | - * @return object |
|
37 | - */ |
|
38 | - public function createMessage($service = 'message') |
|
39 | - { |
|
40 | - return Swift_DependencyContainer::getInstance() |
|
41 | - ->lookup('message.'.$service); |
|
42 | - } |
|
29 | + /** |
|
30 | + * Create a new class instance of one of the message services. |
|
31 | + * |
|
32 | + * For example 'mimepart' would create a 'message.mimepart' instance |
|
33 | + * |
|
34 | + * @param string $service |
|
35 | + * |
|
36 | + * @return object |
|
37 | + */ |
|
38 | + public function createMessage($service = 'message') |
|
39 | + { |
|
40 | + return Swift_DependencyContainer::getInstance() |
|
41 | + ->lookup('message.'.$service); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Send the given Message like it would be sent in a mail client. |
|
46 | - * |
|
47 | - * All recipients (with the exception of Bcc) will be able to see the other |
|
48 | - * recipients this message was sent to. |
|
49 | - * |
|
50 | - * Recipient/sender data will be retrieved from the Message object. |
|
51 | - * |
|
52 | - * The return value is the number of recipients who were accepted for |
|
53 | - * delivery. |
|
54 | - * |
|
55 | - * @param array $failedRecipients An array of failures by-reference |
|
56 | - * |
|
57 | - * @return int The number of successful recipients. Can be 0 which indicates failure |
|
58 | - */ |
|
59 | - public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
|
60 | - { |
|
61 | - $failedRecipients = (array) $failedRecipients; |
|
44 | + /** |
|
45 | + * Send the given Message like it would be sent in a mail client. |
|
46 | + * |
|
47 | + * All recipients (with the exception of Bcc) will be able to see the other |
|
48 | + * recipients this message was sent to. |
|
49 | + * |
|
50 | + * Recipient/sender data will be retrieved from the Message object. |
|
51 | + * |
|
52 | + * The return value is the number of recipients who were accepted for |
|
53 | + * delivery. |
|
54 | + * |
|
55 | + * @param array $failedRecipients An array of failures by-reference |
|
56 | + * |
|
57 | + * @return int The number of successful recipients. Can be 0 which indicates failure |
|
58 | + */ |
|
59 | + public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) |
|
60 | + { |
|
61 | + $failedRecipients = (array) $failedRecipients; |
|
62 | 62 | |
63 | - // FIXME: to be removed in 7.0 (as transport must now start itself on send) |
|
64 | - if (!$this->transport->isStarted()) { |
|
65 | - $this->transport->start(); |
|
66 | - } |
|
63 | + // FIXME: to be removed in 7.0 (as transport must now start itself on send) |
|
64 | + if (!$this->transport->isStarted()) { |
|
65 | + $this->transport->start(); |
|
66 | + } |
|
67 | 67 | |
68 | - $sent = 0; |
|
68 | + $sent = 0; |
|
69 | 69 | |
70 | - try { |
|
71 | - $sent = $this->transport->send($message, $failedRecipients); |
|
72 | - } catch (Swift_RfcComplianceException $e) { |
|
73 | - foreach ($message->getTo() as $address => $name) { |
|
74 | - $failedRecipients[] = $address; |
|
75 | - } |
|
76 | - } |
|
70 | + try { |
|
71 | + $sent = $this->transport->send($message, $failedRecipients); |
|
72 | + } catch (Swift_RfcComplianceException $e) { |
|
73 | + foreach ($message->getTo() as $address => $name) { |
|
74 | + $failedRecipients[] = $address; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $sent; |
|
79 | - } |
|
78 | + return $sent; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Register a plugin using a known unique key (e.g. myPlugin). |
|
83 | - */ |
|
84 | - public function registerPlugin(Swift_Events_EventListener $plugin) |
|
85 | - { |
|
86 | - $this->transport->registerPlugin($plugin); |
|
87 | - } |
|
81 | + /** |
|
82 | + * Register a plugin using a known unique key (e.g. myPlugin). |
|
83 | + */ |
|
84 | + public function registerPlugin(Swift_Events_EventListener $plugin) |
|
85 | + { |
|
86 | + $this->transport->registerPlugin($plugin); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * The Transport used to send messages. |
|
91 | - * |
|
92 | - * @return Swift_Transport |
|
93 | - */ |
|
94 | - public function getTransport() |
|
95 | - { |
|
96 | - return $this->transport; |
|
97 | - } |
|
89 | + /** |
|
90 | + * The Transport used to send messages. |
|
91 | + * |
|
92 | + * @return Swift_Transport |
|
93 | + */ |
|
94 | + public function getTransport() |
|
95 | + { |
|
96 | + return $this->transport; |
|
97 | + } |
|
98 | 98 | } |
@@ -15,39 +15,39 @@ |
||
15 | 15 | */ |
16 | 16 | interface Swift_Spool |
17 | 17 | { |
18 | - /** |
|
19 | - * Starts this Spool mechanism. |
|
20 | - */ |
|
21 | - public function start(); |
|
18 | + /** |
|
19 | + * Starts this Spool mechanism. |
|
20 | + */ |
|
21 | + public function start(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * Stops this Spool mechanism. |
|
25 | - */ |
|
26 | - public function stop(); |
|
23 | + /** |
|
24 | + * Stops this Spool mechanism. |
|
25 | + */ |
|
26 | + public function stop(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Tests if this Spool mechanism has started. |
|
30 | - * |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function isStarted(); |
|
28 | + /** |
|
29 | + * Tests if this Spool mechanism has started. |
|
30 | + * |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function isStarted(); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Queues a message. |
|
37 | - * |
|
38 | - * @param Swift_Mime_SimpleMessage $message The message to store |
|
39 | - * |
|
40 | - * @return bool Whether the operation has succeeded |
|
41 | - */ |
|
42 | - public function queueMessage(Swift_Mime_SimpleMessage $message); |
|
35 | + /** |
|
36 | + * Queues a message. |
|
37 | + * |
|
38 | + * @param Swift_Mime_SimpleMessage $message The message to store |
|
39 | + * |
|
40 | + * @return bool Whether the operation has succeeded |
|
41 | + */ |
|
42 | + public function queueMessage(Swift_Mime_SimpleMessage $message); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Sends messages using the given transport instance. |
|
46 | - * |
|
47 | - * @param Swift_Transport $transport A transport instance |
|
48 | - * @param string[] $failedRecipients An array of failures by-reference |
|
49 | - * |
|
50 | - * @return int The number of sent emails |
|
51 | - */ |
|
52 | - public function flushQueue(Swift_Transport $transport, &$failedRecipients = null); |
|
44 | + /** |
|
45 | + * Sends messages using the given transport instance. |
|
46 | + * |
|
47 | + * @param Swift_Transport $transport A transport instance |
|
48 | + * @param string[] $failedRecipients An array of failures by-reference |
|
49 | + * |
|
50 | + * @return int The number of sent emails |
|
51 | + */ |
|
52 | + public function flushQueue(Swift_Transport $transport, &$failedRecipients = null); |
|
53 | 53 | } |
@@ -13,10 +13,10 @@ |
||
13 | 13 | */ |
14 | 14 | interface Swift_IdGenerator |
15 | 15 | { |
16 | - /** |
|
17 | - * Returns a globally unique string to use for Message-ID or Content-ID. |
|
18 | - * |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public function generateId(); |
|
16 | + /** |
|
17 | + * Returns a globally unique string to use for Message-ID or Content-ID. |
|
18 | + * |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public function generateId(); |
|
22 | 22 | } |
@@ -22,24 +22,24 @@ |
||
22 | 22 | */ |
23 | 23 | class Swift_SmtpTransport extends Swift_Transport_EsmtpTransport |
24 | 24 | { |
25 | - /** |
|
26 | - * @param string $host |
|
27 | - * @param int $port |
|
28 | - * @param string|null $encryption SMTP encryption mode: |
|
29 | - * - null for plain SMTP (no encryption), |
|
30 | - * - 'tls' for SMTP with STARTTLS (best effort encryption), |
|
31 | - * - 'ssl' for SMTPS = SMTP over TLS (always encrypted). |
|
32 | - */ |
|
33 | - public function __construct($host = 'localhost', $port = 25, $encryption = null) |
|
34 | - { |
|
35 | - \call_user_func_array( |
|
36 | - [$this, 'Swift_Transport_EsmtpTransport::__construct'], |
|
37 | - Swift_DependencyContainer::getInstance() |
|
38 | - ->createDependenciesFor('transport.smtp') |
|
39 | - ); |
|
25 | + /** |
|
26 | + * @param string $host |
|
27 | + * @param int $port |
|
28 | + * @param string|null $encryption SMTP encryption mode: |
|
29 | + * - null for plain SMTP (no encryption), |
|
30 | + * - 'tls' for SMTP with STARTTLS (best effort encryption), |
|
31 | + * - 'ssl' for SMTPS = SMTP over TLS (always encrypted). |
|
32 | + */ |
|
33 | + public function __construct($host = 'localhost', $port = 25, $encryption = null) |
|
34 | + { |
|
35 | + \call_user_func_array( |
|
36 | + [$this, 'Swift_Transport_EsmtpTransport::__construct'], |
|
37 | + Swift_DependencyContainer::getInstance() |
|
38 | + ->createDependenciesFor('transport.smtp') |
|
39 | + ); |
|
40 | 40 | |
41 | - $this->setHost($host); |
|
42 | - $this->setPort($port); |
|
43 | - $this->setEncryption($encryption); |
|
44 | - } |
|
41 | + $this->setHost($host); |
|
42 | + $this->setPort($port); |
|
43 | + $this->setEncryption($encryption); |
|
44 | + } |
|
45 | 45 | } |