| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global functions that provide access to the plugin configuration. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
use SolidWP\Performance\Config\Config; |
| 11 |
use SolidWP\Performance\Config\Strategies\Network; |
| 12 |
use SolidWP\Performance\Config\Strategies\Network_File; |
| 13 |
use SolidWP\Performance\Config\Strategies\Pipeline; |
| 14 |
use SolidWP\Performance\Config\Strategies\Site; |
| 15 |
use SolidWP\Performance\Config\Strategies\Site_File; |
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Returns the config that is created from a set of defaults, site settings, and network settings. |
| 23 |
* |
| 24 |
* @since 0.1.0 |
| 25 |
* |
| 26 |
* @param string $key The key to retrieve from the config in dot notation. |
| 27 |
* |
| 28 |
* @return mixed |
| 29 |
*/ |
| 30 |
function swpsp_config_get( string $key ) { |
| 31 |
$config = swpsp_register_config(); |
| 32 |
return $config->get( $key ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns a registered instance of config with all the necessary strategies. |
| 37 |
* |
| 38 |
* @since 0.1.0 |
| 39 |
* |
| 40 |
* @return Config |
| 41 |
*/ |
| 42 |
function swpsp_register_config() { |
| 43 |
// Temporary fix for out of sync advanced-cache.php until that feature is released: PR 109. |
| 44 |
if ( ! function_exists( 'swpsp_plugin' ) ) { |
| 45 |
require_once __DIR__ . '/app.php'; |
| 46 |
} |
| 47 |
|
| 48 |
$container = swpsp_plugin()->container(); |
| 49 |
|
| 50 |
if ( $container->isBound( Config::class ) ) { |
| 51 |
return $container->get( Config::class ); |
| 52 |
} |
| 53 |
|
| 54 |
$pipeline = new Pipeline( $container ); |
| 55 |
$pipeline->pipes( |
| 56 |
[ |
| 57 |
Site::class, |
| 58 |
Site_File::class, |
| 59 |
] |
| 60 |
); |
| 61 |
|
| 62 |
if ( is_multisite() ) { |
| 63 |
$pipeline->pipe( |
| 64 |
[ |
| 65 |
Network::class, |
| 66 |
Network_File::class, |
| 67 |
] |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
$config = new Config( $pipeline ); |
| 72 |
$container->bind( Config::class, $config ); |
| 73 |
|
| 74 |
return $config; |
| 75 |
} |
| 76 |
|