Analytics.php
3 years ago
AutomatedLatestContent.php
2 months ago
AutomaticEmails.php
3 years ago
Captcha.php
1 year ago
Coupons.php
2 years ago
CustomFields.php
2 months ago
DynamicProducts.php
1 year ago
DynamicSegments.php
2 months ago
FeatureFlags.php
3 years ago
Forms.php
2 months ago
Help.php
1 year ago
ImportExport.php
2 months ago
Mailer.php
1 year ago
NewsletterLinks.php
2 months ago
NewsletterTemplates.php
2 months ago
Newsletters.php
2 months ago
Premium.php
10 months ago
RedirectResponse.php
1 year ago
Segments.php
2 months ago
SendingQueue.php
2 months ago
Services.php
6 months ago
Settings.php
2 months ago
Setup.php
1 year ago
StatisticsExport.php
3 months ago
SubscriberStats.php
1 month ago
Subscribers.php
2 months ago
Tags.php
3 years ago
UserFlags.php
2 years ago
WoocommerceProductVariations.php
2 months ago
WoocommerceSettings.php
3 years ago
index.php
3 years ago
FeatureFlags.php
54 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\API\JSON\v1; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\API\JSON\Endpoint as APIEndpoint; |
| 9 | use MailPoet\API\JSON\Error as APIError; |
| 10 | use MailPoet\Config\AccessControl; |
| 11 | use MailPoet\Features\FeatureFlagsController; |
| 12 | use MailPoet\Features\FeaturesController; |
| 13 | |
| 14 | class FeatureFlags extends APIEndpoint { |
| 15 | |
| 16 | public $permissions = [ |
| 17 | 'global' => AccessControl::PERMISSION_MANAGE_FEATURES, |
| 18 | ]; |
| 19 | |
| 20 | /** @var FeaturesController */ |
| 21 | private $featuresController; |
| 22 | |
| 23 | /** @var FeatureFlagsController */ |
| 24 | private $featureFlagsController; |
| 25 | |
| 26 | public function __construct( |
| 27 | FeaturesController $featuresController, |
| 28 | FeatureFlagsController $featureFlags |
| 29 | ) { |
| 30 | $this->featuresController = $featuresController; |
| 31 | $this->featureFlagsController = $featureFlags; |
| 32 | } |
| 33 | |
| 34 | public function getAll() { |
| 35 | $featureFlags = $this->featureFlagsController->getAll(); |
| 36 | return $this->successResponse($featureFlags); |
| 37 | } |
| 38 | |
| 39 | public function set(array $flags) { |
| 40 | foreach ($flags as $name => $value) { |
| 41 | if (!$this->featuresController->exists($name)) { |
| 42 | return $this->badRequest([ |
| 43 | APIError::BAD_REQUEST => "Feature '$name' does not exist'", |
| 44 | ]); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | foreach ($flags as $name => $value) { |
| 49 | $this->featureFlagsController->set($name, (bool)$value); |
| 50 | } |
| 51 | return $this->successResponse([]); |
| 52 | } |
| 53 | } |
| 54 |