stellarwp / configuration
StellarWP Configuration Accessor
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 16
Forks: 0
Open Issues: 0
pkg:composer/stellarwp/configuration
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2025-09-13 07:31:23 UTC
README
Provides a system-wide set of configuration values. Easily access feature flags, and other immutable configurations.
Inspired by systems that load configurations from various sources, like retrieving .ini
or .env
values.
Setup
Add a configuration loader, so the system knows where to get the configuration values from.
// Constants_Provider.php class Constants_Provider implements Configuration_Provider_Interface { public function has( $key ): bool { return defined( $key ); } public function get( $key ) { if ( $this->has( $key ) ) { return constant( $key ); } return null; } public function all(): array { return get_defined_constants( false ); } }
// Provider.php class Provider { protected function register(): void { // Can add other loaders with other configuration values, such as local vs prod configurations. $loader = ( new Configuration_Loader() )->add( new Constants_Provider() ); $this->configuration = new Configuration( $loader ); } }
This is an extensible loader to allow various configuration sources and application specific logic to bind configuration providers in different ways.
Retrieve Configuration Value
// wp-config.php define('TEC_FEATURE_FLAG', true);
// Model.php public function config_magic() { // Feature enabled? if ( $this->configuration->get( 'TEC_FEATURE_FLAG' ) ) { // do stuff... } }