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:
@@ -20,6 +20,7 @@ ob_end_flush();
|
||||
|
||||
use CoreLibs\Template\HtmlBuilder\Element;
|
||||
use CoreLibs\Template\HtmlBuilder\General\Error;
|
||||
use CoreLibs\Template\HtmlBuilder\General\HtmlBuilderExcpetion;
|
||||
use CoreLibs\Debug\Support;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
@@ -83,7 +84,11 @@ echo "<hr>";
|
||||
// self loop
|
||||
|
||||
$el_s = new Element('div', 'id-s', 'Self');
|
||||
$el_s->addSub($el_s, new Element('span', '', 'Span'));
|
||||
try {
|
||||
$el_s->addSub($el_s, new Element('span', '', 'Span'));
|
||||
} catch (HtmlBuilderExcpetion $e) {
|
||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||
}
|
||||
|
||||
// var_dump($el_s);
|
||||
print "el_s, buildHtml(): <pre>" . htmlentities($el_s->buildHtml()) . "</pre>";
|
||||
@@ -95,8 +100,12 @@ $el_s_2->addSub(
|
||||
);
|
||||
|
||||
$el_s_3 = new Element('div', 'id-3', 'ID 3');
|
||||
$el_s_3->addSub($el_s_2);
|
||||
$el_s_2->addSub($el_s_2);
|
||||
try {
|
||||
$el_s_3->addSub($el_s_2);
|
||||
$el_s_2->addSub($el_s_2);
|
||||
} catch (HtmlBuilderExcpetion $e) {
|
||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||
}
|
||||
|
||||
// print "<pre>" . var_export($el_s_3, true) . "</pre>";
|
||||
|
||||
@@ -104,12 +113,22 @@ print "el_s_3, buildHtml(): <pre>" . htmlentities($el_s_3->buildHtml()) . "</pre
|
||||
|
||||
echo "<hr>";
|
||||
Error::resetMessages();
|
||||
$el_er = new Element('');
|
||||
try {
|
||||
$el_er = new Element('');
|
||||
} catch (HtmlBuilderExcpetion $e) {
|
||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
||||
}
|
||||
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
||||
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
||||
print "Error: " . Support::printToString(Error::hasError()) . "<br>";
|
||||
Error::resetMessages();
|
||||
$el_er = new Element('123123');
|
||||
try {
|
||||
$el_er = new Element('123123');
|
||||
} catch (HtmlBuilderExcpetion $e) {
|
||||
print "E: " . $e->getMessage() . " | " . $e->getTraceAsString() . "<br>";
|
||||
print "E: " . $e->getPrevious()->getMessage() . " | " . $e->getPrevious()->getTraceAsString() . "<br>";
|
||||
}
|
||||
print "Errors: <pre>" . print_r(Error::getMessages(), true) . "</pre>";
|
||||
print "Warning: " . Support::printToString(Error::hasWarning()) . "<br>";
|
||||
print "Error: " . Support::printToString(Error::hasError()) . "<br>";
|
||||
|
||||
@@ -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>' ;
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ $test_files = [
|
||||
'class_test.html.php' => 'Class Test: HTML/ELEMENTS',
|
||||
'class_test.html_build.element.php' => 'Class Test: HTML BUILDER: ELEMENT',
|
||||
'class_test.html_build.block.php' => 'Class Test: HTML BUILDER: BLOCK',
|
||||
'class_test.html_build.replace.php' => 'Class Test: HTML BUILDER: REPLACE',
|
||||
'class_test.html_build.replace.php' => 'Class Test: HTML BUILDER: STRING REPLACE',
|
||||
'class_test.email.php' => 'Class Test: EMAIL',
|
||||
'class_test.create_email.php' => 'Class Test: CREATE EMAIL',
|
||||
'class_test.uids.php' => 'Class Test: UIDS',
|
||||
|
||||
Reference in New Issue
Block a user