← All changes
|
vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php
+3
-23
3.2.86
→
3.2.90
View file →
| @@ -14,11 +14,8 @@ | ||
| 14 | 14 | * Generate the output html5 based on element rules. |
| 15 | 15 | */ |
| 16 | 16 | class OutputRules implements RulesInterface |
| 17 | 17 | { |
| 18 | - /** | |
| 19 | - * Defined in http://www.w3.org/TR/html51/infrastructure.html#html-namespace-0. | |
| 20 | - */ | |
| 21 | 18 | const NAMESPACE_HTML = 'http://www.w3.org/1999/xhtml'; |
| 22 | 19 | const NAMESPACE_MATHML = 'http://www.w3.org/1998/Math/MathML'; |
| 23 | 20 | const NAMESPACE_SVG = 'http://www.w3.org/2000/svg'; |
| 24 | 21 | const NAMESPACE_XLINK = 'http://www.w3.org/1999/xlink'; |
| @@ -32,14 +29,8 @@ | ||
| 32 | 29 | protected $implicitNamespaces = array(self::NAMESPACE_HTML, self::NAMESPACE_SVG, self::NAMESPACE_MATHML, self::NAMESPACE_XML, self::NAMESPACE_XMLNS); |
| 33 | 30 | const IM_IN_HTML = 1; |
| 34 | 31 | const IM_IN_SVG = 2; |
| 35 | 32 | const IM_IN_MATHML = 3; |
| 36 | - /** | |
| 37 | - * Used as cache to detect if is available ENT_HTML5. | |
| 38 | - * | |
| 39 | - * @var bool | |
| 40 | - */ | |
| 41 | - private $hasHTML5 = \false; | |
| 42 | 33 | protected $traverser; |
| 43 | 34 | protected $encode = \false; |
| 44 | 35 | protected $out; |
| 45 | 36 | protected $outputMode; |
| @@ -64,9 +55,8 @@ | ||
| 64 | 55 | $this->encode = $options['encode_entities']; |
| 65 | 56 | } |
| 66 | 57 | $this->outputMode = static::IM_IN_HTML; |
| 67 | 58 | $this->out = $output; |
| 68 | - $this->hasHTML5 = defined('ENT_HTML5'); | |
| 69 | 59 | } |
| 70 | 60 | public function addRule(array $rule) |
| 71 | 61 | { |
| 72 | 62 | $this->nonBooleanAttributes[] = $rule; |
| @@ -305,9 +295,9 @@ | ||
| 305 | 295 | * @return $this |
| 306 | 296 | */ |
| 307 | 297 | protected function wr($text) |
| 308 | 298 | { |
| 309 | - fwrite($this->out, $text); | |
| 299 | + fwrite($this->out, (string) $text); | |
| 310 | 300 | return $this; |
| 311 | 301 | } |
| 312 | 302 | /** |
| 313 | 303 | * Write a new line character. |
| @@ -336,14 +326,10 @@ | ||
| 336 | 326 | * @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. |
| 337 | 327 | * This includes such characters as +.# and many other common ones. By default |
| 338 | 328 | * encoding here will just escape &'<>". |
| 339 | 329 | * |
| 340 | - * Note, PHP 5.4+ has better html5 encoding. | |
| 341 | - * | |
| 342 | - * @todo Use the Entities class in php 5.3 to have html5 entities. | |
| 343 | - * | |
| 344 | 330 | * @param string $text Text to encode. |
| 345 | - * @param bool $attribute True if we are encoding an attrubute, false otherwise. | |
| 331 | + * @param bool $attribute True if we are encoding an attribute, false otherwise. | |
| 346 | 332 | * |
| 347 | 333 | * @return string The encoded text. |
| 348 | 334 | */ |
| 349 | 335 | protected function enc($text, $attribute = \false) |
| @@ -351,15 +337,9 @@ | ||
| 351 | 337 | // Escape the text rather than convert to named character references. |
| 352 | 338 | if (!$this->encode) { |
| 353 | 339 | return $this->escape($text, $attribute); |
| 354 | 340 | } |
| 355 | - // If we are in PHP 5.4+ we can use the native html5 entity functionality to | |
| 356 | - // convert the named character references. | |
| 357 | - if ($this->hasHTML5) { | |
| 358 | - return htmlentities($text, \ENT_HTML5 | \ENT_SUBSTITUTE | \ENT_QUOTES, 'UTF-8', \false); | |
| 359 | - } else { | |
| 360 | - return strtr($text, HTML5Entities::$map); | |
| 361 | - } | |
| 341 | + return htmlentities($text, \ENT_HTML5 | \ENT_SUBSTITUTE | \ENT_QUOTES, 'UTF-8', \false); | |
| 362 | 342 | } |
| 363 | 343 | /** |
| 364 | 344 | * Escape test. |
| 365 | 345 | * |