← All changes
|
vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php
+3
-27
3.23.3
→
3.24.3
View file →
| @@ -15,11 +15,8 @@ | ||
| 15 | 15 | * Generate the output html5 based on element rules. |
| 16 | 16 | */ |
| 17 | 17 | class OutputRules implements RulesInterface |
| 18 | 18 | { |
| 19 | - /** | |
| 20 | - * Defined in http://www.w3.org/TR/html51/infrastructure.html#html-namespace-0. | |
| 21 | - */ | |
| 22 | 19 | const NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml'; |
| 23 | 20 | |
| 24 | 21 | const NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML'; |
| 25 | 22 | |
| @@ -49,15 +46,8 @@ | ||
| 49 | 46 | const IM_IN_SVG = 2; |
| 50 | 47 | |
| 51 | 48 | const IM_IN_MATHML = 3; |
| 52 | 49 | |
| 53 | - /** | |
| 54 | - * Used as cache to detect if is available ENT_HTML5. | |
| 55 | - * | |
| 56 | - * @var bool | |
| 57 | - */ | |
| 58 | - private $hasHTML5 = false; | |
| 59 | - | |
| 60 | 50 | protected $traverser; |
| 61 | 51 | |
| 62 | 52 | protected $encode = false; |
| 63 | 53 | |
| @@ -166,9 +156,8 @@ | ||
| 166 | 156 | } |
| 167 | 157 | |
| 168 | 158 | $this->outputMode = static::IM_IN_HTML; |
| 169 | 159 | $this->out = $output; |
| 170 | - $this->hasHTML5 = defined('ENT_HTML5'); | |
| 171 | 160 | } |
| 172 | 161 | |
| 173 | 162 | public function addRule(array $rule) |
| 174 | 163 | { |
| @@ -453,9 +442,9 @@ | ||
| 453 | 442 | * @return $this |
| 454 | 443 | */ |
| 455 | 444 | protected function wr($text) |
| 456 | 445 | { |
| 457 | - fwrite($this->out, $text); | |
| 446 | + fwrite($this->out, (string) $text); | |
| 458 | 447 | |
| 459 | 448 | return $this; |
| 460 | 449 | } |
| 461 | 450 | |
| @@ -488,14 +477,10 @@ | ||
| 488 | 477 | * @see http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#named-character-references True encoding will turn all named character references into their entities. |
| 489 | 478 | * This includes such characters as +.# and many other common ones. By default |
| 490 | 479 | * encoding here will just escape &'<>". |
| 491 | 480 | * |
| 492 | - * Note, PHP 5.4+ has better html5 encoding. | |
| 493 | - * | |
| 494 | - * @todo Use the Entities class in php 5.3 to have html5 entities. | |
| 495 | - * | |
| 496 | 481 | * @param string $text Text to encode. |
| 497 | - * @param bool $attribute True if we are encoding an attrubute, false otherwise. | |
| 482 | + * @param bool $attribute True if we are encoding an attribute, false otherwise. | |
| 498 | 483 | * |
| 499 | 484 | * @return string The encoded text. |
| 500 | 485 | */ |
| 501 | 486 | protected function enc($text, $attribute = false) |
| @@ -504,18 +489,9 @@ | ||
| 504 | 489 | if (!$this->encode) { |
| 505 | 490 | return $this->escape($text, $attribute); |
| 506 | 491 | } |
| 507 | 492 | |
| 508 | - // If we are in PHP 5.4+ we can use the native html5 entity functionality to | |
| 509 | - // convert the named character references. | |
| 510 | - | |
| 511 | - if ($this->hasHTML5) { | |
| 512 | - return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false); | |
| 513 | - } // If a version earlier than 5.4 html5 entities are not entirely handled. | |
| 514 | - // This manually handles them. | |
| 515 | - else { | |
| 516 | - return strtr($text, HTML5Entities::$map); | |
| 517 | - } | |
| 493 | + return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false); | |
| 518 | 494 | } |
| 519 | 495 | |
| 520 | 496 | /** |
| 521 | 497 | * Escape test. |