# solid-performance/1.3.0/src/Performance/Config/Config_Loader.php

Solid Performance – Your No-Code Caching, Performance, &amp; Page Speed Solution, version 1.3.0. 99 lines.

- Page: https://pluginprobe.com/plugins/solid-performance/1.3.0/code/src/Performance/Config/Config_Loader.php
- Raw: https://pluginprobe.com/plugins/solid-performance/1.3.0/raw/src/Performance/Config/Config_Loader.php
- Modified: 2024-09-17T15:49:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/solid-performance/1.3.0/code/src/Performance/Config/Config_Loader.php#L10-L20`.

```php
<?php
/**
 * Responsible for loading configuration items from different locations.
 *
 * @note    When the request begins at advanced-cache.php, the database is not yet available, and we rely on the file based
 *          configuration.
 *
 * @package SolidWP\Performance
 */

declare( strict_types=1 );

namespace SolidWP\Performance\Config;

use SolidWP\Performance\StellarWP\Arrays\Arr;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Responsible for loading configuration items from different locations.
 *
 * @note    When the request begins at advanced-cache.php, the database is not yet available, and we rely on the file based
 *          configuration.
 *
 * @package SolidWP\Performance
 */
final class Config_Loader {

	public const OPTION_KEY = 'solid_performance_settings';

	/**
	 * The default config items.
	 *
	 * @var Default_Config
	 */
	private Default_Config $default_config;

	/**
	 * The config file dir/location.
	 *
	 * @var Config_File
	 */
	private Config_File $config_file;

	/**
	 * @param  Default_Config $default_config The default config items.
	 * @param  Config_File    $config_file The config file dir/location.
	 */
	public function __construct( Default_Config $default_config, Config_File $config_file ) {
		$this->default_config = $default_config;
		$this->config_file    = $config_file;
	}

	/**
	 * Fetches config items from multiple sources, merging them based on precedence.
	 *
	 * @return array<string, mixed>
	 */
	public function load(): array {
		$merge_items = [];

		// This file is the only source available when advanced-cache.php is loaded.
		if ( file_exists( $this->config_file->get() ) ) {
			$merge_items[] = require $this->config_file->get();
		}

		// Fetch the network configuration. Note: we currently have no true MS support/settings page etc...this is just for the future.
		if ( function_exists( 'get_network_option' ) && is_multisite() ) {
			$merge_items[] = (array) get_network_option( get_main_network_id(), self::OPTION_KEY, [] );
		}

		// Allow local sites to override the network configuration.
		if ( function_exists( 'get_option' ) ) {
			$merge_items[] = (array) get_option( self::OPTION_KEY, [] );
		}

		return $this->merge_configs( ...$merge_items );
	}

	/**
	 * Merge configuration items, starting with the default configuration.
	 *
	 * @param  array<string, mixed> ...$configs The different config sources.
	 *
	 * @return array
	 */
	private function merge_configs( array ...$configs ): array {
		$merged = $this->default_config->get();

		foreach ( $configs as $config ) {
			$merged = Arr::merge_recursive( $merged, $config );
		}

		return $merged;
	}
}

```
