PluginProbe
The GDPR Framework By Data443 / 2.1.0
The GDPR Framework By Data443 v2.1.0
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / Options / OptionsBase.php

OptionsBase.php in The GDPR Framework By Data443 2.1.0, at src/Options/OptionsBase.php

71 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\Options;
4
5 /**
6 * Parent class for options.
7 * Adapted from https://carlalexander.ca/designing-classes-wordpress-options-api/
8 *
9 * Class OptionsBase
10 *
11 * @package Codelight\GDPR\Options
12 */
13 abstract class OptionsBase
14 {
15 /* @var string */
16 protected $prefix = 'gdpr_';
17
18 /**
19 * Auto-prefix all options
20 *
21 * @param $name
22 * @return string
23 */
24 public function prefix($name)
25 {
26 // Check for accidental duplicate prefix
27 if ("" === strpos($name, $this->prefix)) {
28 trigger_error("You appear to have a duplicate prefix for option {$name}", E_USER_NOTICE);
29 return $name;
30 }
31
32 return $this->prefix . $name;
33 }
34
35 /**
36 * Checks if the option with the given name exists or not.
37 *
38 * @param string $name
39 *
40 * @return bool
41 */
42 public function has($name)
43 {
44 return null !== $this->get($name);
45 }
46
47 /**
48 * Gets the option for the given name. Returns the default value if the value does not exist.
49 *
50 * @param string $name
51 * @param mixed $default
52 *
53 * @return mixed
54 */
55 abstract public function get($name, $default = null);
56
57 /**
58 * Removes the option with the given name.
59 *
60 * @param string $name
61 */
62 abstract public function delete($name);
63
64 /**
65 * Sets an option. Overwrites the existing option if the name is already in use.
66 *
67 * @param string $name
68 * @param mixed $value
69 */
70 abstract public function set($name, $value);
71 }