Skip to content

Commit

Permalink
Setup execution
Browse files Browse the repository at this point in the history
  • Loading branch information
sroehrl committed Jan 13, 2023
1 parent 1c863f5 commit 51fb51f
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 153 deletions.
29 changes: 29 additions & 0 deletions src/Helper/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
use Exception;
use Neoan\Database\Adapter;
use Neoan\Database\Database;
use Neoan\Enums\ResponseOutput;
use Neoan\Errors\NotFound;
use Neoan\Errors\SystemError;
use Neoan\Render\Renderer;
use Neoan\Response\Response;

class Setup
{
Expand Down Expand Up @@ -91,6 +94,12 @@ public function setSkeletonVariables(array $skeletonVariables): self
return $this;
}

public function setDefaultOutput(ResponseOutput $output): static
{
$this->configuration['defaultOutput'] = $output;
return $this;
}

public function setDatabaseAdapter(Adapter $adapter): self
{
Database::connect($adapter);
Expand Down Expand Up @@ -133,4 +142,24 @@ public function get(string $key): mixed
return $this->configuration[$key];
}

public function __invoke(): static
{
// templating
if(isset($this->configuration['templatePath'])) {
Renderer::setTemplatePath($this->configuration['templatePath']);
}
if(isset($this->configuration['defaultOutput'])) {
Response::setDefaultOutput($this->configuration['defaultOutput']);
}
if(isset($this->configuration['useSkeleton']) && $this->configuration['useSkeleton']) {
Renderer::setHtmlSkeleton(
$this->configuration['skeletonHTML'],
$this->configuration['skeletonComponentPlacement'],
$this->configuration['skeletonVariables']
);
}
return $this;

}

}
3 changes: 3 additions & 0 deletions src/NeoanApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class NeoanApp
public string $cliPath;
public Provide $injectionProvider;
private static NeoanApp $instance;
private Setup $setup;

/**
* @throws Exception
Expand All @@ -32,6 +33,7 @@ public function __construct(Setup $setup, string $cliPath = null)
try{
$this->appPath = $setup->get('libraryPath');
$this->publicPath = $setup->get('publicPath');
$this->setup = $setup;
} catch (Exception $e) {
new SystemError($e->getMessage());
}
Expand Down Expand Up @@ -61,6 +63,7 @@ public function setProvider(Provide $provider): void
*/
public function run(): void
{
$this->invoke($this->setup);
$this->invoke(new Request());
$this->invoke(new Route());
}
Expand Down
Binary file modified tests/Mocks/database.db
Binary file not shown.
Loading

0 comments on commit 51fb51f

Please sign in to comment.