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 / FeatureFlagsRepository.php
FeatureFlagsRepository.php
49 lines 1.1 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\Doctrine\Repository;
9 use MailPoet\Entities\FeatureFlagEntity;
10
11 /**
12 * @extends Repository<FeatureFlagEntity>
13 */
14 class FeatureFlagsRepository extends Repository {
15 protected function getEntityClassName() {
16 return FeatureFlagEntity::class;
17 }
18
19 /**
20 * @param array $data
21 * @throws \RuntimeException
22 * @throws \InvalidArgumentException
23 * @return FeatureFlagEntity
24 */
25 public function createOrUpdate(array $data = []) {
26 if (!$data['name']) {
27 throw new \InvalidArgumentException('Missing name');
28 }
29 $featureFlag = $this->findOneBy([
30 'name' => $data['name'],
31 ]);
32 if (!$featureFlag) {
33 $featureFlag = new FeatureFlagEntity($data['name']);
34 $this->persist($featureFlag);
35 }
36
37 if (array_key_exists('value', $data)) {
38 $featureFlag->setValue($data['value']);
39 }
40
41 try {
42 $this->flush();
43 } catch (\Exception $e) {
44 throw new \RuntimeException("Error when saving feature " . $data['name']);
45 }
46 return $featureFlag;
47 }
48 }
49