77use Traversable ;
88
99class TableBinder {
10- /**
11- * @noinspection PhpPropertyOnlyWrittenInspection
12- * @phpstan-ignore-next-line
13- */
1410 private ListBinder $ listBinder ;
1511 private ListElementCollection $ templateCollection ;
1612 private ElementBinder $ elementBinder ;
@@ -45,12 +41,12 @@ public function bindTableData(
4541 ?string $ bindKey = null
4642 ):void {
4743 $ tableData = $ this ->normaliseTableData ($ tableData );
44+ $ this ->initBinders ($ context );
4845
4946 if ($ context instanceof Document) {
5047 $ context = $ context ->documentElement ;
5148 }
5249
53- $ this ->initBinders ();
5450 $ tableArray = $ this ->findMatchingTables ($ context , $ bindKey );
5551 if (empty ($ tableArray )) {
5652 throw new TableElementNotFoundInContextException ();
@@ -493,7 +489,11 @@ private function normalizeDoubleHeader(array $bindValue):array {
493489 ];
494490 }
495491
496- private function initBinders ():void {
492+ private function initBinders (Document |Element $ context ):void {
493+ $ document = $ context instanceof Document
494+ ? $ context
495+ : $ context ->ownerDocument ;
496+
497497 if (!isset ($ this ->htmlAttributeBinder )) {
498498 $ this ->htmlAttributeBinder = new HTMLAttributeBinder ();
499499 }
@@ -506,5 +506,24 @@ private function initBinders():void {
506506 if (!isset ($ this ->elementBinder )) {
507507 $ this ->elementBinder = new ElementBinder ();
508508 }
509+ if (!isset ($ this ->templateCollection )) {
510+ $ this ->templateCollection = new ListElementCollection ($ document );
511+ }
512+ if (!isset ($ this ->listBinder )) {
513+ $ this ->listBinder = new ListBinder ();
514+ }
515+
516+ $ this ->htmlAttributeBinder ->setDependencies ($ this ->listBinder , $ this );
517+ $ this ->elementBinder ->setDependencies (
518+ $ this ->htmlAttributeBinder ,
519+ $ this ->htmlAttributeCollection ,
520+ $ this ->placeholderBinder ,
521+ );
522+ $ this ->listBinder ->setDependencies (
523+ $ this ->elementBinder ,
524+ $ this ->templateCollection ,
525+ new BindableCache (),
526+ $ this ,
527+ );
509528 }
510529}
0 commit comments