3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model\Config;
24 use Friendica\Database\Database;
27 * The DB-based model of (P-)Config values
28 * Encapsulates db-calls in case of config queries
30 abstract class DbaConfig
36 * @param Database $dba The database connection of this model
38 public function __construct(Database $dba)
44 * Checks if the model is currently connected
48 public function isConnected()
50 return $this->dba->isConnected();
54 * Formats a DB value to a config value
55 * - null = The db-value isn't set
56 * - bool = The db-value is either '0' or '1'
57 * - array = The db-value is a serialized array
58 * - string = The db-value is a string
60 * Keep in mind that there aren't any numeric/integer config values in the database
62 * @param null|string $value
64 * @return null|array|string
66 protected function toConfigValue($value)
74 case preg_match("|^a:[0-9]+:{.*}$|s", $value):
75 return unserialize($value);
83 * Formats a config value to a DB value (string)
89 protected function toDbValue($value)
91 // if not set, save an empty string
98 case is_array($value):
99 return serialize($value);
102 return (string)$value;