/
BaseConfig.php
98 lines (83 loc) · 2.28 KB
/
BaseConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\config;
use Craft;
use craft\base\Model;
/**
* Base config class
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.2.0
*/
class BaseConfig extends Model
{
/**
* @var array Settings that have been renamed
*/
protected static array $renamedSettings = [];
/**
* @var string|null The config filename
*/
protected ?string $filename = null;
/**
* Factory method for creating new config objects.
*
* @param array $config
* @return static
*/
public static function create(array $config = []): static
{
// We can't use Craft::createObject() here because Craft may not be autoloadable yet
return new static($config);
}
/**
* @inerhitdoc
*/
final public function __construct($config = [])
{
if (class_exists(Craft::class, false) && Craft::$app) {
$this->filename = Craft::$app->getConfig()->getLoadingConfigFile();
}
parent::__construct($config);
}
/**
* @inheritdoc
*/
public function __get($name)
{
if (isset(static::$renamedSettings[$name])) {
return $this->{static::$renamedSettings[$name]};
}
return parent::__get($name);
}
/**
* @inheritdoc
*/
public function __set($name, $value)
{
if (isset(static::$renamedSettings[$name])) {
$newName = static::$renamedSettings[$name];
if (class_exists(Craft::class, false)) {
$configFilePath = $this->filename ? Craft::$app->getConfig()->getConfigFilePath($this->filename) : null;
Craft::$app->getDeprecator()->log(sprintf('%s::%s', static::class, $name), "`$name` has been renamed to `$newName`.", $configFilePath);
}
$this->$newName = $value;
return;
}
parent::__set($name, $value);
}
/**
* @inheritdoc
*/
public function __isset($name)
{
if (isset(static::$renamedSettings[$name])) {
return isset($this->{static::$renamedSettings[$name]});
}
return parent::__isset($name);
}
}