3 namespace Friendica\Model\Config;
5 use Friendica\Database\Database;
8 * The DB-based model of (P-)Config values
9 * Encapsulates db-calls in case of config queries
11 abstract class DbaConfig
17 * @param Database $dba The database connection of this model
19 public function __construct(Database $dba)
25 * Checks if the model is currently connected
29 public function isConnected()
31 return $this->dba->isConnected();
35 * Formats a DB value to a config value
36 * - null = The db-value isn't set
37 * - bool = The db-value is either '0' or '1'
38 * - array = The db-value is a serialized array
39 * - string = The db-value is a string
41 * Keep in mind that there aren't any numeric/integer config values in the database
43 * @param null|string $value
45 * @return null|array|string
47 protected function toConfigValue($value)
55 case preg_match("|^a:[0-9]+:{.*}$|s", $value):
56 return unserialize($value);
64 * Formats a config value to a DB value (string)
70 protected function toDbValue($value)
72 // if not set, save an empty string
79 case is_array($value):
80 return serialize($value);
83 return (string)$value;