-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAssertableElementPromoter.php
More file actions
33 lines (26 loc) · 923 Bytes
/
AssertableElementPromoter.php
File metadata and controls
33 lines (26 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);
namespace Ziadoz\AssertableHtml\Dom;
use Dom\Element;
use Dom\HTMLElement;
use Ziadoz\AssertableHtml\Contracts\PromotableAssertableElement;
use Ziadoz\AssertableHtml\Dom\Elements\AssertableForm;
final readonly class AssertableElementPromoter
{
private const array CUSTOM_ELEMENTS = [
AssertableForm::class,
];
/** Create a core assertable element. */
public function __construct(private HTMLElement|Element $element)
{
}
/** Promote and return the first matching assertable element that matches the given HTML element. */
public function promote(): (PromotableAssertableElement&AssertableElement)|null
{
$match = array_find(
self::CUSTOM_ELEMENTS,
fn (string $customElement): bool => $customElement::shouldPromote($this->element),
);
return $match ? new $match($this->element) : null;
}
}