1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 06:04:53 +00:00
Arsse/vendor/JKingWeb/NewsSync/Conf.php

62 lines
1.7 KiB
PHP
Raw Normal View History

2016-09-27 13:00:02 +00:00
<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync;
class Conf {
public $lang = "en";
public $dbClass = NS_BASE."Db\\DriverSQLite3";
2016-09-27 13:00:02 +00:00
public $dbSQLite3PDO = false;
public $dbSQLite3File = BASE."newssync.db";
public $dbPostgreSQLPDO = false;
public $dbPostgreSQLHost = "localhost";
public $dbPostgreSQLUser = "newssync";
public $dbPostgreSQLPass = "";
public $dbPostgreSQLPort = 5432;
public $dbPostgreSQLDb = "newssync";
public $dbPostgreSQLSchema = "";
public $dbMySQLPDO = false;
public $dbMySQLHost = "localhost";
public $dbMySQLUser = "newssync";
public $dbMySQLPass = "";
public $dbMySQLPort = 3306;
public $dbMySQLDb = "newssync";
public $authClass = NS_BASE."Auth\\DriverInternal";
public $authPreferHTTP = false;
public $authProvision = false;
2016-09-27 13:00:02 +00:00
public $simplepieCache = BASE.".cache";
public function __construct(string $import_file = "") {
if($import_file != "") $this->import_file($import_file);
2016-09-27 13:00:02 +00:00
}
public function importFile(string $file): self {
if(!file_exists($file)) throw new Conf\Exception("fileMissing");
if(!is_readable($file)) throw new Conf\Exception("fileUnreadable");
2016-09-27 13:00:02 +00:00
$json = @file_get_contents($file);
if($json===false) throw new Conf\Exception("fileUnreadable");
return $this->import($json);
}
public function import(string $json): self {
if($json=="") throw new Conf\Exception("blank");
2016-09-27 13:00:02 +00:00
$json = json_decode($json, true);
if(!is_array($json)) throw new Conf\Exception("corrupt");
2016-09-27 13:00:02 +00:00
foreach($json as $key => $value) {
$this->$$key = $value;
}
return $this;
2016-09-27 13:00:02 +00:00
}
public function export(string $file = ""): string {
2016-09-27 13:00:02 +00:00
return json_encode($this, JSON_PRETTY_PRINT);
}
public function __toString(): string {
2016-09-27 13:00:02 +00:00
return $this->export();
}
}