gcworld/common
最新稳定版本:2.7.19
Composer 安装命令:
composer require gcworld/common
包简介
GCWorld Industries Common
README 文档
README
gcworld/common is the shared base library used to build GCWorld applications around a single project-level service object. It provides a common singleton pattern, YAML-backed configuration loading, lazy database and Redis connections, path helpers, and version lookup helpers for both the library and the consuming project.
What It Provides
- An abstract
Commonbase class implementing the shared project service container pattern - YAML configuration loading through
CommonConfig - Optional cached config compilation to a neighboring
.phpfile - Lazy MySQL connection management through
gcworld/database - Lazy Redis and Redis Cluster connection management
- File path and web path helpers from config
- Library and project version discovery
Requirements
- PHP
>=8.4 ext-pdoext-redis
Installation
composer require gcworld/common
Usage
Create a project-specific class that extends GCWorld\Common\Common and implements getEnvironment().
<?php namespace App; use GCWorld\Common\Common; use GCWorld\Interfaces\CommonEnvironmentEnumInterface; final class AppCommon extends Common { protected ?string $configPath = '/path/to/config/config.yml'; public function getEnvironment(): CommonEnvironmentEnumInterface { return AppEnvironment::LOCAL; } }
Then resolve shared services from the singleton instance:
$common = AppCommon::getInstance(); $config = $common->getConfig('server'); $db = $common->getDatabase(); $cache = $common->getCache(); $tempPath = $common->getDirectory('temp'); $baseUrl = $common->getPath('base');
Configuration
CommonConfig loads a YAML file and can automatically search upward for config/config.yml if no explicit path is provided.
The sample config in config/config.example.yml shows the expected sections:
database: named MySQL connections, including alias support and SSL optionscache: standalone Redis or Redis Cluster definitionspaths.file: filesystem paths such asroot,temp, andprivatepaths.web: web-facing paths such asbase,temp, andasset_cachecommon.sort: optional key sorting and write-back of the YAML filecommon.resolve_hosts: optional hostname resolution forhostentries
Included config files are also supported through the YAML includes section.
Behavior Notes
- Database and cache connections are created on first use and cached per instance name.
- Redis cache instances support an
instance:identifiersuffix for distinct persistent connections. getProjectVersion()looks for aVERSIONfile in the consuming project and falls back toCOMMON-ONLY:<common version>when used standalone.getCommonVersion()reads this library'sVERSIONfile.
Version
2.7.19
统计信息
- 总下载量: 31.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2016-03-30