HtmlBuilder: change all return error to Throw, update Element/StrinReplace

We do not return old style bool on error, we throw Exceptions: HtmlBuilderExcpetion

Element has more classes to set tag, id, etc with basic checks for valid data

String Replace to set strings is one array with key -> value entries

Errors thrown on index for element/replace blocks
This commit is contained in:
Clemens Schwaighofer
2023-06-28 14:16:44 +09:00
parent 3c37899a48
commit 1754ecf2ee
12 changed files with 316 additions and 118 deletions

View File

@@ -44,11 +44,9 @@ HTML;
print "<pre>" . htmlentities(StringReplace::replaceData(
$html_block,
[
'ID', 'CSS', '{CONTENT}'
],
[
'block-id', join(',', ['blue', 'red']),
'Some content here<br>with bla bla inside'
'ID' => 'block-id',
'CSS' => join(',', ['blue', 'red']),
'{CONTENT}' => 'Some content here<br>with bla bla inside'
]
)) . "</pre>";
@@ -63,14 +61,18 @@ print "Get: <pre>" . htmlentities(StringReplace::getElement('bar') ?: '') . '</p
print "Build element: <pre>" . htmlentities(StringReplace::buildElement(
'bar',
['ID}', '{CONTENT'],
['new-id', 'Test cow 日本語']
[
'ID}' => 'new-id',
'{CONTENT' => 'Test cow 日本語'
]
)) . '</pre>' ;
print "Build element as replace: <pre>" . htmlentities(StringReplace::buildElement(
'bar',
['ID}', '{CONTENT'],
['diff-id', 'Test cow 日本語. More text plus'],
['
ID}' => 'diff-id',
'{CONTENT' => 'Test cow 日本語. More text plus'
],
'rpl-1'
)) . '</pre>' ;