diff --git a/.gitignore b/.gitignore index 93f6ca3..a0a5339 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor/ +app/config.php \ No newline at end of file diff --git a/app/Template/routes.php b/app/Template/routes.php index 4031b7b..ea9e2d9 100644 --- a/app/Template/routes.php +++ b/app/Template/routes.php @@ -9,4 +9,4 @@ foreach ($this->routes->getRoutes() as $route) { $route->getMethod() ); } -?> \ No newline at end of file +?> diff --git a/app/config.example.php b/app/config.example.php new file mode 100644 index 0000000..6f28ea1 --- /dev/null +++ b/app/config.example.php @@ -0,0 +1,9 @@ + 'value', +]); \ No newline at end of file diff --git a/src/AppConfig.php b/src/Config/AppConfig.php similarity index 85% rename from src/AppConfig.php rename to src/Config/AppConfig.php index e3ce075..e4e7840 100644 --- a/src/AppConfig.php +++ b/src/Config/AppConfig.php @@ -1,6 +1,6 @@ config[$key]; + } +} \ No newline at end of file diff --git a/src/Container/GenericContainer.php b/src/Container/GenericContainer.php index 96b0b94..aa11fc2 100644 --- a/src/Container/GenericContainer.php +++ b/src/Container/GenericContainer.php @@ -2,7 +2,6 @@ namespace Ardent\Undercurrent\Container; -use Ardent\Undercurrent\Http\RouteConfig; use Ardent\Undercurrent\Logger\LogContainer; use Ardent\Undercurrent\Logger\LoggerInterface; use Exception; @@ -41,6 +40,10 @@ class GenericContainer implements ContainerInterface 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; return $this; diff --git a/src/Http/GenericRouter.php b/src/Http/GenericRouter.php index ffcfa06..74051e2 100644 --- a/src/Http/GenericRouter.php +++ b/src/Http/GenericRouter.php @@ -2,7 +2,7 @@ namespace Ardent\Undercurrent\Http; -use Ardent\Undercurrent\AppConfig; +use Ardent\Undercurrent\Config\AppConfig; use Ardent\Undercurrent\Container\ContainerInterface; use Ardent\Undercurrent\Logger\LoggerInterface; use Ardent\Undercurrent\View\ViewHelper; diff --git a/src/Kernel/BaseKernel.php b/src/Kernel/BaseKernel.php index 1a9b184..9b0ba13 100644 --- a/src/Kernel/BaseKernel.php +++ b/src/Kernel/BaseKernel.php @@ -2,7 +2,8 @@ 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\GenericContainer; use Ardent\Undercurrent\Http\GenericRequest; @@ -15,7 +16,6 @@ use Ardent\Undercurrent\Http\StatusEnum; use Ardent\Undercurrent\Logger\LogContainer; use Ardent\Undercurrent\Logger\LoggerInterface; use Ardent\Undercurrent\View\ViewHelper; -use Ardent\Undercurrent\View\ViewInterface; class BaseKernel { @@ -40,7 +40,12 @@ class BaseKernel ->add(ViewHelper::class) ->add(LogContainer::class); + // App related dependencies $this->dependencies($container); + $configPath = $this->rootDirectory . '/config.php'; + if (file_exists($configPath)) { + $container->add(GenericConfig::class, fn() => include $configPath); + } $this->render($container); } diff --git a/src/View/BaseView.php b/src/View/BaseView.php index 3263226..66b68f3 100644 --- a/src/View/BaseView.php +++ b/src/View/BaseView.php @@ -2,7 +2,7 @@ namespace Ardent\Undercurrent\View; -use Ardent\Undercurrent\AppConfig; +use Ardent\Undercurrent\Config\AppConfig; class BaseView implements ViewInterface { diff --git a/src/View/ViewInterface.php b/src/View/ViewInterface.php index 29f7d29..4940f7d 100644 --- a/src/View/ViewInterface.php +++ b/src/View/ViewInterface.php @@ -2,8 +2,7 @@ namespace Ardent\Undercurrent\View; -use Ardent\Undercurrent\AppConfig; -use Ardent\Undercurrent\Http\ResponseInterface; +use Ardent\Undercurrent\Config\AppConfig; interface ViewInterface {