5e9fce9c6981457329565f9783108d9fe354157c
[yaffs-website] / web / modules / contrib / security_review / src / CheckSettings.php
1 <?php
2
3 namespace Drupal\security_review;
4
5 use Drupal\Core\Config\Config;
6
7 /**
8  * Defines the default implementation of CheckSettingsInterface.
9  */
10 class CheckSettings implements CheckSettingsInterface {
11
12   /**
13    * The parent check.
14    *
15    * @var \Drupal\security_review\Check
16    */
17   protected $check;
18
19   /**
20    * The configuration storage of the parent Check.
21    *
22    * @var \Drupal\Core\Config\Config $config
23    */
24   protected $config;
25
26   /**
27    * Creates a CheckSettings instance.
28    *
29    * @param \Drupal\security_review\Check $check
30    *   The parent Check.
31    * @param \Drupal\Core\Config\Config $config
32    *   The parent Check's configuration.
33    */
34   public function __construct(Check $check, Config &$config) {
35     $this->check = $check;
36     $this->config = $config;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function get($key, $default_value = NULL) {
43     $value = $this->config->get('settings.' . $key);
44
45     if ($value == NULL) {
46       return $default_value;
47     }
48     return $value;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function set($key, $value) {
55     $this->config->set('settings.' . $key, $value);
56     $this->config->save();
57     return $this;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function buildForm() {
64     return [];
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function validateForm(array &$form, array $values) {
71     // Validation is optional.
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function submitForm(array &$form, array $values) {
78     // Handle submission.
79   }
80
81 }