-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathElementBinder.php
42 lines (36 loc) · 1.17 KB
/
ElementBinder.php
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
34
35
36
37
38
39
40
41
42
<?php
namespace Gt\DomTemplate;
use Gt\Dom\Element;
class ElementBinder {
private HTMLAttributeBinder $htmlAttributeBinder;
private HTMLAttributeCollection $htmlAttributeCollection;
private PlaceholderBinder $placeholderBinder;
public function setDependencies(
HTMLAttributeBinder $htmlAttributeBinder,
HTMLAttributeCollection $htmlAttributeCollection,
PlaceholderBinder $placeholderBinder,
):void {
$this->htmlAttributeBinder = $htmlAttributeBinder;
$this->htmlAttributeCollection = $htmlAttributeCollection;
$this->placeholderBinder = $placeholderBinder;
}
/**
* Binds an Element and its children according to any HTML "data-bind"
* attributes found, and any {{placeholder}} text.
*/
public function bind(
?string $key,
mixed $value,
Element $context
):void {
if(!is_null($value) && !is_scalar($value) && !is_iterable($value)) {
$value = new BindValue($value);
}
/** @var Element $element */
foreach($this->htmlAttributeCollection->find($context) as $element) {
$this->htmlAttributeBinder->expandAttributes($element);
$this->htmlAttributeBinder->bind($key, $value, $element);
}
$this->placeholderBinder->bind($key, $value, $context);
}
}