Add key based genericConfig
This commit is contained in:
parent
18848e041f
commit
56e8caa26c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
vendor/
|
vendor/
|
||||||
|
app/config.php
|
9
app/config.example.php
Normal file
9
app/config.example.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Ardent\Undercurrent\Config\GenericConfig;
|
||||||
|
|
||||||
|
return new GenericConfig([
|
||||||
|
'key' => 'value',
|
||||||
|
]);
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Ardent\Undercurrent;
|
namespace Ardent\Undercurrent\Config;
|
||||||
|
|
||||||
class AppConfig
|
class AppConfig
|
||||||
{
|
{
|
17
src/Config/GenericConfig.php
Normal file
17
src/Config/GenericConfig.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Ardent\Undercurrent\Config;
|
||||||
|
|
||||||
|
class GenericConfig
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly array $config,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get(string $key): mixed
|
||||||
|
{
|
||||||
|
return $this->config[$key];
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Ardent\Undercurrent\Container;
|
namespace Ardent\Undercurrent\Container;
|
||||||
|
|
||||||
use Ardent\Undercurrent\Http\RouteConfig;
|
|
||||||
use Ardent\Undercurrent\Logger\LogContainer;
|
use Ardent\Undercurrent\Logger\LogContainer;
|
||||||
use Ardent\Undercurrent\Logger\LoggerInterface;
|
use Ardent\Undercurrent\Logger\LoggerInterface;
|
||||||
use Exception;
|
use Exception;
|
||||||
@ -41,6 +40,10 @@ class GenericContainer implements ContainerInterface
|
|||||||
|
|
||||||
public function alias(string $alias, string $className): self
|
public function alias(string $alias, string $className): self
|
||||||
{
|
{
|
||||||
|
if (isset($this->aliases[$alias])) {
|
||||||
|
throw new Exception(sprintf('Class %s already defined', $className));
|
||||||
|
}
|
||||||
|
|
||||||
$this->aliases[$alias] = $className;
|
$this->aliases[$alias] = $className;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Ardent\Undercurrent\Http;
|
namespace Ardent\Undercurrent\Http;
|
||||||
|
|
||||||
use Ardent\Undercurrent\AppConfig;
|
use Ardent\Undercurrent\Config\AppConfig;
|
||||||
use Ardent\Undercurrent\Container\ContainerInterface;
|
use Ardent\Undercurrent\Container\ContainerInterface;
|
||||||
use Ardent\Undercurrent\Logger\LoggerInterface;
|
use Ardent\Undercurrent\Logger\LoggerInterface;
|
||||||
use Ardent\Undercurrent\View\ViewHelper;
|
use Ardent\Undercurrent\View\ViewHelper;
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
namespace Ardent\Undercurrent\Kernel;
|
namespace Ardent\Undercurrent\Kernel;
|
||||||
|
|
||||||
use Ardent\Undercurrent\AppConfig;
|
use Ardent\Undercurrent\Config\AppConfig;
|
||||||
|
use Ardent\Undercurrent\Config\GenericConfig;
|
||||||
use Ardent\Undercurrent\Container\ContainerInterface;
|
use Ardent\Undercurrent\Container\ContainerInterface;
|
||||||
use Ardent\Undercurrent\Container\GenericContainer;
|
use Ardent\Undercurrent\Container\GenericContainer;
|
||||||
use Ardent\Undercurrent\Http\GenericRequest;
|
use Ardent\Undercurrent\Http\GenericRequest;
|
||||||
@ -15,7 +16,6 @@ use Ardent\Undercurrent\Http\StatusEnum;
|
|||||||
use Ardent\Undercurrent\Logger\LogContainer;
|
use Ardent\Undercurrent\Logger\LogContainer;
|
||||||
use Ardent\Undercurrent\Logger\LoggerInterface;
|
use Ardent\Undercurrent\Logger\LoggerInterface;
|
||||||
use Ardent\Undercurrent\View\ViewHelper;
|
use Ardent\Undercurrent\View\ViewHelper;
|
||||||
use Ardent\Undercurrent\View\ViewInterface;
|
|
||||||
|
|
||||||
class BaseKernel
|
class BaseKernel
|
||||||
{
|
{
|
||||||
@ -40,7 +40,12 @@ class BaseKernel
|
|||||||
->add(ViewHelper::class)
|
->add(ViewHelper::class)
|
||||||
->add(LogContainer::class);
|
->add(LogContainer::class);
|
||||||
|
|
||||||
|
// App related dependencies
|
||||||
$this->dependencies($container);
|
$this->dependencies($container);
|
||||||
|
$configPath = $this->rootDirectory . '/config.php';
|
||||||
|
if (file_exists($configPath)) {
|
||||||
|
$container->add(GenericConfig::class, fn() => include $configPath);
|
||||||
|
}
|
||||||
|
|
||||||
$this->render($container);
|
$this->render($container);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Ardent\Undercurrent\View;
|
namespace Ardent\Undercurrent\View;
|
||||||
|
|
||||||
use Ardent\Undercurrent\AppConfig;
|
use Ardent\Undercurrent\Config\AppConfig;
|
||||||
|
|
||||||
class BaseView implements ViewInterface
|
class BaseView implements ViewInterface
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace Ardent\Undercurrent\View;
|
namespace Ardent\Undercurrent\View;
|
||||||
|
|
||||||
use Ardent\Undercurrent\AppConfig;
|
use Ardent\Undercurrent\Config\AppConfig;
|
||||||
use Ardent\Undercurrent\Http\ResponseInterface;
|
|
||||||
|
|
||||||
interface ViewInterface
|
interface ViewInterface
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user