Issues (10)

src/AbstractConfigSchema.php (3 issues)

Severity
1
<?php
2
/**
3
 * Bright Nucleus Config Component.
4
 *
5
 * @package   BrightNucleus\Config
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2016-2017 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\Config;
13
14
/**
15
 * Handles basic validation of the config schema.
16
 *
17
 * @since   0.1.0
18
 *
19
 * @package BrightNucleus\Config
20
 * @author  Alain Schlesser <[email protected]>
21
 */
22
abstract class AbstractConfigSchema implements ConfigSchemaInterface
23
{
24
25
    /**
26
     * The defined values that are recognized.
27
     *
28
     * @var ConfigInterface
29
     */
30
    protected $defined;
31
32
    /**
33
     * The default values that can be overwritten.
34
     *
35
     * @var ConfigInterface
36
     */
37
    protected $defaults;
38
39
    /**
40
     * The required values that need to be set.
41
     *
42
     * @var ConfigInterface
43
     */
44
    protected $required;
45
46
    /**
47
     * Get the set of defined options.
48
     *
49
     * @since 0.1.0
50
     *
51
     * @return array|null
52
     */
53
    public function getDefinedOptions()
54
    {
55
        if (! $this->defined) {
56
            return null;
57
        }
58
59
        if ($this->defined instanceof ConfigInterface) {
0 ignored issues
show
$this->defined is always a sub-type of BrightNucleus\Config\ConfigInterface.
Loading history...
60
            return $this->defined->getArrayCopy();
61
        }
62
63
        return (array)$this->defined;
64
    }
65
66
    /**
67
     * Get the set of default options.
68
     *
69
     * @since 0.1.0
70
     *
71
     * @return array|null
72
     */
73
    public function getDefaultOptions()
74
    {
75
        if (! $this->defaults) {
76
            return null;
77
        }
78
79
        if ($this->defaults instanceof ConfigInterface) {
0 ignored issues
show
$this->defaults is always a sub-type of BrightNucleus\Config\ConfigInterface.
Loading history...
80
            return $this->defaults->getArrayCopy();
81
        }
82
83
        return (array)$this->defaults;
84
    }
85
86
    /**
87
     * Get the set of required options.
88
     *
89
     * @since 0.1.0
90
     *
91
     * @return array|null
92
     */
93
    public function getRequiredOptions()
94
    {
95
        if (! $this->required) {
96
            return null;
97
        }
98
99
        if ($this->required instanceof ConfigInterface) {
0 ignored issues
show
$this->required is always a sub-type of BrightNucleus\Config\ConfigInterface.
Loading history...
100
            return $this->required->getArrayCopy();
101
        }
102
103
        return (array)$this->required;
104
    }
105
}
106