2016-09-27 13:00:02 +00:00
< ? php
2017-07-17 02:27:55 +00:00
/** Conf class */
2016-09-27 13:00:02 +00:00
declare ( strict_types = 1 );
2017-03-28 04:12:12 +00:00
namespace JKingWeb\Arsse ;
2016-09-27 13:00:02 +00:00
2017-07-17 02:27:55 +00:00
/** Class for loading , saving , and querying configuration
*
* The Conf class serves both as a means of importing and querying configuration information , as well as a source for default parameters when a configuration file does not specify a value .
* All public properties are configuration parameters that may be set by the server administrator .
*/
2016-09-27 13:00:02 +00:00
class Conf {
2017-07-17 02:27:55 +00:00
/** @var string Default language to use for logging and errors */
2017-02-16 20:29:42 +00:00
public $lang = " en " ;
2016-10-15 13:45:23 +00:00
2017-07-17 02:27:55 +00:00
/** @var string Class of the database driver in use (SQLite3 by default) */
2017-03-07 23:01:13 +00:00
public $dbDriver = Db\SQLite3\Driver :: class ;
2017-07-17 02:27:55 +00:00
/** @var string Base path to database schema files */
2017-03-10 02:39:42 +00:00
public $dbSchemaBase = BASE . 'sql' ;
2017-07-17 02:27:55 +00:00
/** @var boolean Whether to attempt to automatically update the database when updated to a new version with schema changes */
2017-07-12 00:27:37 +00:00
public $dbAutoUpdate = true ;
2017-07-17 02:27:55 +00:00
/** @var string Full path and file name of SQLite database (if using SQLite) */
2017-03-28 04:12:12 +00:00
public $dbSQLite3File = BASE . " arsse.db " ;
2017-07-17 02:27:55 +00:00
/** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */
2017-02-16 20:29:42 +00:00
public $dbSQLite3Key = " " ;
2017-07-17 02:27:55 +00:00
/** @var string Address of host name for PostgreSQL database server (if using PostgreSQL) */
2017-02-16 20:29:42 +00:00
public $dbPostgreSQLHost = " localhost " ;
2017-07-17 02:27:55 +00:00
/** @var string Log-in user name for PostgreSQL database server (if using PostgreSQL) */
2017-03-28 04:12:12 +00:00
public $dbPostgreSQLUser = " arsse " ;
2017-07-17 02:27:55 +00:00
/** @var string Log-in password for PostgreSQL database server (if using PostgreSQL) */
2017-02-16 20:29:42 +00:00
public $dbPostgreSQLPass = " " ;
2017-07-17 02:27:55 +00:00
/** @var integer Listening port for PostgreSQL database server (if using PostgreSQL) */
2017-02-16 20:29:42 +00:00
public $dbPostgreSQLPort = 5432 ;
2017-07-17 02:27:55 +00:00
/** @var string Database name on PostgreSQL database server (if using PostgreSQL) */
2017-03-28 04:12:12 +00:00
public $dbPostgreSQLDb = " arsse " ;
2017-07-17 02:27:55 +00:00
/** @var string Schema name on PostgreSQL database server (if using PostgreSQL) */
2017-02-16 20:29:42 +00:00
public $dbPostgreSQLSchema = " " ;
2017-07-17 02:27:55 +00:00
/** @var string Address of host name for MySQL/MariaDB database server (if using MySQL or MariaDB) */
2017-02-16 20:29:42 +00:00
public $dbMySQLHost = " localhost " ;
2017-07-17 02:27:55 +00:00
/** @var string Log-in user name for MySQL/MariaDB database server (if using MySQL or MariaDB) */
2017-03-28 04:12:12 +00:00
public $dbMySQLUser = " arsse " ;
2017-07-17 02:27:55 +00:00
/** @var string Log-in password for MySQL/MariaDB database server (if using MySQL or MariaDB) */
2017-02-16 20:29:42 +00:00
public $dbMySQLPass = " " ;
2017-07-17 02:27:55 +00:00
/** @var integer Listening port for MySQL/MariaDB database server (if using MySQL or MariaDB) */
2017-02-16 20:29:42 +00:00
public $dbMySQLPort = 3306 ;
2017-07-17 02:27:55 +00:00
/** @var string Database name on MySQL/MariaDB database server (if using MySQL or MariaDB) */
2017-03-28 04:12:12 +00:00
public $dbMySQLDb = " arsse " ;
2016-10-15 13:45:23 +00:00
2017-07-17 02:27:55 +00:00
/** @var string Class of the user management driver in use (Internal by default) */
2017-03-07 23:01:13 +00:00
public $userDriver = User\Internal\Driver :: class ;
2017-07-17 02:27:55 +00:00
/** @var boolean Whether users are already authenticated by the Web server before the application is executed */
2017-07-15 17:33:17 +00:00
public $userPreAuth = true ;
2017-07-17 02:27:55 +00:00
/** @ var boolean Whether to automatically append the hostname to form a user @ host combination before performing authentication
* @ deprecated */
2017-02-16 20:29:42 +00:00
public $userComposeNames = true ;
2017-07-17 02:27:55 +00:00
/** @var integer Desired length of temporary user passwords */
2017-02-20 22:04:13 +00:00
public $userTempPasswordLength = 20 ;
2016-09-27 13:00:02 +00:00
2017-07-17 02:27:55 +00:00
/** @var string Class of the background feed update service driver in use (Forking by default) */
2017-07-15 17:33:17 +00:00
public $serviceDriver = Service\Internal\Driver :: class ;
2017-07-17 02:27:55 +00:00
/** @ var string The interval between checks for new feeds , as an ISO 8601 duration
* @ see https :// en . wikipedia . org / wiki / ISO_8601 #Durations
*/
2017-07-12 00:27:37 +00:00
public $serviceFrequency = " PT2M " ;
2017-07-17 02:27:55 +00:00
/** @var integer Number of concurrent feed updates to perform */
2017-07-15 17:33:17 +00:00
public $serviceQueueWidth = 5 ;
2017-07-17 02:27:55 +00:00
/** @var string The base server address (with scheme, host, port if necessary, and terminal slash) to connect to the server when performing feed updates using cURL */
2017-07-12 00:27:37 +00:00
public $serviceCurlBase = " http://localhost/ " ;
2017-07-17 02:27:55 +00:00
/** @var string The user name to use when performing feed updates using cURL; if none is provided, a temporary name and password will be stored in the database (this is not compatible with pre-authentication) */
2017-07-12 00:27:37 +00:00
public $serviceCurlUser = null ;
2017-07-17 02:27:55 +00:00
/** @var string The password to use when performing feed updates using cURL */
2017-07-12 00:27:37 +00:00
public $serviceCurlPassword = null ;
2017-07-17 02:27:55 +00:00
/** @var integer Number of seconds to wait for data when fetching feeds from foreign servers */
2017-05-27 22:15:52 +00:00
public $fetchTimeout = 10 ;
2017-07-17 02:27:55 +00:00
/** @var integer Maximum size, in bytes, of data when fetching feeds from foreign servers */
2017-05-27 22:15:52 +00:00
public $fetchSizeLimit = 2 * 1024 * 1024 ;
2017-07-17 02:27:55 +00:00
/** @var string User-Agent string to use when fetching feeds from foreign servers */
2017-05-27 22:15:52 +00:00
public $fetchUserAgentString ;
2016-09-27 13:00:02 +00:00
2017-07-17 02:27:55 +00:00
/** Creates a new configuration object
* @ param string $import_file Optional file to read configuration data from
* @ see self :: importFile ()
*/
2017-02-16 20:29:42 +00:00
public function __construct ( string $import_file = " " ) {
if ( $import_file != " " ) $this -> importFile ( $import_file );
2017-07-11 13:15:44 +00:00
if ( is_null ( $this -> fetchUserAgentString )) {
$this -> fetchUserAgentString = sprintf ( 'Arsse/%s (%s %s; %s; https://code.jkingweb.ca/jking/arsse) PicoFeed (https://github.com/fguillot/picoFeed)' ,
VERSION , // Arsse version
php_uname ( 's' ), // OS
php_uname ( 'r' ), // OS version
php_uname ( 'm' ) // platform architecture
);
}
2017-02-16 20:29:42 +00:00
}
2016-09-30 01:58:09 +00:00
2017-07-17 02:27:55 +00:00
/** Layers configuration data from a file into an existing object
*
* The file must be a PHP script which return an array with keys that match the properties of the Conf class . Malformed files will throw an exception ; unknown keys are silently ignored . Files may be imported is succession , though this is not currently used .
* @ param string $file Full path and file name for the file to import */
2017-02-16 20:29:42 +00:00
public function importFile ( string $file ) : self {
if ( ! file_exists ( $file )) throw new Conf\Exception ( " fileMissing " , $file );
if ( ! is_readable ( $file )) throw new Conf\Exception ( " fileUnreadable " , $file );
try {
ob_start ();
$arr = ( @ include $file );
} catch ( \Throwable $e ) {
$arr = null ;
} finally {
ob_end_clean ();
}
if ( ! is_array ( $arr )) throw new Conf\Exception ( " fileCorrupt " , $file );
return $this -> import ( $arr );
}
2016-09-27 13:00:02 +00:00
2017-07-17 02:27:55 +00:00
/** Layers configuration data from an associative array into an existing object
*
* The input array must have keys that match the properties of the Conf class ; unknown keys are silently ignored . Arrays may be imported is succession , though this is not currently used .
* @ param mixed [] $arr Array of configuration parameters to export */
2017-02-16 20:29:42 +00:00
public function import ( array $arr ) : self {
foreach ( $arr as $key => $value ) {
$this -> $key = $value ;
}
return $this ;
}
2016-09-27 13:00:02 +00:00
2017-07-17 02:27:55 +00:00
/** Outputs non - default configuration settings as a string compatible with var_export ()
*
* If provided a file name , will produce the text of a PHP script suitable for laterimport
* @ param string $file Full path and file name for the file to export to */
2017-02-16 20:29:42 +00:00
public function export ( string $file = " " ) : string {
2017-07-17 02:27:55 +00:00
// TODO: write export method
2017-02-16 20:29:42 +00:00
}
2017-07-17 02:27:55 +00:00
/** Alias of export () method with no parameters
* @ see self :: export () */
2017-02-16 20:29:42 +00:00
public function __toString () : string {
return $this -> export ();
}
2016-09-27 13:00:02 +00:00
}