From c80b25f870be0d8673c1045f13fdd256bc3ce33c Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Fri, 3 Nov 2023 11:58:35 +0000 Subject: [PATCH] wip: component binder - tweak order of execution --- src/Middleware/RequestHandler.php | 82 ++++++++++++++++++------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/src/Middleware/RequestHandler.php b/src/Middleware/RequestHandler.php index 5f420916..08df5163 100644 --- a/src/Middleware/RequestHandler.php +++ b/src/Middleware/RequestHandler.php @@ -138,7 +138,7 @@ protected function completeRequestHandling( $this->handleLogicExecution($this->logicAssembly); // TODO: Why is this in the handle function? - $documentBinder = $this->serviceContainer->get(DocumentBinder::class); + $documentBinder = $this->serviceContainer->get(Binder::class); $documentBinder->cleanupDocument(); $this->view->stream($this->viewModel); @@ -184,37 +184,8 @@ protected function handleRouting(ServerRequestInterface $request) { } protected function handleHTMLDocumentViewModel():void { - $this->serviceContainer->get(HTMLAttributeBinder::class)->setDependencies( - $this->serviceContainer->get(ListBinder::class), - $this->serviceContainer->get(TableBinder::class), - ); - $this->serviceContainer->get(ElementBinder::class)->setDependencies( - $this->serviceContainer->get(HTMLAttributeBinder::class), - $this->serviceContainer->get(HTMLAttributeCollection::class), - $this->serviceContainer->get(PlaceholderBinder::class), - ); - $this->serviceContainer->get(TableBinder::class)->setDependencies( - $this->serviceContainer->get(ListBinder::class), - $this->serviceContainer->get(ListElementCollection::class), - $this->serviceContainer->get(ElementBinder::class), - $this->serviceContainer->get(HTMLAttributeBinder::class), - $this->serviceContainer->get(HTMLAttributeCollection::class), - $this->serviceContainer->get(PlaceholderBinder::class), - ); - $this->serviceContainer->get(ListBinder::class)->setDependencies( - $this->serviceContainer->get(ElementBinder::class), - $this->serviceContainer->get(ListElementCollection::class), - $this->serviceContainer->get(BindableCache::class), - $this->serviceContainer->get(TableBinder::class), - ); - $this->serviceContainer->get(Binder::class)->setDependencies( - $this->serviceContainer->get(ElementBinder::class), - $this->serviceContainer->get(PlaceholderBinder::class), - $this->serviceContainer->get(TableBinder::class), - $this->serviceContainer->get(ListBinder::class), - $this->serviceContainer->get(ListElementCollection::class), - $this->serviceContainer->get(BindableCache::class), - ); + $expandedLogicAssemblyList = []; + $expandedComponentList = []; try { $partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [ @@ -235,7 +206,8 @@ protected function handleHTMLDocumentViewModel():void { if(is_file($filePath)) { $componentAssembly = new Assembly(); $componentAssembly->add($filePath); - $this->handleLogicExecution($componentAssembly, $componentElement); + array_push($expandedLogicAssemblyList, $componentAssembly); + array_push($expandedComponentList, $componentElement); } } } @@ -267,6 +239,49 @@ protected function handleHTMLDocumentViewModel():void { $bodyDirClass .= "--$pathPart"; $this->viewModel->body->classList->add($bodyDirClass); } + + $this->serviceContainer->get(HTMLAttributeBinder::class)->setDependencies( + $this->serviceContainer->get(ListBinder::class), + $this->serviceContainer->get(TableBinder::class), + ); + $this->serviceContainer->get(ElementBinder::class)->setDependencies( + $this->serviceContainer->get(HTMLAttributeBinder::class), + $this->serviceContainer->get(HTMLAttributeCollection::class), + $this->serviceContainer->get(PlaceholderBinder::class), + ); + $this->serviceContainer->get(TableBinder::class)->setDependencies( + $this->serviceContainer->get(ListBinder::class), + $this->serviceContainer->get(ListElementCollection::class), + $this->serviceContainer->get(ElementBinder::class), + $this->serviceContainer->get(HTMLAttributeBinder::class), + $this->serviceContainer->get(HTMLAttributeCollection::class), + $this->serviceContainer->get(PlaceholderBinder::class), + ); + $this->serviceContainer->get(ListBinder::class)->setDependencies( + $this->serviceContainer->get(ElementBinder::class), + $this->serviceContainer->get(ListElementCollection::class), + $this->serviceContainer->get(BindableCache::class), + $this->serviceContainer->get(TableBinder::class), + ); + $this->serviceContainer->get(Binder::class)->setDependencies( + $this->serviceContainer->get(ElementBinder::class), + $this->serviceContainer->get(PlaceholderBinder::class), + $this->serviceContainer->get(TableBinder::class), + $this->serviceContainer->get(ListBinder::class), + $this->serviceContainer->get(ListElementCollection::class), + $this->serviceContainer->get(BindableCache::class), + ); + +// $listElementCollection = $this->serviceContainer->get(ListElementCollection::class); +// var_dump($listElementCollection);die(); + + foreach($expandedLogicAssemblyList as $i => $assembly) { + $componentElement = $expandedComponentList[$i]; + if(!$componentElement) { + var_dump($assembly);die(); + } + $this->handleLogicExecution($assembly, $componentElement); + } } protected function handleSession():void { @@ -368,6 +383,7 @@ protected function handleLogicExecution(Assembly $logicAssembly, ?Element $compo ); $binder->setComponentBinderDependencies($component); $extraArgs[Binder::class] = $binder; + $extraArgs[Element::class] = $component; } foreach($logicExecutor->invoke("go_before", $extraArgs) as $file) {