diff --git a/.gitignore b/.gitignore index 58075ac..4bbb441 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ [Dd]esktop.ini .DS_Store /.debug +/config/config.cfg /config/config.ini /public/robots.txt /vendor diff --git a/awaki.php b/awaki.php index 4484289..10dd7e7 100644 --- a/awaki.php +++ b/awaki.php @@ -4,6 +4,7 @@ namespace Awaki; use Index\Environment; use Index\Data\ConnectionFailedException; use Index\Data\DbTools; +use Syokuhou\SharpConfig; define('AWK_STARTUP', microtime(true)); define('AWK_ROOT', __DIR__); @@ -17,15 +18,13 @@ require_once AWK_ROOT . '/vendor/autoload.php'; Environment::setDebug(AWK_DEBUG); -$config = parse_ini_file(AWK_DIR_CFG . '/config.ini', true); -if($config === false) - die('Config sux.'); +$config = SharpConfig::fromFile(AWK_DIR_CFG . '/config.cfg'); try { - $db = DbTools::create($config['dsn']); + $db = DbTools::create($config->getString('dsn')); } catch(ConnectionFailedException $ex) { echo '

Unable to connect to database

'; die($ex->getMessage()); } -$awk = new AwakiContext($db, $config['urls']); +$awk = new AwakiContext($db, $config->scopeTo('urls')); diff --git a/src/AwakiContext.php b/src/AwakiContext.php index 9f3dce2..fedf3ee 100644 --- a/src/AwakiContext.php +++ b/src/AwakiContext.php @@ -8,6 +8,7 @@ use Index\Data\Migration\FsDbMigrationRepo; use Index\Http\HttpFx; use Index\Http\HttpRequest; use Index\Routing\IRouter; +use Syokuhou\IConfig; // theme colours: #99403d, #592824, #d18c83 // totally didn't just eyedrop musujime @@ -17,9 +18,9 @@ class AwakiContext { private IDbConnection $dbConn; private HttpFx $router; - private array $urls; + private IConfig $urls; - public function __construct(IDbConnection $dbConn, array $urls) { + public function __construct(IDbConnection $dbConn, IConfig $urls) { $this->dbConn = $dbConn; $this->urls = $urls; $dbConn->execute(self::DB_INIT); diff --git a/src/RedirectorRoutes.php b/src/RedirectorRoutes.php index ded8926..a325173 100644 --- a/src/RedirectorRoutes.php +++ b/src/RedirectorRoutes.php @@ -2,14 +2,14 @@ namespace Awaki; use Index\Data\IDbConnection; -use Index\Data\DbType; use Index\Routing\IRouter; +use Syokuhou\IConfig; final class RedirectorRoutes { private IDbConnection $dbConn; - private array $urls; + private IConfig $urls; - public function __construct(IRouter $router, IDbConnection $dbConn, array $urls) { + public function __construct(IRouter $router, IDbConnection $dbConn, IConfig $urls) { $this->dbConn = $dbConn; $this->urls = $urls; @@ -48,8 +48,8 @@ final class RedirectorRoutes { public function redirectDatabase($response, $request, $id) { $getInfo = $this->dbConn->prepare('SELECT redir_id, redir_url FROM awk_redirects WHERE redir_id = ? OR redir_vanity = ?'); - $getInfo->addParameter(1, $id, DbType::INTEGER); - $getInfo->addParameter(2, $id, DbType::STRING); + $getInfo->addParameter(1, $id); + $getInfo->addParameter(2, $id); $getInfo->execute(); $info = $getInfo->getResult(); @@ -57,7 +57,7 @@ final class RedirectorRoutes { return 404; $incClicks = $this->dbConn->prepare('UPDATE awk_redirects SET redir_clicks = redir_clicks + 1 WHERE redir_id = ?'); - $incClicks->addParameter(1, $info->getInteger(0), DbType::INTEGER); + $incClicks->addParameter(1, $info->getInteger(0)); $incClicks->execute(); $this->redirect($response, $request, $info->getString(1)); @@ -72,18 +72,18 @@ final class RedirectorRoutes { } public function redirectProfile($response, $request, string $userId) { - $this->redirectSimple($response, $request, $this->urls['user_profile'], $userId); + $this->redirectSimple($response, $request, $this->urls->getString('user_profile'), $userId); } public function redirectForumCategory($response, $request, string $categoryId) { - $this->redirectSimple($response, $request, $this->urls['forum_category'], $categoryId); + $this->redirectSimple($response, $request, $this->urls->getString('forum_category'), $categoryId); } public function redirectForumTopic($response, $request, string $topicId) { - $this->redirectSimple($response, $request, $this->urls['forum_topic'], $topicId); + $this->redirectSimple($response, $request, $this->urls->getString('forum_topic'), $topicId); } public function redirectForumPost($response, $request, string $postId) { - $this->redirectSimple($response, $request, $this->urls['forum_post'], $postId); + $this->redirectSimple($response, $request, $this->urls->getString('forum_post'), $postId); } }