Introduce ConfigFileManager for config files

This commit is contained in:
Philipp 2023-01-01 21:10:37 +01:00
parent fea4b202c1
commit 0f91d1cbde
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
21 changed files with 343 additions and 302 deletions

View file

@ -21,13 +21,13 @@
namespace Friendica\Core\Config\ValueObject;
use Friendica\Core\Config\Util\ConfigFileLoader;
use Friendica\Core\Config\Util\ConfigFileManager;
use ParagonIE\HiddenString\HiddenString;
/**
* The Friendica config cache for the application
* Initial, all *.config.php files are loaded into this cache with the
* ConfigFileLoader ( @see ConfigFileLoader )
* ConfigFileManager ( @see ConfigFileManager )
*/
class Cache
{
@ -35,8 +35,8 @@ class Cache
const SOURCE_STATIC = 0;
/** @var int Indicates that the cache entry is set by file - Low Priority */
const SOURCE_FILE = 1;
/** @var int Indicates that the cache entry is set by the DB config table - Middle Priority */
const SOURCE_DB = 2;
/** @var int Indicates that the cache entry is manually set by the application (per admin page/console) - Middle Priority */
const SOURCE_DATA = 2;
/** @var int Indicates that the cache entry is set by a server environment variable - High Priority */
const SOURCE_ENV = 3;
/** @var int Indicates that the cache entry is fixed and must not be changed */
@ -128,6 +128,34 @@ class Cache
return $this->source[$cat][$key] ?? -1;
}
/**
* Returns the whole config array based on the given source type
*
* @param int $source Indicates the source of the config entry
*
* @return array The config array part of the given source
*/
public function getDataBySource(int $source): array
{
$data = [];
$categories = array_keys($this->source);
foreach ($categories as $category) {
if (is_array($this->source[$category])) {
$keys = array_keys($this->source[$category]);
foreach ($keys as $key) {
if ($this->source[$category][$key] === $source) {
$data[$category][$key] = $this->config[$category][$key];
}
}
}
}
return $data;
}
/**
* Sets a value in the config cache. Accepts raw output from the config table
*