1 | <?php |
||
2 | /** |
||
3 | * SEOmatic plugin for Craft CMS 3.x |
||
4 | * |
||
5 | * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
||
6 | * and flexible |
||
7 | * |
||
8 | * @link https://nystudio107.com |
||
9 | * @copyright Copyright (c) 2017 nystudio107 |
||
10 | */ |
||
11 | |||
12 | namespace nystudio107\seomatic\base; |
||
13 | |||
14 | use craft\helpers\StringHelper; |
||
15 | |||
16 | /** |
||
17 | * InheritableSettingsModel allows keeping track of inherited/overridden settings. |
||
18 | * |
||
19 | * @author nystudio107 |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
20 | * @package Seomatic |
||
21 | * @since 3.4.0 |
||
22 | */ |
||
23 | abstract class InheritableSettingsModel extends VarsModel |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var array A list of all the settings for which the inherited values should be used. |
||
28 | */ |
||
29 | public $inherited = []; |
||
30 | |||
31 | /** |
||
32 | * @var array A list of all the settings for which the inherited values are overridden. |
||
33 | */ |
||
34 | public $overrides = []; |
||
35 | |||
36 | /** |
||
37 | * Keep track of which settings to use the override for. |
||
38 | * |
||
39 | * @param string $name |
||
0 ignored issues
–
show
|
|||
40 | * @param mixed $value |
||
0 ignored issues
–
show
|
|||
41 | * @throws \yii\base\UnknownPropertyException |
||
0 ignored issues
–
show
|
|||
42 | */ |
||
43 | public function __set($name, $value) |
||
44 | { |
||
45 | if (StringHelper::startsWith($name, 'override-')) { |
||
46 | $remainder = StringHelper::removeLeft($name, 'override-'); |
||
47 | |||
48 | if ($remainder) { |
||
49 | if ($value) { |
||
50 | $this->overrides[$remainder] = true; |
||
51 | unset($this->inherited[$remainder]); |
||
52 | } else { |
||
53 | $this->inherited[$remainder] = true; |
||
54 | unset($this->overrides[$remainder]); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | return; |
||
59 | } |
||
60 | |||
61 | parent::__set($name, $value); |
||
62 | } |
||
63 | } |
||
64 |