@@ -15,10 +15,10 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Swift_Mime_CharsetObserver |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Notify this observer that the entity's charset has changed. |
|
| 20 | - * |
|
| 21 | - * @param string $charset |
|
| 22 | - */ |
|
| 23 | - public function charsetChanged($charset); |
|
| 18 | + /** |
|
| 19 | + * Notify this observer that the entity's charset has changed. |
|
| 20 | + * |
|
| 21 | + * @param string $charset |
|
| 22 | + */ |
|
| 23 | + public function charsetChanged($charset); |
|
| 24 | 24 | } |
@@ -15,79 +15,79 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface Swift_Mime_Header |
| 17 | 17 | { |
| 18 | - /** Text headers */ |
|
| 19 | - const TYPE_TEXT = 2; |
|
| 18 | + /** Text headers */ |
|
| 19 | + const TYPE_TEXT = 2; |
|
| 20 | 20 | |
| 21 | - /** headers (text + params) */ |
|
| 22 | - const TYPE_PARAMETERIZED = 6; |
|
| 21 | + /** headers (text + params) */ |
|
| 22 | + const TYPE_PARAMETERIZED = 6; |
|
| 23 | 23 | |
| 24 | - /** Mailbox and address headers */ |
|
| 25 | - const TYPE_MAILBOX = 8; |
|
| 24 | + /** Mailbox and address headers */ |
|
| 25 | + const TYPE_MAILBOX = 8; |
|
| 26 | 26 | |
| 27 | - /** Date and time headers */ |
|
| 28 | - const TYPE_DATE = 16; |
|
| 27 | + /** Date and time headers */ |
|
| 28 | + const TYPE_DATE = 16; |
|
| 29 | 29 | |
| 30 | - /** Identification headers */ |
|
| 31 | - const TYPE_ID = 32; |
|
| 30 | + /** Identification headers */ |
|
| 31 | + const TYPE_ID = 32; |
|
| 32 | 32 | |
| 33 | - /** Address path headers */ |
|
| 34 | - const TYPE_PATH = 64; |
|
| 33 | + /** Address path headers */ |
|
| 34 | + const TYPE_PATH = 64; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Get the type of Header that this instance represents. |
|
| 38 | - * |
|
| 39 | - * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 40 | - * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 41 | - * |
|
| 42 | - * @return int |
|
| 43 | - */ |
|
| 44 | - public function getFieldType(); |
|
| 36 | + /** |
|
| 37 | + * Get the type of Header that this instance represents. |
|
| 38 | + * |
|
| 39 | + * @see TYPE_TEXT, TYPE_PARAMETERIZED, TYPE_MAILBOX |
|
| 40 | + * @see TYPE_DATE, TYPE_ID, TYPE_PATH |
|
| 41 | + * |
|
| 42 | + * @return int |
|
| 43 | + */ |
|
| 44 | + public function getFieldType(); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Set the model for the field body. |
|
| 48 | - * |
|
| 49 | - * The actual types needed will vary depending upon the type of Header. |
|
| 50 | - * |
|
| 51 | - * @param mixed $model |
|
| 52 | - */ |
|
| 53 | - public function setFieldBodyModel($model); |
|
| 46 | + /** |
|
| 47 | + * Set the model for the field body. |
|
| 48 | + * |
|
| 49 | + * The actual types needed will vary depending upon the type of Header. |
|
| 50 | + * |
|
| 51 | + * @param mixed $model |
|
| 52 | + */ |
|
| 53 | + public function setFieldBodyModel($model); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Set the charset used when rendering the Header. |
|
| 57 | - * |
|
| 58 | - * @param string $charset |
|
| 59 | - */ |
|
| 60 | - public function setCharset($charset); |
|
| 55 | + /** |
|
| 56 | + * Set the charset used when rendering the Header. |
|
| 57 | + * |
|
| 58 | + * @param string $charset |
|
| 59 | + */ |
|
| 60 | + public function setCharset($charset); |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get the model for the field body. |
|
| 64 | - * |
|
| 65 | - * The return type depends on the specifics of the Header. |
|
| 66 | - * |
|
| 67 | - * @return mixed |
|
| 68 | - */ |
|
| 69 | - public function getFieldBodyModel(); |
|
| 62 | + /** |
|
| 63 | + * Get the model for the field body. |
|
| 64 | + * |
|
| 65 | + * The return type depends on the specifics of the Header. |
|
| 66 | + * |
|
| 67 | + * @return mixed |
|
| 68 | + */ |
|
| 69 | + public function getFieldBodyModel(); |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get the name of this header (e.g. Subject). |
|
| 73 | - * |
|
| 74 | - * The name is an identifier and as such will be immutable. |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function getFieldName(); |
|
| 71 | + /** |
|
| 72 | + * Get the name of this header (e.g. Subject). |
|
| 73 | + * |
|
| 74 | + * The name is an identifier and as such will be immutable. |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function getFieldName(); |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Get the field body, prepared for folding into a final header value. |
|
| 82 | - * |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function getFieldBody(); |
|
| 80 | + /** |
|
| 81 | + * Get the field body, prepared for folding into a final header value. |
|
| 82 | + * |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function getFieldBody(); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Get this Header rendered as a compliant string, including trailing CRLF. |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function toString(); |
|
| 87 | + /** |
|
| 88 | + * Get this Header rendered as a compliant string, including trailing CRLF. |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function toString(); |
|
| 93 | 93 | } |
@@ -15,385 +15,385 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver |
| 17 | 17 | { |
| 18 | - /** HeaderFactory */ |
|
| 19 | - private $factory; |
|
| 20 | - |
|
| 21 | - /** Collection of set Headers */ |
|
| 22 | - private $headers = []; |
|
| 23 | - |
|
| 24 | - /** Field ordering details */ |
|
| 25 | - private $order = []; |
|
| 26 | - |
|
| 27 | - /** List of fields which are required to be displayed */ |
|
| 28 | - private $required = []; |
|
| 29 | - |
|
| 30 | - /** The charset used by Headers */ |
|
| 31 | - private $charset; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Create a new SimpleHeaderSet with the given $factory. |
|
| 35 | - * |
|
| 36 | - * @param string $charset |
|
| 37 | - */ |
|
| 38 | - public function __construct(Swift_Mime_SimpleHeaderFactory $factory, $charset = null) |
|
| 39 | - { |
|
| 40 | - $this->factory = $factory; |
|
| 41 | - if (isset($charset)) { |
|
| 42 | - $this->setCharset($charset); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function newInstance() |
|
| 47 | - { |
|
| 48 | - return new self($this->factory); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Set the charset used by these headers. |
|
| 53 | - * |
|
| 54 | - * @param string $charset |
|
| 55 | - */ |
|
| 56 | - public function setCharset($charset) |
|
| 57 | - { |
|
| 58 | - $this->charset = $charset; |
|
| 59 | - $this->factory->charsetChanged($charset); |
|
| 60 | - $this->notifyHeadersOfCharset($charset); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Add a new Mailbox Header with a list of $addresses. |
|
| 65 | - * |
|
| 66 | - * @param string $name |
|
| 67 | - * @param array|string $addresses |
|
| 68 | - */ |
|
| 69 | - public function addMailboxHeader($name, $addresses = null) |
|
| 70 | - { |
|
| 71 | - $this->storeHeader($name, $this->factory->createMailboxHeader($name, $addresses)); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Add a new Date header using $dateTime. |
|
| 76 | - * |
|
| 77 | - * @param string $name |
|
| 78 | - */ |
|
| 79 | - public function addDateHeader($name, DateTimeInterface $dateTime = null) |
|
| 80 | - { |
|
| 81 | - $this->storeHeader($name, $this->factory->createDateHeader($name, $dateTime)); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Add a new basic text header with $name and $value. |
|
| 86 | - * |
|
| 87 | - * @param string $name |
|
| 88 | - * @param string $value |
|
| 89 | - */ |
|
| 90 | - public function addTextHeader($name, $value = null) |
|
| 91 | - { |
|
| 92 | - $this->storeHeader($name, $this->factory->createTextHeader($name, $value)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Add a new ParameterizedHeader with $name, $value and $params. |
|
| 97 | - * |
|
| 98 | - * @param string $name |
|
| 99 | - * @param string $value |
|
| 100 | - * @param array $params |
|
| 101 | - */ |
|
| 102 | - public function addParameterizedHeader($name, $value = null, $params = []) |
|
| 103 | - { |
|
| 104 | - $this->storeHeader($name, $this->factory->createParameterizedHeader($name, $value, $params)); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Add a new ID header for Message-ID or Content-ID. |
|
| 109 | - * |
|
| 110 | - * @param string $name |
|
| 111 | - * @param string|array $ids |
|
| 112 | - */ |
|
| 113 | - public function addIdHeader($name, $ids = null) |
|
| 114 | - { |
|
| 115 | - $this->storeHeader($name, $this->factory->createIdHeader($name, $ids)); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Add a new Path header with an address (path) in it. |
|
| 120 | - * |
|
| 121 | - * @param string $name |
|
| 122 | - * @param string $path |
|
| 123 | - */ |
|
| 124 | - public function addPathHeader($name, $path = null) |
|
| 125 | - { |
|
| 126 | - $this->storeHeader($name, $this->factory->createPathHeader($name, $path)); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Returns true if at least one header with the given $name exists. |
|
| 131 | - * |
|
| 132 | - * If multiple headers match, the actual one may be specified by $index. |
|
| 133 | - * |
|
| 134 | - * @param string $name |
|
| 135 | - * @param int $index |
|
| 136 | - * |
|
| 137 | - * @return bool |
|
| 138 | - */ |
|
| 139 | - public function has($name, $index = 0) |
|
| 140 | - { |
|
| 141 | - $lowerName = strtolower($name ?? ''); |
|
| 142 | - |
|
| 143 | - if (!\array_key_exists($lowerName, $this->headers)) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if (\func_num_args() < 2) { |
|
| 148 | - // index was not specified, so we only need to check that there is at least one header value set |
|
| 149 | - return (bool) \count($this->headers[$lowerName]); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return \array_key_exists($index, $this->headers[$lowerName]); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Set a header in the HeaderSet. |
|
| 157 | - * |
|
| 158 | - * The header may be a previously fetched header via {@link get()} or it may |
|
| 159 | - * be one that has been created separately. |
|
| 160 | - * |
|
| 161 | - * If $index is specified, the header will be inserted into the set at this |
|
| 162 | - * offset. |
|
| 163 | - * |
|
| 164 | - * @param int $index |
|
| 165 | - */ |
|
| 166 | - public function set(Swift_Mime_Header $header, $index = 0) |
|
| 167 | - { |
|
| 168 | - $this->storeHeader($header->getFieldName(), $header, $index); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Get the header with the given $name. |
|
| 173 | - * |
|
| 174 | - * If multiple headers match, the actual one may be specified by $index. |
|
| 175 | - * Returns NULL if none present. |
|
| 176 | - * |
|
| 177 | - * @param string $name |
|
| 178 | - * @param int $index |
|
| 179 | - * |
|
| 180 | - * @return Swift_Mime_Header|null |
|
| 181 | - */ |
|
| 182 | - public function get($name, $index = 0) |
|
| 183 | - { |
|
| 184 | - $name = strtolower($name ?? ''); |
|
| 185 | - |
|
| 186 | - if (\func_num_args() < 2) { |
|
| 187 | - if ($this->has($name)) { |
|
| 188 | - $values = array_values($this->headers[$name]); |
|
| 189 | - |
|
| 190 | - return array_shift($values); |
|
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - if ($this->has($name, $index)) { |
|
| 194 | - return $this->headers[$name][$index]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get all headers with the given $name. |
|
| 201 | - * |
|
| 202 | - * @param string $name |
|
| 203 | - * |
|
| 204 | - * @return array |
|
| 205 | - */ |
|
| 206 | - public function getAll($name = null) |
|
| 207 | - { |
|
| 208 | - if (!isset($name)) { |
|
| 209 | - $headers = []; |
|
| 210 | - foreach ($this->headers as $collection) { |
|
| 211 | - $headers = array_merge($headers, $collection); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $headers; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $lowerName = strtolower($name ?? ''); |
|
| 218 | - if (!\array_key_exists($lowerName, $this->headers)) { |
|
| 219 | - return []; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $this->headers[$lowerName]; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Return the name of all Headers. |
|
| 227 | - * |
|
| 228 | - * @return array |
|
| 229 | - */ |
|
| 230 | - public function listAll() |
|
| 231 | - { |
|
| 232 | - $headers = $this->headers; |
|
| 233 | - if ($this->canSort()) { |
|
| 234 | - uksort($headers, [$this, 'sortHeaders']); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return array_keys($headers); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Remove the header with the given $name if it's set. |
|
| 242 | - * |
|
| 243 | - * If multiple headers match, the actual one may be specified by $index. |
|
| 244 | - * |
|
| 245 | - * @param string $name |
|
| 246 | - * @param int $index |
|
| 247 | - */ |
|
| 248 | - public function remove($name, $index = 0) |
|
| 249 | - { |
|
| 250 | - $lowerName = strtolower($name ?? ''); |
|
| 251 | - unset($this->headers[$lowerName][$index]); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Remove all headers with the given $name. |
|
| 256 | - * |
|
| 257 | - * @param string $name |
|
| 258 | - */ |
|
| 259 | - public function removeAll($name) |
|
| 260 | - { |
|
| 261 | - $lowerName = strtolower($name ?? ''); |
|
| 262 | - unset($this->headers[$lowerName]); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Define a list of Header names as an array in the correct order. |
|
| 267 | - * |
|
| 268 | - * These Headers will be output in the given order where present. |
|
| 269 | - */ |
|
| 270 | - public function defineOrdering(array $sequence) |
|
| 271 | - { |
|
| 272 | - $this->order = array_flip(array_map('strtolower', $sequence)); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Set a list of header names which must always be displayed when set. |
|
| 277 | - * |
|
| 278 | - * Usually headers without a field value won't be output unless set here. |
|
| 279 | - */ |
|
| 280 | - public function setAlwaysDisplayed(array $names) |
|
| 281 | - { |
|
| 282 | - $this->required = array_flip(array_map('strtolower', $names)); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Notify this observer that the entity's charset has changed. |
|
| 287 | - * |
|
| 288 | - * @param string $charset |
|
| 289 | - */ |
|
| 290 | - public function charsetChanged($charset) |
|
| 291 | - { |
|
| 292 | - $this->setCharset($charset); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Returns a string with a representation of all headers. |
|
| 297 | - * |
|
| 298 | - * @return string |
|
| 299 | - */ |
|
| 300 | - public function toString() |
|
| 301 | - { |
|
| 302 | - $string = ''; |
|
| 303 | - $headers = $this->headers; |
|
| 304 | - if ($this->canSort()) { |
|
| 305 | - uksort($headers, [$this, 'sortHeaders']); |
|
| 306 | - } |
|
| 307 | - foreach ($headers as $collection) { |
|
| 308 | - foreach ($collection as $header) { |
|
| 309 | - if ($this->isDisplayed($header) || '' != $header->getFieldBody()) { |
|
| 310 | - $string .= $header->toString(); |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $string; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Returns a string representation of this object. |
|
| 320 | - * |
|
| 321 | - * @return string |
|
| 322 | - * |
|
| 323 | - * @see toString() |
|
| 324 | - */ |
|
| 325 | - public function __toString() |
|
| 326 | - { |
|
| 327 | - return $this->toString(); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** Save a Header to the internal collection */ |
|
| 331 | - private function storeHeader($name, Swift_Mime_Header $header, $offset = null) |
|
| 332 | - { |
|
| 333 | - if (!isset($this->headers[strtolower($name ?? '')])) { |
|
| 334 | - $this->headers[strtolower($name ?? '')] = []; |
|
| 335 | - } |
|
| 336 | - if (!isset($offset)) { |
|
| 337 | - $this->headers[strtolower($name ?? '')][] = $header; |
|
| 338 | - } else { |
|
| 339 | - $this->headers[strtolower($name ?? '')][$offset] = $header; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** Test if the headers can be sorted */ |
|
| 344 | - private function canSort() |
|
| 345 | - { |
|
| 346 | - return \count($this->order) > 0; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** uksort() algorithm for Header ordering */ |
|
| 350 | - private function sortHeaders($a, $b) |
|
| 351 | - { |
|
| 352 | - $lowerA = strtolower($a ?? ''); |
|
| 353 | - $lowerB = strtolower($b ?? ''); |
|
| 354 | - $aPos = \array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1; |
|
| 355 | - $bPos = \array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1; |
|
| 356 | - |
|
| 357 | - if (-1 === $aPos && -1 === $bPos) { |
|
| 358 | - // just be sure to be determinist here |
|
| 359 | - return $a > $b ? -1 : 1; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (-1 == $aPos) { |
|
| 363 | - return 1; |
|
| 364 | - } elseif (-1 == $bPos) { |
|
| 365 | - return -1; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return $aPos < $bPos ? -1 : 1; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** Test if the given Header is always displayed */ |
|
| 372 | - private function isDisplayed(Swift_Mime_Header $header) |
|
| 373 | - { |
|
| 374 | - return \array_key_exists(strtolower($header->getFieldName() ?? ''), $this->required); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** Notify all Headers of the new charset */ |
|
| 378 | - private function notifyHeadersOfCharset($charset) |
|
| 379 | - { |
|
| 380 | - foreach ($this->headers as $headerGroup) { |
|
| 381 | - foreach ($headerGroup as $header) { |
|
| 382 | - $header->setCharset($charset); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Make a deep copy of object. |
|
| 389 | - */ |
|
| 390 | - public function __clone() |
|
| 391 | - { |
|
| 392 | - $this->factory = clone $this->factory; |
|
| 393 | - foreach ($this->headers as $groupKey => $headerGroup) { |
|
| 394 | - foreach ($headerGroup as $key => $header) { |
|
| 395 | - $this->headers[$groupKey][$key] = clone $header; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - } |
|
| 18 | + /** HeaderFactory */ |
|
| 19 | + private $factory; |
|
| 20 | + |
|
| 21 | + /** Collection of set Headers */ |
|
| 22 | + private $headers = []; |
|
| 23 | + |
|
| 24 | + /** Field ordering details */ |
|
| 25 | + private $order = []; |
|
| 26 | + |
|
| 27 | + /** List of fields which are required to be displayed */ |
|
| 28 | + private $required = []; |
|
| 29 | + |
|
| 30 | + /** The charset used by Headers */ |
|
| 31 | + private $charset; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Create a new SimpleHeaderSet with the given $factory. |
|
| 35 | + * |
|
| 36 | + * @param string $charset |
|
| 37 | + */ |
|
| 38 | + public function __construct(Swift_Mime_SimpleHeaderFactory $factory, $charset = null) |
|
| 39 | + { |
|
| 40 | + $this->factory = $factory; |
|
| 41 | + if (isset($charset)) { |
|
| 42 | + $this->setCharset($charset); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function newInstance() |
|
| 47 | + { |
|
| 48 | + return new self($this->factory); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Set the charset used by these headers. |
|
| 53 | + * |
|
| 54 | + * @param string $charset |
|
| 55 | + */ |
|
| 56 | + public function setCharset($charset) |
|
| 57 | + { |
|
| 58 | + $this->charset = $charset; |
|
| 59 | + $this->factory->charsetChanged($charset); |
|
| 60 | + $this->notifyHeadersOfCharset($charset); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Add a new Mailbox Header with a list of $addresses. |
|
| 65 | + * |
|
| 66 | + * @param string $name |
|
| 67 | + * @param array|string $addresses |
|
| 68 | + */ |
|
| 69 | + public function addMailboxHeader($name, $addresses = null) |
|
| 70 | + { |
|
| 71 | + $this->storeHeader($name, $this->factory->createMailboxHeader($name, $addresses)); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Add a new Date header using $dateTime. |
|
| 76 | + * |
|
| 77 | + * @param string $name |
|
| 78 | + */ |
|
| 79 | + public function addDateHeader($name, DateTimeInterface $dateTime = null) |
|
| 80 | + { |
|
| 81 | + $this->storeHeader($name, $this->factory->createDateHeader($name, $dateTime)); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Add a new basic text header with $name and $value. |
|
| 86 | + * |
|
| 87 | + * @param string $name |
|
| 88 | + * @param string $value |
|
| 89 | + */ |
|
| 90 | + public function addTextHeader($name, $value = null) |
|
| 91 | + { |
|
| 92 | + $this->storeHeader($name, $this->factory->createTextHeader($name, $value)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Add a new ParameterizedHeader with $name, $value and $params. |
|
| 97 | + * |
|
| 98 | + * @param string $name |
|
| 99 | + * @param string $value |
|
| 100 | + * @param array $params |
|
| 101 | + */ |
|
| 102 | + public function addParameterizedHeader($name, $value = null, $params = []) |
|
| 103 | + { |
|
| 104 | + $this->storeHeader($name, $this->factory->createParameterizedHeader($name, $value, $params)); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Add a new ID header for Message-ID or Content-ID. |
|
| 109 | + * |
|
| 110 | + * @param string $name |
|
| 111 | + * @param string|array $ids |
|
| 112 | + */ |
|
| 113 | + public function addIdHeader($name, $ids = null) |
|
| 114 | + { |
|
| 115 | + $this->storeHeader($name, $this->factory->createIdHeader($name, $ids)); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Add a new Path header with an address (path) in it. |
|
| 120 | + * |
|
| 121 | + * @param string $name |
|
| 122 | + * @param string $path |
|
| 123 | + */ |
|
| 124 | + public function addPathHeader($name, $path = null) |
|
| 125 | + { |
|
| 126 | + $this->storeHeader($name, $this->factory->createPathHeader($name, $path)); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Returns true if at least one header with the given $name exists. |
|
| 131 | + * |
|
| 132 | + * If multiple headers match, the actual one may be specified by $index. |
|
| 133 | + * |
|
| 134 | + * @param string $name |
|
| 135 | + * @param int $index |
|
| 136 | + * |
|
| 137 | + * @return bool |
|
| 138 | + */ |
|
| 139 | + public function has($name, $index = 0) |
|
| 140 | + { |
|
| 141 | + $lowerName = strtolower($name ?? ''); |
|
| 142 | + |
|
| 143 | + if (!\array_key_exists($lowerName, $this->headers)) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if (\func_num_args() < 2) { |
|
| 148 | + // index was not specified, so we only need to check that there is at least one header value set |
|
| 149 | + return (bool) \count($this->headers[$lowerName]); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return \array_key_exists($index, $this->headers[$lowerName]); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Set a header in the HeaderSet. |
|
| 157 | + * |
|
| 158 | + * The header may be a previously fetched header via {@link get()} or it may |
|
| 159 | + * be one that has been created separately. |
|
| 160 | + * |
|
| 161 | + * If $index is specified, the header will be inserted into the set at this |
|
| 162 | + * offset. |
|
| 163 | + * |
|
| 164 | + * @param int $index |
|
| 165 | + */ |
|
| 166 | + public function set(Swift_Mime_Header $header, $index = 0) |
|
| 167 | + { |
|
| 168 | + $this->storeHeader($header->getFieldName(), $header, $index); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Get the header with the given $name. |
|
| 173 | + * |
|
| 174 | + * If multiple headers match, the actual one may be specified by $index. |
|
| 175 | + * Returns NULL if none present. |
|
| 176 | + * |
|
| 177 | + * @param string $name |
|
| 178 | + * @param int $index |
|
| 179 | + * |
|
| 180 | + * @return Swift_Mime_Header|null |
|
| 181 | + */ |
|
| 182 | + public function get($name, $index = 0) |
|
| 183 | + { |
|
| 184 | + $name = strtolower($name ?? ''); |
|
| 185 | + |
|
| 186 | + if (\func_num_args() < 2) { |
|
| 187 | + if ($this->has($name)) { |
|
| 188 | + $values = array_values($this->headers[$name]); |
|
| 189 | + |
|
| 190 | + return array_shift($values); |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + if ($this->has($name, $index)) { |
|
| 194 | + return $this->headers[$name][$index]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get all headers with the given $name. |
|
| 201 | + * |
|
| 202 | + * @param string $name |
|
| 203 | + * |
|
| 204 | + * @return array |
|
| 205 | + */ |
|
| 206 | + public function getAll($name = null) |
|
| 207 | + { |
|
| 208 | + if (!isset($name)) { |
|
| 209 | + $headers = []; |
|
| 210 | + foreach ($this->headers as $collection) { |
|
| 211 | + $headers = array_merge($headers, $collection); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $headers; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $lowerName = strtolower($name ?? ''); |
|
| 218 | + if (!\array_key_exists($lowerName, $this->headers)) { |
|
| 219 | + return []; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $this->headers[$lowerName]; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Return the name of all Headers. |
|
| 227 | + * |
|
| 228 | + * @return array |
|
| 229 | + */ |
|
| 230 | + public function listAll() |
|
| 231 | + { |
|
| 232 | + $headers = $this->headers; |
|
| 233 | + if ($this->canSort()) { |
|
| 234 | + uksort($headers, [$this, 'sortHeaders']); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return array_keys($headers); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Remove the header with the given $name if it's set. |
|
| 242 | + * |
|
| 243 | + * If multiple headers match, the actual one may be specified by $index. |
|
| 244 | + * |
|
| 245 | + * @param string $name |
|
| 246 | + * @param int $index |
|
| 247 | + */ |
|
| 248 | + public function remove($name, $index = 0) |
|
| 249 | + { |
|
| 250 | + $lowerName = strtolower($name ?? ''); |
|
| 251 | + unset($this->headers[$lowerName][$index]); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Remove all headers with the given $name. |
|
| 256 | + * |
|
| 257 | + * @param string $name |
|
| 258 | + */ |
|
| 259 | + public function removeAll($name) |
|
| 260 | + { |
|
| 261 | + $lowerName = strtolower($name ?? ''); |
|
| 262 | + unset($this->headers[$lowerName]); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Define a list of Header names as an array in the correct order. |
|
| 267 | + * |
|
| 268 | + * These Headers will be output in the given order where present. |
|
| 269 | + */ |
|
| 270 | + public function defineOrdering(array $sequence) |
|
| 271 | + { |
|
| 272 | + $this->order = array_flip(array_map('strtolower', $sequence)); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Set a list of header names which must always be displayed when set. |
|
| 277 | + * |
|
| 278 | + * Usually headers without a field value won't be output unless set here. |
|
| 279 | + */ |
|
| 280 | + public function setAlwaysDisplayed(array $names) |
|
| 281 | + { |
|
| 282 | + $this->required = array_flip(array_map('strtolower', $names)); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Notify this observer that the entity's charset has changed. |
|
| 287 | + * |
|
| 288 | + * @param string $charset |
|
| 289 | + */ |
|
| 290 | + public function charsetChanged($charset) |
|
| 291 | + { |
|
| 292 | + $this->setCharset($charset); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Returns a string with a representation of all headers. |
|
| 297 | + * |
|
| 298 | + * @return string |
|
| 299 | + */ |
|
| 300 | + public function toString() |
|
| 301 | + { |
|
| 302 | + $string = ''; |
|
| 303 | + $headers = $this->headers; |
|
| 304 | + if ($this->canSort()) { |
|
| 305 | + uksort($headers, [$this, 'sortHeaders']); |
|
| 306 | + } |
|
| 307 | + foreach ($headers as $collection) { |
|
| 308 | + foreach ($collection as $header) { |
|
| 309 | + if ($this->isDisplayed($header) || '' != $header->getFieldBody()) { |
|
| 310 | + $string .= $header->toString(); |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $string; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Returns a string representation of this object. |
|
| 320 | + * |
|
| 321 | + * @return string |
|
| 322 | + * |
|
| 323 | + * @see toString() |
|
| 324 | + */ |
|
| 325 | + public function __toString() |
|
| 326 | + { |
|
| 327 | + return $this->toString(); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** Save a Header to the internal collection */ |
|
| 331 | + private function storeHeader($name, Swift_Mime_Header $header, $offset = null) |
|
| 332 | + { |
|
| 333 | + if (!isset($this->headers[strtolower($name ?? '')])) { |
|
| 334 | + $this->headers[strtolower($name ?? '')] = []; |
|
| 335 | + } |
|
| 336 | + if (!isset($offset)) { |
|
| 337 | + $this->headers[strtolower($name ?? '')][] = $header; |
|
| 338 | + } else { |
|
| 339 | + $this->headers[strtolower($name ?? '')][$offset] = $header; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** Test if the headers can be sorted */ |
|
| 344 | + private function canSort() |
|
| 345 | + { |
|
| 346 | + return \count($this->order) > 0; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** uksort() algorithm for Header ordering */ |
|
| 350 | + private function sortHeaders($a, $b) |
|
| 351 | + { |
|
| 352 | + $lowerA = strtolower($a ?? ''); |
|
| 353 | + $lowerB = strtolower($b ?? ''); |
|
| 354 | + $aPos = \array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1; |
|
| 355 | + $bPos = \array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1; |
|
| 356 | + |
|
| 357 | + if (-1 === $aPos && -1 === $bPos) { |
|
| 358 | + // just be sure to be determinist here |
|
| 359 | + return $a > $b ? -1 : 1; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (-1 == $aPos) { |
|
| 363 | + return 1; |
|
| 364 | + } elseif (-1 == $bPos) { |
|
| 365 | + return -1; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return $aPos < $bPos ? -1 : 1; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** Test if the given Header is always displayed */ |
|
| 372 | + private function isDisplayed(Swift_Mime_Header $header) |
|
| 373 | + { |
|
| 374 | + return \array_key_exists(strtolower($header->getFieldName() ?? ''), $this->required); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** Notify all Headers of the new charset */ |
|
| 378 | + private function notifyHeadersOfCharset($charset) |
|
| 379 | + { |
|
| 380 | + foreach ($this->headers as $headerGroup) { |
|
| 381 | + foreach ($headerGroup as $header) { |
|
| 382 | + $header->setCharset($charset); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Make a deep copy of object. |
|
| 389 | + */ |
|
| 390 | + public function __clone() |
|
| 391 | + { |
|
| 392 | + $this->factory = clone $this->factory; |
|
| 393 | + foreach ($this->headers as $groupKey => $headerGroup) { |
|
| 394 | + foreach ($headerGroup as $key => $header) { |
|
| 395 | + $this->headers[$groupKey][$key] = clone $header; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | 399 | } |
@@ -15,86 +15,86 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_Preferences |
| 17 | 17 | { |
| 18 | - /** Singleton instance */ |
|
| 19 | - private static $instance = null; |
|
| 18 | + /** Singleton instance */ |
|
| 19 | + private static $instance = null; |
|
| 20 | 20 | |
| 21 | - /** Constructor not to be used */ |
|
| 22 | - private function __construct() |
|
| 23 | - { |
|
| 24 | - } |
|
| 21 | + /** Constructor not to be used */ |
|
| 22 | + private function __construct() |
|
| 23 | + { |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Gets the instance of Preferences. |
|
| 28 | - * |
|
| 29 | - * @return self |
|
| 30 | - */ |
|
| 31 | - public static function getInstance() |
|
| 32 | - { |
|
| 33 | - if (!isset(self::$instance)) { |
|
| 34 | - self::$instance = new self(); |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Gets the instance of Preferences. |
|
| 28 | + * |
|
| 29 | + * @return self |
|
| 30 | + */ |
|
| 31 | + public static function getInstance() |
|
| 32 | + { |
|
| 33 | + if (!isset(self::$instance)) { |
|
| 34 | + self::$instance = new self(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - return self::$instance; |
|
| 38 | - } |
|
| 37 | + return self::$instance; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the default charset used. |
|
| 42 | - * |
|
| 43 | - * @param string $charset |
|
| 44 | - * |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function setCharset($charset) |
|
| 48 | - { |
|
| 49 | - Swift_DependencyContainer::getInstance()->register('properties.charset')->asValue($charset); |
|
| 40 | + /** |
|
| 41 | + * Set the default charset used. |
|
| 42 | + * |
|
| 43 | + * @param string $charset |
|
| 44 | + * |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function setCharset($charset) |
|
| 48 | + { |
|
| 49 | + Swift_DependencyContainer::getInstance()->register('properties.charset')->asValue($charset); |
|
| 50 | 50 | |
| 51 | - return $this; |
|
| 52 | - } |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Set the directory where temporary files can be saved. |
|
| 56 | - * |
|
| 57 | - * @param string $dir |
|
| 58 | - * |
|
| 59 | - * @return $this |
|
| 60 | - */ |
|
| 61 | - public function setTempDir($dir) |
|
| 62 | - { |
|
| 63 | - Swift_DependencyContainer::getInstance()->register('tempdir')->asValue($dir); |
|
| 54 | + /** |
|
| 55 | + * Set the directory where temporary files can be saved. |
|
| 56 | + * |
|
| 57 | + * @param string $dir |
|
| 58 | + * |
|
| 59 | + * @return $this |
|
| 60 | + */ |
|
| 61 | + public function setTempDir($dir) |
|
| 62 | + { |
|
| 63 | + Swift_DependencyContainer::getInstance()->register('tempdir')->asValue($dir); |
|
| 64 | 64 | |
| 65 | - return $this; |
|
| 66 | - } |
|
| 65 | + return $this; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Set the type of cache to use (i.e. "disk" or "array"). |
|
| 70 | - * |
|
| 71 | - * @param string $type |
|
| 72 | - * |
|
| 73 | - * @return $this |
|
| 74 | - */ |
|
| 75 | - public function setCacheType($type) |
|
| 76 | - { |
|
| 77 | - Swift_DependencyContainer::getInstance()->register('cache')->asAliasOf(sprintf('cache.%s', $type)); |
|
| 68 | + /** |
|
| 69 | + * Set the type of cache to use (i.e. "disk" or "array"). |
|
| 70 | + * |
|
| 71 | + * @param string $type |
|
| 72 | + * |
|
| 73 | + * @return $this |
|
| 74 | + */ |
|
| 75 | + public function setCacheType($type) |
|
| 76 | + { |
|
| 77 | + Swift_DependencyContainer::getInstance()->register('cache')->asAliasOf(sprintf('cache.%s', $type)); |
|
| 78 | 78 | |
| 79 | - return $this; |
|
| 80 | - } |
|
| 79 | + return $this; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Set the QuotedPrintable dot escaper preference. |
|
| 84 | - * |
|
| 85 | - * @param bool $dotEscape |
|
| 86 | - * |
|
| 87 | - * @return $this |
|
| 88 | - */ |
|
| 89 | - public function setQPDotEscape($dotEscape) |
|
| 90 | - { |
|
| 91 | - $dotEscape = !empty($dotEscape); |
|
| 92 | - Swift_DependencyContainer::getInstance() |
|
| 93 | - ->register('mime.qpcontentencoder') |
|
| 94 | - ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') |
|
| 95 | - ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) |
|
| 96 | - ->addConstructorValue($dotEscape); |
|
| 82 | + /** |
|
| 83 | + * Set the QuotedPrintable dot escaper preference. |
|
| 84 | + * |
|
| 85 | + * @param bool $dotEscape |
|
| 86 | + * |
|
| 87 | + * @return $this |
|
| 88 | + */ |
|
| 89 | + public function setQPDotEscape($dotEscape) |
|
| 90 | + { |
|
| 91 | + $dotEscape = !empty($dotEscape); |
|
| 92 | + Swift_DependencyContainer::getInstance() |
|
| 93 | + ->register('mime.qpcontentencoder') |
|
| 94 | + ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') |
|
| 95 | + ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) |
|
| 96 | + ->addConstructorValue($dotEscape); |
|
| 97 | 97 | |
| 98 | - return $this; |
|
| 99 | - } |
|
| 98 | + return $this; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -15,19 +15,19 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Creates a new LoadBalancedTransport with $transports. |
|
| 20 | - * |
|
| 21 | - * @param array $transports |
|
| 22 | - */ |
|
| 23 | - public function __construct($transports = []) |
|
| 24 | - { |
|
| 25 | - \call_user_func_array( |
|
| 26 | - [$this, 'Swift_Transport_LoadBalancedTransport::__construct'], |
|
| 27 | - Swift_DependencyContainer::getInstance() |
|
| 28 | - ->createDependenciesFor('transport.loadbalanced') |
|
| 29 | - ); |
|
| 18 | + /** |
|
| 19 | + * Creates a new LoadBalancedTransport with $transports. |
|
| 20 | + * |
|
| 21 | + * @param array $transports |
|
| 22 | + */ |
|
| 23 | + public function __construct($transports = []) |
|
| 24 | + { |
|
| 25 | + \call_user_func_array( |
|
| 26 | + [$this, 'Swift_Transport_LoadBalancedTransport::__construct'], |
|
| 27 | + Swift_DependencyContainer::getInstance() |
|
| 28 | + ->createDependenciesFor('transport.loadbalanced') |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | - $this->setTransports($transports); |
|
| 32 | - } |
|
| 31 | + $this->setTransports($transports); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -16,17 +16,17 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Swift_AddressEncoderException extends Swift_RfcComplianceException |
| 18 | 18 | { |
| 19 | - protected $address; |
|
| 19 | + protected $address; |
|
| 20 | 20 | |
| 21 | - public function __construct(string $message, string $address) |
|
| 22 | - { |
|
| 23 | - parent::__construct($message); |
|
| 21 | + public function __construct(string $message, string $address) |
|
| 22 | + { |
|
| 23 | + parent::__construct($message); |
|
| 24 | 24 | |
| 25 | - $this->address = $address; |
|
| 26 | - } |
|
| 25 | + $this->address = $address; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function getAddress(): string |
|
| 29 | - { |
|
| 30 | - return $this->address; |
|
| 31 | - } |
|
| 28 | + public function getAddress(): string |
|
| 29 | + { |
|
| 30 | + return $this->address; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -16,82 +16,82 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * The number of bytes in a single character. |
|
| 21 | - * |
|
| 22 | - * @var int |
|
| 23 | - */ |
|
| 24 | - private $width; |
|
| 19 | + /** |
|
| 20 | + * The number of bytes in a single character. |
|
| 21 | + * |
|
| 22 | + * @var int |
|
| 23 | + */ |
|
| 24 | + private $width; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Creates a new GenericFixedWidthReader using $width bytes per character. |
|
| 28 | - * |
|
| 29 | - * @param int $width |
|
| 30 | - */ |
|
| 31 | - public function __construct($width) |
|
| 32 | - { |
|
| 33 | - $this->width = $width; |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Creates a new GenericFixedWidthReader using $width bytes per character. |
|
| 28 | + * |
|
| 29 | + * @param int $width |
|
| 30 | + */ |
|
| 31 | + public function __construct($width) |
|
| 32 | + { |
|
| 33 | + $this->width = $width; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Returns the complete character map. |
|
| 38 | - * |
|
| 39 | - * @param string $string |
|
| 40 | - * @param int $startOffset |
|
| 41 | - * @param array $currentMap |
|
| 42 | - * @param mixed $ignoredChars |
|
| 43 | - * |
|
| 44 | - * @return int |
|
| 45 | - */ |
|
| 46 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 47 | - { |
|
| 48 | - $strlen = \strlen($string); |
|
| 49 | - // % and / are CPU intensive, so, maybe find a better way |
|
| 50 | - $ignored = $strlen % $this->width; |
|
| 51 | - $ignoredChars = $ignored ? substr($string, -$ignored) : ''; |
|
| 52 | - $currentMap = $this->width; |
|
| 36 | + /** |
|
| 37 | + * Returns the complete character map. |
|
| 38 | + * |
|
| 39 | + * @param string $string |
|
| 40 | + * @param int $startOffset |
|
| 41 | + * @param array $currentMap |
|
| 42 | + * @param mixed $ignoredChars |
|
| 43 | + * |
|
| 44 | + * @return int |
|
| 45 | + */ |
|
| 46 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 47 | + { |
|
| 48 | + $strlen = \strlen($string); |
|
| 49 | + // % and / are CPU intensive, so, maybe find a better way |
|
| 50 | + $ignored = $strlen % $this->width; |
|
| 51 | + $ignoredChars = $ignored ? substr($string, -$ignored) : ''; |
|
| 52 | + $currentMap = $this->width; |
|
| 53 | 53 | |
| 54 | - return ($strlen - $ignored) / $this->width; |
|
| 55 | - } |
|
| 54 | + return ($strlen - $ignored) / $this->width; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Returns the mapType. |
|
| 59 | - * |
|
| 60 | - * @return int |
|
| 61 | - */ |
|
| 62 | - public function getMapType() |
|
| 63 | - { |
|
| 64 | - return self::MAP_TYPE_FIXED_LEN; |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Returns the mapType. |
|
| 59 | + * |
|
| 60 | + * @return int |
|
| 61 | + */ |
|
| 62 | + public function getMapType() |
|
| 63 | + { |
|
| 64 | + return self::MAP_TYPE_FIXED_LEN; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Returns an integer which specifies how many more bytes to read. |
|
| 69 | - * |
|
| 70 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 71 | - * this method again. |
|
| 72 | - * |
|
| 73 | - * A value of zero means this is already a valid character. |
|
| 74 | - * A value of -1 means this cannot possibly be a valid character. |
|
| 75 | - * |
|
| 76 | - * @param string $bytes |
|
| 77 | - * @param int $size |
|
| 78 | - * |
|
| 79 | - * @return int |
|
| 80 | - */ |
|
| 81 | - public function validateByteSequence($bytes, $size) |
|
| 82 | - { |
|
| 83 | - $needed = $this->width - $size; |
|
| 67 | + /** |
|
| 68 | + * Returns an integer which specifies how many more bytes to read. |
|
| 69 | + * |
|
| 70 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 71 | + * this method again. |
|
| 72 | + * |
|
| 73 | + * A value of zero means this is already a valid character. |
|
| 74 | + * A value of -1 means this cannot possibly be a valid character. |
|
| 75 | + * |
|
| 76 | + * @param string $bytes |
|
| 77 | + * @param int $size |
|
| 78 | + * |
|
| 79 | + * @return int |
|
| 80 | + */ |
|
| 81 | + public function validateByteSequence($bytes, $size) |
|
| 82 | + { |
|
| 83 | + $needed = $this->width - $size; |
|
| 84 | 84 | |
| 85 | - return $needed > -1 ? $needed : -1; |
|
| 86 | - } |
|
| 85 | + return $needed > -1 ? $needed : -1; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Returns the number of bytes which should be read to start each character. |
|
| 90 | - * |
|
| 91 | - * @return int |
|
| 92 | - */ |
|
| 93 | - public function getInitialByteSize() |
|
| 94 | - { |
|
| 95 | - return $this->width; |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * Returns the number of bytes which should be read to start each character. |
|
| 90 | + * |
|
| 91 | + * @return int |
|
| 92 | + */ |
|
| 93 | + public function getInitialByteSize() |
|
| 94 | + { |
|
| 95 | + return $this->width; |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -16,161 +16,161 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader |
| 18 | 18 | { |
| 19 | - /** Pre-computed for optimization */ |
|
| 20 | - private static $length_map = [ |
|
| 21 | - // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
|
| 22 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N |
|
| 23 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N |
|
| 24 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N |
|
| 25 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N |
|
| 26 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N |
|
| 27 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N |
|
| 28 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N |
|
| 29 | - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N |
|
| 30 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N |
|
| 31 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N |
|
| 32 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN |
|
| 33 | - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN |
|
| 34 | - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN |
|
| 35 | - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN |
|
| 36 | - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN |
|
| 37 | - 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN |
|
| 38 | - ]; |
|
| 19 | + /** Pre-computed for optimization */ |
|
| 20 | + private static $length_map = [ |
|
| 21 | + // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F |
|
| 22 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N |
|
| 23 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N |
|
| 24 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N |
|
| 25 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N |
|
| 26 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N |
|
| 27 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N |
|
| 28 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N |
|
| 29 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N |
|
| 30 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N |
|
| 31 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N |
|
| 32 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN |
|
| 33 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN |
|
| 34 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN |
|
| 35 | + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN |
|
| 36 | + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN |
|
| 37 | + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN |
|
| 38 | + ]; |
|
| 39 | 39 | |
| 40 | - private static $s_length_map = [ |
|
| 41 | - "\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1, |
|
| 42 | - "\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1, |
|
| 43 | - "\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1, |
|
| 44 | - "\x18" => 1, "\x19" => 1, "\x1a" => 1, "\x1b" => 1, "\x1c" => 1, "\x1d" => 1, "\x1e" => 1, "\x1f" => 1, |
|
| 45 | - "\x20" => 1, "\x21" => 1, "\x22" => 1, "\x23" => 1, "\x24" => 1, "\x25" => 1, "\x26" => 1, "\x27" => 1, |
|
| 46 | - "\x28" => 1, "\x29" => 1, "\x2a" => 1, "\x2b" => 1, "\x2c" => 1, "\x2d" => 1, "\x2e" => 1, "\x2f" => 1, |
|
| 47 | - "\x30" => 1, "\x31" => 1, "\x32" => 1, "\x33" => 1, "\x34" => 1, "\x35" => 1, "\x36" => 1, "\x37" => 1, |
|
| 48 | - "\x38" => 1, "\x39" => 1, "\x3a" => 1, "\x3b" => 1, "\x3c" => 1, "\x3d" => 1, "\x3e" => 1, "\x3f" => 1, |
|
| 49 | - "\x40" => 1, "\x41" => 1, "\x42" => 1, "\x43" => 1, "\x44" => 1, "\x45" => 1, "\x46" => 1, "\x47" => 1, |
|
| 50 | - "\x48" => 1, "\x49" => 1, "\x4a" => 1, "\x4b" => 1, "\x4c" => 1, "\x4d" => 1, "\x4e" => 1, "\x4f" => 1, |
|
| 51 | - "\x50" => 1, "\x51" => 1, "\x52" => 1, "\x53" => 1, "\x54" => 1, "\x55" => 1, "\x56" => 1, "\x57" => 1, |
|
| 52 | - "\x58" => 1, "\x59" => 1, "\x5a" => 1, "\x5b" => 1, "\x5c" => 1, "\x5d" => 1, "\x5e" => 1, "\x5f" => 1, |
|
| 53 | - "\x60" => 1, "\x61" => 1, "\x62" => 1, "\x63" => 1, "\x64" => 1, "\x65" => 1, "\x66" => 1, "\x67" => 1, |
|
| 54 | - "\x68" => 1, "\x69" => 1, "\x6a" => 1, "\x6b" => 1, "\x6c" => 1, "\x6d" => 1, "\x6e" => 1, "\x6f" => 1, |
|
| 55 | - "\x70" => 1, "\x71" => 1, "\x72" => 1, "\x73" => 1, "\x74" => 1, "\x75" => 1, "\x76" => 1, "\x77" => 1, |
|
| 56 | - "\x78" => 1, "\x79" => 1, "\x7a" => 1, "\x7b" => 1, "\x7c" => 1, "\x7d" => 1, "\x7e" => 1, "\x7f" => 1, |
|
| 57 | - "\x80" => 0, "\x81" => 0, "\x82" => 0, "\x83" => 0, "\x84" => 0, "\x85" => 0, "\x86" => 0, "\x87" => 0, |
|
| 58 | - "\x88" => 0, "\x89" => 0, "\x8a" => 0, "\x8b" => 0, "\x8c" => 0, "\x8d" => 0, "\x8e" => 0, "\x8f" => 0, |
|
| 59 | - "\x90" => 0, "\x91" => 0, "\x92" => 0, "\x93" => 0, "\x94" => 0, "\x95" => 0, "\x96" => 0, "\x97" => 0, |
|
| 60 | - "\x98" => 0, "\x99" => 0, "\x9a" => 0, "\x9b" => 0, "\x9c" => 0, "\x9d" => 0, "\x9e" => 0, "\x9f" => 0, |
|
| 61 | - "\xa0" => 0, "\xa1" => 0, "\xa2" => 0, "\xa3" => 0, "\xa4" => 0, "\xa5" => 0, "\xa6" => 0, "\xa7" => 0, |
|
| 62 | - "\xa8" => 0, "\xa9" => 0, "\xaa" => 0, "\xab" => 0, "\xac" => 0, "\xad" => 0, "\xae" => 0, "\xaf" => 0, |
|
| 63 | - "\xb0" => 0, "\xb1" => 0, "\xb2" => 0, "\xb3" => 0, "\xb4" => 0, "\xb5" => 0, "\xb6" => 0, "\xb7" => 0, |
|
| 64 | - "\xb8" => 0, "\xb9" => 0, "\xba" => 0, "\xbb" => 0, "\xbc" => 0, "\xbd" => 0, "\xbe" => 0, "\xbf" => 0, |
|
| 65 | - "\xc0" => 2, "\xc1" => 2, "\xc2" => 2, "\xc3" => 2, "\xc4" => 2, "\xc5" => 2, "\xc6" => 2, "\xc7" => 2, |
|
| 66 | - "\xc8" => 2, "\xc9" => 2, "\xca" => 2, "\xcb" => 2, "\xcc" => 2, "\xcd" => 2, "\xce" => 2, "\xcf" => 2, |
|
| 67 | - "\xd0" => 2, "\xd1" => 2, "\xd2" => 2, "\xd3" => 2, "\xd4" => 2, "\xd5" => 2, "\xd6" => 2, "\xd7" => 2, |
|
| 68 | - "\xd8" => 2, "\xd9" => 2, "\xda" => 2, "\xdb" => 2, "\xdc" => 2, "\xdd" => 2, "\xde" => 2, "\xdf" => 2, |
|
| 69 | - "\xe0" => 3, "\xe1" => 3, "\xe2" => 3, "\xe3" => 3, "\xe4" => 3, "\xe5" => 3, "\xe6" => 3, "\xe7" => 3, |
|
| 70 | - "\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3, |
|
| 71 | - "\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4, |
|
| 72 | - "\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0, |
|
| 73 | - ]; |
|
| 40 | + private static $s_length_map = [ |
|
| 41 | + "\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1, |
|
| 42 | + "\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1, |
|
| 43 | + "\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1, |
|
| 44 | + "\x18" => 1, "\x19" => 1, "\x1a" => 1, "\x1b" => 1, "\x1c" => 1, "\x1d" => 1, "\x1e" => 1, "\x1f" => 1, |
|
| 45 | + "\x20" => 1, "\x21" => 1, "\x22" => 1, "\x23" => 1, "\x24" => 1, "\x25" => 1, "\x26" => 1, "\x27" => 1, |
|
| 46 | + "\x28" => 1, "\x29" => 1, "\x2a" => 1, "\x2b" => 1, "\x2c" => 1, "\x2d" => 1, "\x2e" => 1, "\x2f" => 1, |
|
| 47 | + "\x30" => 1, "\x31" => 1, "\x32" => 1, "\x33" => 1, "\x34" => 1, "\x35" => 1, "\x36" => 1, "\x37" => 1, |
|
| 48 | + "\x38" => 1, "\x39" => 1, "\x3a" => 1, "\x3b" => 1, "\x3c" => 1, "\x3d" => 1, "\x3e" => 1, "\x3f" => 1, |
|
| 49 | + "\x40" => 1, "\x41" => 1, "\x42" => 1, "\x43" => 1, "\x44" => 1, "\x45" => 1, "\x46" => 1, "\x47" => 1, |
|
| 50 | + "\x48" => 1, "\x49" => 1, "\x4a" => 1, "\x4b" => 1, "\x4c" => 1, "\x4d" => 1, "\x4e" => 1, "\x4f" => 1, |
|
| 51 | + "\x50" => 1, "\x51" => 1, "\x52" => 1, "\x53" => 1, "\x54" => 1, "\x55" => 1, "\x56" => 1, "\x57" => 1, |
|
| 52 | + "\x58" => 1, "\x59" => 1, "\x5a" => 1, "\x5b" => 1, "\x5c" => 1, "\x5d" => 1, "\x5e" => 1, "\x5f" => 1, |
|
| 53 | + "\x60" => 1, "\x61" => 1, "\x62" => 1, "\x63" => 1, "\x64" => 1, "\x65" => 1, "\x66" => 1, "\x67" => 1, |
|
| 54 | + "\x68" => 1, "\x69" => 1, "\x6a" => 1, "\x6b" => 1, "\x6c" => 1, "\x6d" => 1, "\x6e" => 1, "\x6f" => 1, |
|
| 55 | + "\x70" => 1, "\x71" => 1, "\x72" => 1, "\x73" => 1, "\x74" => 1, "\x75" => 1, "\x76" => 1, "\x77" => 1, |
|
| 56 | + "\x78" => 1, "\x79" => 1, "\x7a" => 1, "\x7b" => 1, "\x7c" => 1, "\x7d" => 1, "\x7e" => 1, "\x7f" => 1, |
|
| 57 | + "\x80" => 0, "\x81" => 0, "\x82" => 0, "\x83" => 0, "\x84" => 0, "\x85" => 0, "\x86" => 0, "\x87" => 0, |
|
| 58 | + "\x88" => 0, "\x89" => 0, "\x8a" => 0, "\x8b" => 0, "\x8c" => 0, "\x8d" => 0, "\x8e" => 0, "\x8f" => 0, |
|
| 59 | + "\x90" => 0, "\x91" => 0, "\x92" => 0, "\x93" => 0, "\x94" => 0, "\x95" => 0, "\x96" => 0, "\x97" => 0, |
|
| 60 | + "\x98" => 0, "\x99" => 0, "\x9a" => 0, "\x9b" => 0, "\x9c" => 0, "\x9d" => 0, "\x9e" => 0, "\x9f" => 0, |
|
| 61 | + "\xa0" => 0, "\xa1" => 0, "\xa2" => 0, "\xa3" => 0, "\xa4" => 0, "\xa5" => 0, "\xa6" => 0, "\xa7" => 0, |
|
| 62 | + "\xa8" => 0, "\xa9" => 0, "\xaa" => 0, "\xab" => 0, "\xac" => 0, "\xad" => 0, "\xae" => 0, "\xaf" => 0, |
|
| 63 | + "\xb0" => 0, "\xb1" => 0, "\xb2" => 0, "\xb3" => 0, "\xb4" => 0, "\xb5" => 0, "\xb6" => 0, "\xb7" => 0, |
|
| 64 | + "\xb8" => 0, "\xb9" => 0, "\xba" => 0, "\xbb" => 0, "\xbc" => 0, "\xbd" => 0, "\xbe" => 0, "\xbf" => 0, |
|
| 65 | + "\xc0" => 2, "\xc1" => 2, "\xc2" => 2, "\xc3" => 2, "\xc4" => 2, "\xc5" => 2, "\xc6" => 2, "\xc7" => 2, |
|
| 66 | + "\xc8" => 2, "\xc9" => 2, "\xca" => 2, "\xcb" => 2, "\xcc" => 2, "\xcd" => 2, "\xce" => 2, "\xcf" => 2, |
|
| 67 | + "\xd0" => 2, "\xd1" => 2, "\xd2" => 2, "\xd3" => 2, "\xd4" => 2, "\xd5" => 2, "\xd6" => 2, "\xd7" => 2, |
|
| 68 | + "\xd8" => 2, "\xd9" => 2, "\xda" => 2, "\xdb" => 2, "\xdc" => 2, "\xdd" => 2, "\xde" => 2, "\xdf" => 2, |
|
| 69 | + "\xe0" => 3, "\xe1" => 3, "\xe2" => 3, "\xe3" => 3, "\xe4" => 3, "\xe5" => 3, "\xe6" => 3, "\xe7" => 3, |
|
| 70 | + "\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3, |
|
| 71 | + "\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4, |
|
| 72 | + "\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0, |
|
| 73 | + ]; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Returns the complete character map. |
|
| 77 | - * |
|
| 78 | - * @param string $string |
|
| 79 | - * @param int $startOffset |
|
| 80 | - * @param array $currentMap |
|
| 81 | - * @param mixed $ignoredChars |
|
| 82 | - * |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 86 | - { |
|
| 87 | - if (!isset($currentMap['i']) || !isset($currentMap['p'])) { |
|
| 88 | - $currentMap['p'] = $currentMap['i'] = []; |
|
| 89 | - } |
|
| 75 | + /** |
|
| 76 | + * Returns the complete character map. |
|
| 77 | + * |
|
| 78 | + * @param string $string |
|
| 79 | + * @param int $startOffset |
|
| 80 | + * @param array $currentMap |
|
| 81 | + * @param mixed $ignoredChars |
|
| 82 | + * |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 86 | + { |
|
| 87 | + if (!isset($currentMap['i']) || !isset($currentMap['p'])) { |
|
| 88 | + $currentMap['p'] = $currentMap['i'] = []; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - $strlen = \strlen($string); |
|
| 92 | - $charPos = \count($currentMap['p']); |
|
| 93 | - $foundChars = 0; |
|
| 94 | - $invalid = false; |
|
| 95 | - for ($i = 0; $i < $strlen; ++$i) { |
|
| 96 | - $char = $string[$i]; |
|
| 97 | - $size = self::$s_length_map[$char]; |
|
| 98 | - if (0 == $size) { |
|
| 99 | - /* char is invalid, we must wait for a resync */ |
|
| 100 | - $invalid = true; |
|
| 101 | - continue; |
|
| 102 | - } else { |
|
| 103 | - if (true === $invalid) { |
|
| 104 | - /* We mark the chars as invalid and start a new char */ |
|
| 105 | - $currentMap['p'][$charPos + $foundChars] = $startOffset + $i; |
|
| 106 | - $currentMap['i'][$charPos + $foundChars] = true; |
|
| 107 | - ++$foundChars; |
|
| 108 | - $invalid = false; |
|
| 109 | - } |
|
| 110 | - if (($i + $size) > $strlen) { |
|
| 111 | - $ignoredChars = substr($string, $i); |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - for ($j = 1; $j < $size; ++$j) { |
|
| 115 | - $char = $string[$i + $j]; |
|
| 116 | - if ($char > "\x7F" && $char < "\xC0") { |
|
| 117 | - // Valid - continue parsing |
|
| 118 | - } else { |
|
| 119 | - /* char is invalid, we must wait for a resync */ |
|
| 120 | - $invalid = true; |
|
| 121 | - continue 2; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - /* Ok we got a complete char here */ |
|
| 125 | - $currentMap['p'][$charPos + $foundChars] = $startOffset + $i + $size; |
|
| 126 | - $i += $j - 1; |
|
| 127 | - ++$foundChars; |
|
| 128 | - } |
|
| 129 | - } |
|
| 91 | + $strlen = \strlen($string); |
|
| 92 | + $charPos = \count($currentMap['p']); |
|
| 93 | + $foundChars = 0; |
|
| 94 | + $invalid = false; |
|
| 95 | + for ($i = 0; $i < $strlen; ++$i) { |
|
| 96 | + $char = $string[$i]; |
|
| 97 | + $size = self::$s_length_map[$char]; |
|
| 98 | + if (0 == $size) { |
|
| 99 | + /* char is invalid, we must wait for a resync */ |
|
| 100 | + $invalid = true; |
|
| 101 | + continue; |
|
| 102 | + } else { |
|
| 103 | + if (true === $invalid) { |
|
| 104 | + /* We mark the chars as invalid and start a new char */ |
|
| 105 | + $currentMap['p'][$charPos + $foundChars] = $startOffset + $i; |
|
| 106 | + $currentMap['i'][$charPos + $foundChars] = true; |
|
| 107 | + ++$foundChars; |
|
| 108 | + $invalid = false; |
|
| 109 | + } |
|
| 110 | + if (($i + $size) > $strlen) { |
|
| 111 | + $ignoredChars = substr($string, $i); |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + for ($j = 1; $j < $size; ++$j) { |
|
| 115 | + $char = $string[$i + $j]; |
|
| 116 | + if ($char > "\x7F" && $char < "\xC0") { |
|
| 117 | + // Valid - continue parsing |
|
| 118 | + } else { |
|
| 119 | + /* char is invalid, we must wait for a resync */ |
|
| 120 | + $invalid = true; |
|
| 121 | + continue 2; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + /* Ok we got a complete char here */ |
|
| 125 | + $currentMap['p'][$charPos + $foundChars] = $startOffset + $i + $size; |
|
| 126 | + $i += $j - 1; |
|
| 127 | + ++$foundChars; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - return $foundChars; |
|
| 132 | - } |
|
| 131 | + return $foundChars; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Returns mapType. |
|
| 136 | - * |
|
| 137 | - * @return int mapType |
|
| 138 | - */ |
|
| 139 | - public function getMapType() |
|
| 140 | - { |
|
| 141 | - return self::MAP_TYPE_POSITIONS; |
|
| 142 | - } |
|
| 134 | + /** |
|
| 135 | + * Returns mapType. |
|
| 136 | + * |
|
| 137 | + * @return int mapType |
|
| 138 | + */ |
|
| 139 | + public function getMapType() |
|
| 140 | + { |
|
| 141 | + return self::MAP_TYPE_POSITIONS; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Returns an integer which specifies how many more bytes to read. |
|
| 146 | - * |
|
| 147 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 148 | - * this method again. |
|
| 149 | - * A value of zero means this is already a valid character. |
|
| 150 | - * A value of -1 means this cannot possibly be a valid character. |
|
| 151 | - * |
|
| 152 | - * @param string $bytes |
|
| 153 | - * @param int $size |
|
| 154 | - * |
|
| 155 | - * @return int |
|
| 156 | - */ |
|
| 157 | - public function validateByteSequence($bytes, $size) |
|
| 158 | - { |
|
| 159 | - if ($size < 1) { |
|
| 160 | - return -1; |
|
| 161 | - } |
|
| 162 | - $needed = self::$length_map[$bytes[0]] - $size; |
|
| 144 | + /** |
|
| 145 | + * Returns an integer which specifies how many more bytes to read. |
|
| 146 | + * |
|
| 147 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 148 | + * this method again. |
|
| 149 | + * A value of zero means this is already a valid character. |
|
| 150 | + * A value of -1 means this cannot possibly be a valid character. |
|
| 151 | + * |
|
| 152 | + * @param string $bytes |
|
| 153 | + * @param int $size |
|
| 154 | + * |
|
| 155 | + * @return int |
|
| 156 | + */ |
|
| 157 | + public function validateByteSequence($bytes, $size) |
|
| 158 | + { |
|
| 159 | + if ($size < 1) { |
|
| 160 | + return -1; |
|
| 161 | + } |
|
| 162 | + $needed = self::$length_map[$bytes[0]] - $size; |
|
| 163 | 163 | |
| 164 | - return $needed > -1 ? $needed : -1; |
|
| 165 | - } |
|
| 164 | + return $needed > -1 ? $needed : -1; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Returns the number of bytes which should be read to start each character. |
|
| 169 | - * |
|
| 170 | - * @return int |
|
| 171 | - */ |
|
| 172 | - public function getInitialByteSize() |
|
| 173 | - { |
|
| 174 | - return 1; |
|
| 175 | - } |
|
| 167 | + /** |
|
| 168 | + * Returns the number of bytes which should be read to start each character. |
|
| 169 | + * |
|
| 170 | + * @return int |
|
| 171 | + */ |
|
| 172 | + public function getInitialByteSize() |
|
| 173 | + { |
|
| 174 | + return 1; |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -15,70 +15,70 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Returns the complete character map. |
|
| 20 | - * |
|
| 21 | - * @param string $string |
|
| 22 | - * @param int $startOffset |
|
| 23 | - * @param array $currentMap |
|
| 24 | - * @param string $ignoredChars |
|
| 25 | - * |
|
| 26 | - * @return int |
|
| 27 | - */ |
|
| 28 | - public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 29 | - { |
|
| 30 | - $strlen = \strlen($string); |
|
| 31 | - $ignoredChars = ''; |
|
| 32 | - for ($i = 0; $i < $strlen; ++$i) { |
|
| 33 | - if ($string[$i] > "\x07F") { |
|
| 34 | - // Invalid char |
|
| 35 | - $currentMap[$i + $startOffset] = $string[$i]; |
|
| 36 | - } |
|
| 37 | - } |
|
| 18 | + /** |
|
| 19 | + * Returns the complete character map. |
|
| 20 | + * |
|
| 21 | + * @param string $string |
|
| 22 | + * @param int $startOffset |
|
| 23 | + * @param array $currentMap |
|
| 24 | + * @param string $ignoredChars |
|
| 25 | + * |
|
| 26 | + * @return int |
|
| 27 | + */ |
|
| 28 | + public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) |
|
| 29 | + { |
|
| 30 | + $strlen = \strlen($string); |
|
| 31 | + $ignoredChars = ''; |
|
| 32 | + for ($i = 0; $i < $strlen; ++$i) { |
|
| 33 | + if ($string[$i] > "\x07F") { |
|
| 34 | + // Invalid char |
|
| 35 | + $currentMap[$i + $startOffset] = $string[$i]; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $strlen; |
|
| 40 | - } |
|
| 39 | + return $strlen; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Returns mapType. |
|
| 44 | - * |
|
| 45 | - * @return int mapType |
|
| 46 | - */ |
|
| 47 | - public function getMapType() |
|
| 48 | - { |
|
| 49 | - return self::MAP_TYPE_INVALID; |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Returns mapType. |
|
| 44 | + * |
|
| 45 | + * @return int mapType |
|
| 46 | + */ |
|
| 47 | + public function getMapType() |
|
| 48 | + { |
|
| 49 | + return self::MAP_TYPE_INVALID; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Returns an integer which specifies how many more bytes to read. |
|
| 54 | - * |
|
| 55 | - * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 56 | - * this method again. |
|
| 57 | - * A value of zero means this is already a valid character. |
|
| 58 | - * A value of -1 means this cannot possibly be a valid character. |
|
| 59 | - * |
|
| 60 | - * @param string $bytes |
|
| 61 | - * @param int $size |
|
| 62 | - * |
|
| 63 | - * @return int |
|
| 64 | - */ |
|
| 65 | - public function validateByteSequence($bytes, $size) |
|
| 66 | - { |
|
| 67 | - $byte = reset($bytes); |
|
| 68 | - if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { |
|
| 69 | - return 0; |
|
| 70 | - } |
|
| 52 | + /** |
|
| 53 | + * Returns an integer which specifies how many more bytes to read. |
|
| 54 | + * |
|
| 55 | + * A positive integer indicates the number of more bytes to fetch before invoking |
|
| 56 | + * this method again. |
|
| 57 | + * A value of zero means this is already a valid character. |
|
| 58 | + * A value of -1 means this cannot possibly be a valid character. |
|
| 59 | + * |
|
| 60 | + * @param string $bytes |
|
| 61 | + * @param int $size |
|
| 62 | + * |
|
| 63 | + * @return int |
|
| 64 | + */ |
|
| 65 | + public function validateByteSequence($bytes, $size) |
|
| 66 | + { |
|
| 67 | + $byte = reset($bytes); |
|
| 68 | + if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { |
|
| 69 | + return 0; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return -1; |
|
| 73 | - } |
|
| 72 | + return -1; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Returns the number of bytes which should be read to start each character. |
|
| 77 | - * |
|
| 78 | - * @return int |
|
| 79 | - */ |
|
| 80 | - public function getInitialByteSize() |
|
| 81 | - { |
|
| 82 | - return 1; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Returns the number of bytes which should be read to start each character. |
|
| 77 | + * |
|
| 78 | + * @return int |
|
| 79 | + */ |
|
| 80 | + public function getInitialByteSize() |
|
| 81 | + { |
|
| 82 | + return 1; |
|
| 83 | + } |
|
| 84 | 84 | } |