1 | <?php |
||
17 | class Config { |
||
18 | |||
19 | const FEATURE_ENSURED = 1; |
||
20 | const FEATURE_NOT_AVAILABLE = 0; |
||
21 | const FEATURE_ALREADY_ENSURED = -1; |
||
22 | |||
23 | /** |
||
24 | * The initial setting values. |
||
25 | * |
||
26 | * @var Array |
||
27 | */ |
||
28 | protected $config = array( |
||
29 | 'sync' => false, |
||
30 | 'tracking' => false, |
||
31 | 'tos' => false, |
||
32 | ); |
||
33 | |||
34 | /** |
||
35 | * Creates the configuration class instance. |
||
36 | */ |
||
37 | public function __construct() { |
||
45 | |||
46 | /** |
||
47 | * Require a feature to be initialized. It's up to the package consumer to actually add |
||
48 | * the package to their composer project. Declaring a requirement using this method |
||
49 | * instructs the class to initalize it. |
||
50 | * |
||
51 | * @param String $feature the feature slug. |
||
52 | */ |
||
53 | public function ensure( $feature ) { |
||
56 | |||
57 | /** |
||
58 | * Runs on plugins_loaded hook priority with priority 2. |
||
59 | * |
||
60 | * @action plugins_loaded |
||
61 | */ |
||
62 | public function on_plugins_loaded() { |
||
75 | |||
76 | /** |
||
77 | * Returns true if the required class is available and alerts the user if it's not available |
||
78 | * in case the site is in debug mode. |
||
79 | * |
||
80 | * @param String $classname a fully qualified class name. |
||
81 | * @return Boolean whether the class is available. |
||
82 | */ |
||
83 | protected function ensure_class( $classname ) { |
||
102 | |||
103 | /** |
||
104 | * Ensures a feature is enabled, sets it up if it hasn't already been set up. |
||
105 | * |
||
106 | * @param String $feature slug of the feature. |
||
107 | * @return Integer either FEATURE_ENSURED, FEATURE_ALREADY_ENSURED or FEATURE_NOT_AVAILABLE constants. |
||
108 | */ |
||
109 | protected function ensure_feature( $feature ) { |
||
130 | |||
131 | /** |
||
132 | * Dummy method to enable Terms of Service. |
||
133 | */ |
||
134 | protected function enable_tos() { |
||
137 | |||
138 | /** |
||
139 | * Enables the tracking feature. Depends on the Terms of Service package, so enables it too. |
||
140 | */ |
||
141 | protected function enable_tracking() { |
||
159 | |||
160 | /** |
||
161 | * Enables the Sync feature. |
||
162 | */ |
||
163 | protected function enable_sync() { |
||
168 | |||
169 | } |
||
170 |