定制 stellarwp/configuration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stellarwp/configuration

Composer 安装命令:

composer require stellarwp/configuration

包简介

StellarWP Configuration Accessor

README 文档

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...
	}
}

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 16
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-01-13