PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.59.2
MailPoet – Newsletters, Email Marketing, and Automation v3.59.2
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / Features / FeatureFlagsController.php

FeatureFlagsController.php in MailPoet – Newsletters, Email Marketing, and Automation 3.59.2, at lib/Features/FeatureFlagsController.php

54 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailPoet\Features;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Entities\FeatureFlagEntity;
9
10 class FeatureFlagsController {
11
12 /** @var FeaturesController */
13 private $featuresController;
14
15 /** @var FeatureFlagsRepository */
16 private $featureFlagsRepository;
17
18 public function __construct(FeaturesController $featuresController, FeatureFlagsRepository $featureFlagsRepository) {
19 $this->featuresController = $featuresController;
20 $this->featureFlagsRepository = $featureFlagsRepository;
21 }
22
23 public function set($name, $value) {
24 if (!$this->featuresController->exists($name)) {
25 throw new \RuntimeException("Feature '$name' does not exist'");
26 }
27
28 $this->featureFlagsRepository->createOrUpdate(['name' => $name, 'value' => $value]);
29 }
30
31 public function getAll() {
32 $flags = $this->featureFlagsRepository->findAll();
33 $flagsMap = array_combine(
34 array_map(
35 function (FeatureFlagEntity $flag) {
36 return $flag->getName();
37 },
38 $flags
39 ),
40 $flags
41 );
42
43 $output = [];
44 foreach ($this->featuresController->getDefaults() as $name => $default) {
45 $output[] = [
46 'name' => $name,
47 'value' => isset($flagsMap[$name]) ? (bool)$flagsMap[$name]->getValue() : $default,
48 'default' => $default,
49 ];
50 }
51 return $output;
52 }
53 }
54