Use sharp config format.
This commit is contained in:
parent
227754dbff
commit
e859c5d839
4 changed files with 18 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
[Dd]esktop.ini
|
||||
.DS_Store
|
||||
/.debug
|
||||
/config/config.cfg
|
||||
/config/config.ini
|
||||
/public/robots.txt
|
||||
/vendor
|
||||
|
|
|
@ -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 '<h3>Unable to connect to database</h3>';
|
||||
die($ex->getMessage());
|
||||
}
|
||||
|
||||
$awk = new AwakiContext($db, $config['urls']);
|
||||
$awk = new AwakiContext($db, $config->scopeTo('urls'));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue