HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/FeatureFlags/ConfigurationLoader.php
<?php

namespace GoDaddy\WordPress\MWC\Core\FeatureFlags;

use GoDaddy\WordPress\MWC\Common\Components\Contracts\ComponentContract;
use GoDaddy\WordPress\MWC\Common\Configuration\Configuration;
use GoDaddy\WordPress\MWC\Common\Helpers\ArrayHelper;
use GoDaddy\WordPress\MWC\Core\FeatureFlags\Models\FeatureFlag;
use GoDaddy\WordPress\MWC\Core\FeatureFlags\Repositories\FeatureFlagsRepository;

/**
 * Loads feature flags values into the configuration.
 */
class ConfigurationLoader implements ComponentContract
{
    /**
     * Loads the component.
     */
    public function load()
    {
        $this->maybeUpdateFeaturesConfiguration();
    }

    /**
     * Loads the available feature flags and tries to inject those values into the configuration.
     */
    protected function maybeUpdateFeaturesConfiguration()
    {
        foreach (FeatureFlagsRepository::all() as $featureFlag) {
            $this->maybeUpdateFeatureConfiguration($featureFlag);
        }
    }

    /**
     * Attempts to inject the value of the given feature flag into the configuration.
     *
     * @param FeatureFlag $featureFlag
     */
    protected function maybeUpdateFeatureConfiguration(FeatureFlag $featureFlag)
    {
        if (! $featureId = $featureFlag->getId()) {
            return;
        }

        // return early if the feature has no configuration defined
        if (! ArrayHelper::accessible(Configuration::get("features.{$featureId}"))) {
            return;
        }

        if (is_null($featureFlag->getValue()) || is_null($featureFlag->getValue()->getBoolValue())) {
            return;
        }

        Configuration::set("features.{$featureId}.enabled", $featureFlag->getValue()->getBoolValue());
    }
}