for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Kevintweber\HtmlTokenizer\Tokens;
use Kevintweber\HtmlTokenizer\Exceptions\TokenMatchingException;
class TokenFactory
{
public static function buildFromHtml($html, Token $parent = null, $throwOnError = false)
$matchCriteria = array(
'Text' => "/^[^<]/",
'Element' => "/^<[a-z]/i",
'Comment' => "/^<!--/",
'CData' => "/^<!\[CDATA\[/",
'DocType' => "/^<!DOCTYPE /i"
);
foreach ($matchCriteria as $className => $regex) {
if (preg_match($regex, $html) === 1) {
$fullClassName = "Kevintweber\\HtmlTokenizer\\Tokens\\" . $className;
return new $fullClassName($parent, $throwOnError);
}
// Error condition
if ($throwOnError) {
throw new TokenMatchingException();
return false;