# solid-performance/1.1.0/src/Performance/Config/Provider.php

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

- Page: https://pluginprobe.com/plugins/solid-performance/1.1.0/code/src/Performance/Config/Provider.php
- Raw: https://pluginprobe.com/plugins/solid-performance/1.1.0/raw/src/Performance/Config/Provider.php
- Modified: 2024-09-03T15:51:20+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.1.0/code/src/Performance/Config/Provider.php#L10-L20`.

```php
<?php
/**
 * The provider responsible for registering Config classes with the container & WordPress.
 *
 * @since 0.1.0
 *
 * @package SolidWP\Performance
 */

namespace SolidWP\Performance\Config;

use SolidWP\Performance\Contracts\Service_Provider;
use SolidWP\Performance\StellarWP\Arrays\Arr;

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

/**
 * The class for registering Config classes with the container & WordPress.
 *
 * @since 0.1.0
 *
 * @package SolidWP\Performance
 */
class Provider extends Service_Provider {

	/**
	 * {@inheritdoc}
	 */
	public function register(): void {
		$this->container->when( Advanced_Cache::class )
						->needs( '$template_file' )
						->give( '/src/views/cache/advanced-cache.php' );

		swpsp_register_config();

		$this->register_actions();
	}

	/**
	 * {@inheritdoc}
	 */
	public function register_actions(): void {
		$option_key = Config::OPTION_KEY;

		add_action( "update_option_{$option_key}", [ $this, 'save_via_config' ], 10, 2 );
		add_action( "update_site_option_{$option_key}", [ $this, 'save_via_config' ], 10, 2 );
	}

	/**
	 * Saves the option updates using the Config architecture.
	 *
	 * @since 0.1.0
	 *
	 * @param mixed $old_value The value being updated.
	 * @param mixed $new_value The new values to update.
	 *
	 * @return void
	 */
	public function save_via_config( $old_value, $new_value ) {
		$changes = Arr::dot( $new_value );

		foreach ( $changes as $key => $value ) {
			$this->container->get( Config::class )->set( $key, $value );
		}

		$this->container->get( Config::class )->save();
	}
}

```
