Skip to content

Commit

Permalink
wip: component binder
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Nov 1, 2023
1 parent ac82ac7 commit 818df87
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Logic/LogicExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
}

/** @return Generator<string> filename::function() */
public function invoke(string $name, mixed...$extraArgs):Generator {
public function invoke(string $name, array $extraArgs = []):Generator {
foreach($this->assembly as $file) {
$nsProject = (string)(new LogicProjectNamespace(
$file,
Expand Down
47 changes: 5 additions & 42 deletions src/Middleware/DefaultServiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DefaultServiceLoader {
public function __construct(
protected Config $config,
protected Container $container
) {}
) { }

public function loadResponseHeaders():ResponseHeaders {
$response = $this->container->get(Response::class);
Expand Down Expand Up @@ -66,26 +66,11 @@ public function loadPlaceholderBinder():PlaceholderBinder {
}

public function loadElementBinder():ElementBinder {
$elementBinder = new ElementBinder();
$elementBinder->setDependencies(
$this->container->get(HTMLAttributeBinder::class),
$this->container->get(HTMLAttributeCollection::class),
$this->container->get(PlaceholderBinder::class),
);
return $elementBinder;
return new ElementBinder();
}

public function loadTableBinder():TableBinder {
$tableBinder = new TableBinder();
$tableBinder->setDependencies(
$this->container->get(ListBinder::class),
$this->container->get(ListElementCollection::class),
$this->container->get(ElementBinder::class),
$this->container->get(HTMLAttributeBinder::class),
$this->container->get(HTMLAttributeCollection::class),
$this->container->get(PlaceholderBinder::class),
);
return $tableBinder;
return new TableBinder();
}

public function loadListElementCollection():ListElementCollection {
Expand All @@ -95,34 +80,12 @@ public function loadListElementCollection():ListElementCollection {
}

public function loadListBinder():ListBinder {
$listBinder = new ListBinder();
$listBinder->setDependencies(
$this->container->get(ElementBinder::class),
$this->container->get(ListElementCollection::class),
$this->container->get(BindableCache::class),
$this->container->get(TableBinder::class),
);
return $listBinder;
return new ListBinder();
}

public function loadBinder():Binder {
$document = $this->container->get(Document::class);
$binder = new DocumentBinder($document);
$binder->setDependencies(
$this->container->get(ElementBinder::class),
$this->container->get(PlaceholderBinder::class),
$this->container->get(TableBinder::class),
$this->container->get(ListBinder::class),
$this->container->get(ListElementCollection::class),
$this->container->get(BindableCache::class),
);
return $binder;
}

public function loadDocumentBinder():DocumentBinder {
/** @var DocumentBinder $documentBinder */
$documentBinder = $this->loadBinder();
return $documentBinder;
return new DocumentBinder($document);
}

public function loadRequestUri():Uri {
Expand Down
51 changes: 43 additions & 8 deletions src/Middleware/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Gt\DomTemplate\ComponentExpander;
use Gt\DomTemplate\DocumentBinder;
use Gt\DomTemplate\ElementBinder;
use Gt\DomTemplate\HTMLAttributeBinder;
use Gt\DomTemplate\HTMLAttributeCollection;
use Gt\DomTemplate\ListBinder;
use Gt\DomTemplate\ListElementCollection;
use Gt\DomTemplate\PartialContent;
Expand Down Expand Up @@ -126,12 +128,13 @@ protected function completeRequestHandling(
$this->handleSession();
}

$this->handleProtectedGlobals();

if($this->viewModel instanceof HTMLDocument) {
$this->handleHTMLDocumentViewModel();
// $this->handleCsrf($request);
}

$this->handleProtectedGlobals();
$this->handleLogicExecution($this->logicAssembly);

// TODO: Why is this in the handle function?
Expand Down Expand Up @@ -181,6 +184,38 @@ 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),
);

try {
$partial = new PartialContent(implode(DIRECTORY_SEPARATOR, [
getcwd(),
Expand All @@ -198,9 +233,9 @@ protected function handleHTMLDocumentViewModel():void {
$filePath .= ".php";

if(is_file($filePath)) {
$assembly = new Assembly();
$assembly->add($filePath);
$this->handleLogicExecution($assembly, $componentElement);
$componentAssembly = new Assembly();
$componentAssembly->add($filePath);
$this->handleLogicExecution($componentAssembly, $componentElement);
}
}
}
Expand Down Expand Up @@ -313,15 +348,15 @@ protected function handleProtectedGlobals():void {
));
}

protected function handleLogicExecution(Assembly $logicAssembly, ?Element $componentElement = null):void {
protected function handleLogicExecution(Assembly $logicAssembly, ?Element $component = null):void {
$logicExecutor = new LogicExecutor(
$logicAssembly,
$this->injector,
$this->config->getString("app.namespace")
);
$extraArgs = [];

if($componentElement) {
if($component) {
$binder = new ComponentBinder($this->viewModel);
$binder->setDependencies(
$this->serviceContainer->get(ElementBinder::class),
Expand All @@ -331,7 +366,7 @@ protected function handleLogicExecution(Assembly $logicAssembly, ?Element $compo
$this->serviceContainer->get(ListElementCollection::class),
$this->serviceContainer->get(BindableCache::class),
);
$binder->setComponentBinderDependencies($componentElement);
$binder->setComponentBinderDependencies($component);
$extraArgs[Binder::class] = $binder;
}

Expand All @@ -345,7 +380,7 @@ function(InputData $data)use($logicExecutor, $extraArgs) {
$doName = "do_" . str_replace(
"-",
"_",
$data->getString("do")
$data->getString("do"),
);

foreach($logicExecutor->invoke($doName, $extraArgs) as $file) {
Expand Down

0 comments on commit 818df87

Please sign in to comment.