Files
accessibility-console/src/Core/Scanner.php
T

37 lines
835 B
PHP
Raw Normal View History

2026-05-13 09:10:43 +03:00
<?php
namespace YakNet\AccessibilityConsole\Core;
class Scanner
{
2026-05-13 12:13:32 +03:00
public function __construct(private ?RuleEngine $engine = null)
{
if ($this->engine === null) {
$this->engine = new RuleEngine();
2026-05-13 09:10:43 +03:00
}
}
2026-05-13 12:46:26 +03:00
public function addRule(mixed $rule): void
{
$this->engine->addRule($rule);
}
2026-05-13 09:10:43 +03:00
/**
2026-05-13 12:13:32 +03:00
* Scan HTML content for accessibility violations.
*
* @param string $html
2026-05-13 09:10:43 +03:00
* @return Violation[]
*/
public function scan(string $html): array
{
2026-05-13 12:13:32 +03:00
if (empty(trim($html))) {
2026-05-13 09:10:43 +03:00
return [];
}
2026-05-13 12:13:32 +03:00
$doc = new \DOMDocument();
// Suppress warnings for malformed HTML
@$doc->loadHTML('<?xml encoding="utf-8" ?>' . $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
2026-05-13 09:10:43 +03:00
2026-05-13 12:13:32 +03:00
return $this->engine->run($doc);
2026-05-13 09:10:43 +03:00
}
}