Skip to content

Commit 412039b

Browse files
committed
renamed Nette\Utils\IHtmlString -> Nette\HtmlStringable, added class alias
1 parent cf737a2 commit 412039b

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

src/Utils/Html.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Nette\Utils;
1111

1212
use Nette;
13+
use Nette\HtmlStringable;
1314
use function is_array, is_float, is_object, is_string;
1415

1516

@@ -230,7 +231,7 @@
230231
* @method self width(?int $val)
231232
* @method self wrap(?string $val)
232233
*/
233-
class Html implements \ArrayAccess, \Countable, \IteratorAggregate, IHtmlString
234+
class Html implements \ArrayAccess, \Countable, \IteratorAggregate, HtmlStringable
234235
{
235236
use Nette\SmartObject;
236237

@@ -548,7 +549,7 @@ public function data(string $name, $value = null)
548549

549550
/**
550551
* Sets element's HTML content.
551-
* @param IHtmlString|string $html
552+
* @param HtmlStringable|string $html
552553
* @return static
553554
*/
554555
final public function setHtml($html)
@@ -569,12 +570,12 @@ final public function getHtml(): string
569570

570571
/**
571572
* Sets element's textual content.
572-
* @param IHtmlString|string|int|float $text
573+
* @param HtmlStringable|string|int|float $text
573574
* @return static
574575
*/
575576
final public function setText($text)
576577
{
577-
if (!$text instanceof IHtmlString) {
578+
if (!$text instanceof HtmlStringable) {
578579
$text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8');
579580
}
580581
$this->children = [(string) $text];
@@ -593,7 +594,7 @@ final public function getText(): string
593594

594595
/**
595596
* Adds new element's child.
596-
* @param IHtmlString|string $child Html node or raw HTML string
597+
* @param HtmlStringable|string $child Html node or raw HTML string
597598
* @return static
598599
*/
599600
final public function addHtml($child)
@@ -604,12 +605,12 @@ final public function addHtml($child)
604605

605606
/**
606607
* Appends plain-text string to element content.
607-
* @param IHtmlString|string|int|float $text
608+
* @param HtmlStringable|string|int|float $text
608609
* @return static
609610
*/
610611
public function addText($text)
611612
{
612-
if (!$text instanceof IHtmlString) {
613+
if (!$text instanceof HtmlStringable) {
613614
$text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8');
614615
}
615616
return $this->insert(null, $text);
@@ -630,7 +631,7 @@ final public function create(string $name, $attrs = null)
630631

631632
/**
632633
* Inserts child node.
633-
* @param IHtmlString|string $child Html node or raw HTML string
634+
* @param HtmlStringable|string $child Html node or raw HTML string
634635
* @return static
635636
*/
636637
public function insert(?int $index, $child, bool $replace = false)

src/Utils/IHtmlString.php renamed to src/Utils/HtmlStringable.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
declare(strict_types=1);
99

10-
namespace Nette\Utils;
10+
namespace Nette;
1111

1212

13-
interface IHtmlString
13+
interface HtmlStringable
1414
{
1515
/**
1616
* Returns string in HTML format
1717
*/
1818
function __toString(): string;
1919
}
20+
21+
22+
interface_exists(Utils\IHtmlString::class);

src/compatibility.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nette Framework (https://nette.org)
5+
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Nette\Utils {
11+
if (false) {
12+
/** @deprecated use Nette\HtmlStringable */
13+
interface IHtmlString
14+
{
15+
}
16+
} elseif (!interface_exists(IHtmlString::class)) {
17+
class_alias(\Nette\HtmlStringable::class, IHtmlString::class);
18+
}
19+
}

tests/Utils/Html.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test('attributes escaping', function () {
113113
});
114114

115115

116-
class BR implements Nette\Utils\IHtmlString
116+
class BR implements Nette\HtmlStringable
117117
{
118118
public function __toString(): string
119119
{

0 commit comments

Comments
 (0)