PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.5.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.5.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Config / Writers / Option_Writer.php

Option_Writer.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.5.0, at src/Performance/Config/Writers/Option_Writer.php

60 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Writes config items to the options table.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Config\Writers;
11
12 use RuntimeException;
13 use SolidWP\Performance\Config\Config;
14 use SolidWP\Performance\Config\Config_Loader;
15 use SolidWP\Performance\Config\Writers\Contracts\Writable;
16
17 /**
18 * Writes config items to the options table.
19 *
20 * @package SolidWP\Performance
21 */
22 final class Option_Writer implements Writable {
23
24 /**
25 * @var Config
26 */
27 private Config $config;
28
29 /**
30 * @param Config $config The config singleton.
31 */
32 public function __construct( Config $config ) {
33 $this->config = $config;
34 }
35
36 /**
37 * Writes config items to the options table.
38 *
39 * @action solidwp/performance/config/save
40 *
41 * @throws RuntimeException If trying to save before WordPress is fully bootstrapped.
42 *
43 * @return bool
44 */
45 public function save(): bool {
46 $items = $this->config->all();
47
48 if ( ! function_exists( 'update_option' ) ) {
49 throw new RuntimeException(
50 sprintf(
51 '%s::save() was called too early in the execution. Wait until plugins_loaded has fired.',
52 Config::class
53 )
54 );
55 }
56
57 return update_option( Config_Loader::OPTION_KEY, $items );
58 }
59 }
60