init config model

This commit is contained in:
yggverse 2024-06-27 16:50:32 +03:00
parent cba3676d73
commit 789db97319
6 changed files with 247 additions and 230 deletions

45
src/Model/Config.php Normal file
View file

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace Yggverse\Yoda\Model;
class Config
{
public function __construct(
?string $filename = null
) {
if (empty($filename))
{
$filename = __DIR__ .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'config.json';
}
if (!file_exists($filename))
{
throw new \Exception; // @TODO
}
if (!is_readable($filename))
{
throw new \Exception; // @TODO
}
if (!$data = file_get_contents($filename))
{
throw new \Exception; // @TODO
}
if (!$config = @json_decode($data))
{
throw new \Exception; // @TODO
}
foreach ($config as $key => $value)
{
$this->{$key} = $value; // @TODO
}
}
}

View file

@ -6,30 +6,6 @@ namespace Yggverse\Yoda\Model;
class File
{
public static function getConfig(): object
{
$filename = __DIR__ .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . 'config.json';
if (file_exists($filename) && is_readable($filename))
{
$result = json_decode(
file_get_contents(
$filename
)
);
}
if (empty($result))
{
throw new \Exception(); // @TODO
}
return $result;
}
public static function getTheme(string $name): string
{
$filename = __DIR__ .