Skip to content

Commit

Permalink
Merge pull request #58 from sroehrl/setup-rendering
Browse files Browse the repository at this point in the history
Setup rendering
  • Loading branch information
sroehrl authored Jan 13, 2023
2 parents 1c863f5 + e208779 commit 1da8889
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 180 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
21 changes: 21 additions & 0 deletions tests/Helper/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Test\Helper;

use Neoan\Database\SqLiteAdapter;
use Neoan\Enums\ResponseOutput;
use Neoan\Helper\Setup;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -79,4 +80,24 @@ public function testSetSkeletonHTML()
$this->setup->setSkeletonHTML('src/views/skeleton.html');
$this->assertSame('src/views/skeleton.html', $this->setup->get('skeletonHTML'));
}

public function testDefaultOutput()
{
$this->setup->setDefaultOutput(ResponseOutput::HTML);
$this->assertSame(ResponseOutput::HTML, $this->setup->get('defaultOutput'));
}

public function testInvoke()
{
$this->setup->setSkeletonComponentPlacement('haupt');
$this->setup->setTemplatePath('src');
$this->setup->setDefaultOutput(ResponseOutput::HTML);
$this->setup->setUseSkeleton(true);
$this->setup->setSkeletonHTML('some.html');
$this->setup->setSkeletonVariables([]);
$setup = $this->setup;
$setup();
$this->assertSame('haupt', $this->setup->get('skeletonComponentPlacement'));
}

}
Binary file modified tests/Mocks/database.db
Binary file not shown.
Loading

0 comments on commit 1da8889

Please sign in to comment.