1 | <?php |
||
18 | class Config { |
||
19 | |||
20 | const FEATURE_ENSURED = 1; |
||
21 | const FEATURE_NOT_AVAILABLE = 0; |
||
22 | const FEATURE_ALREADY_ENSURED = -1; |
||
23 | |||
24 | /** |
||
25 | * The initial setting values. |
||
26 | * |
||
27 | * @var Array |
||
28 | */ |
||
29 | protected $config = array( |
||
30 | 'connection' => false, |
||
31 | 'sync' => false, |
||
32 | 'tracking' => false, |
||
33 | 'tos' => false, |
||
34 | ); |
||
35 | |||
36 | /** |
||
37 | * Creates the configuration class instance. |
||
38 | */ |
||
39 | public function __construct() { |
||
47 | |||
48 | /** |
||
49 | * Require a feature to be initialized. It's up to the package consumer to actually add |
||
50 | * the package to their composer project. Declaring a requirement using this method |
||
51 | * instructs the class to initalize it. |
||
52 | * |
||
53 | * @param String $feature the feature slug. |
||
54 | */ |
||
55 | public function ensure( $feature ) { |
||
58 | |||
59 | /** |
||
60 | * Runs on plugins_loaded hook priority with priority 2. |
||
61 | * |
||
62 | * @action plugins_loaded |
||
63 | */ |
||
64 | public function on_plugins_loaded() { |
||
82 | |||
83 | /** |
||
84 | * Returns true if the required class is available and alerts the user if it's not available |
||
85 | * in case the site is in debug mode. |
||
86 | * |
||
87 | * @param String $classname a fully qualified class name. |
||
88 | * @return Boolean whether the class is available. |
||
89 | */ |
||
90 | protected function ensure_class( $classname ) { |
||
109 | |||
110 | /** |
||
111 | * Ensures a feature is enabled, sets it up if it hasn't already been set up. |
||
112 | * |
||
113 | * @param String $feature slug of the feature. |
||
114 | * @return Integer either FEATURE_ENSURED, FEATURE_ALREADY_ENSURED or FEATURE_NOT_AVAILABLE constants. |
||
115 | */ |
||
116 | protected function ensure_feature( $feature ) { |
||
137 | |||
138 | /** |
||
139 | * Dummy method to enable Terms of Service. |
||
140 | */ |
||
141 | protected function enable_tos() { |
||
144 | |||
145 | /** |
||
146 | * Enables the tracking feature. Depends on the Terms of Service package, so enables it too. |
||
147 | */ |
||
148 | protected function enable_tracking() { |
||
166 | |||
167 | /** |
||
168 | * Enables the Sync feature. |
||
169 | */ |
||
170 | protected function enable_sync() { |
||
175 | |||
176 | /** |
||
177 | * Enables the Connection feature. |
||
178 | */ |
||
179 | protected function enable_connection() { |
||
184 | |||
185 | } |
||
186 |