gcworld / common
GCWorld Industries Common
Requires
- php: >=8.4
- ext-pdo: *
- ext-redis: *
- gcworld/database: ^2.7.6
- gcworld/errorhandlers: ^1.2.0
- gcworld/interfaces: >=4.4.12
- symfony/yaml: ^6.0
Requires (Dev)
- gcworld/code_sniffer_contrib: ^1.0
- phpmd/phpmd: ^2.8.1
- phpstan/phpstan: ^1.9
- dev-master
- 2.7.20
- 2.7.19
- 2.7.18
- 2.7.17
- 2.7.16
- 2.7.15
- 2.7.14
- 2.7.13
- 2.7.12
- 2.7.11
- 2.7.10
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1.1
- 2.3.1
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.2
- 1.2.1
- 1.2.0.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.8
- 1.0.7.1
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.0.0.1
This package is auto-updated.
Last update: 2026-05-28 13:16:49 UTC
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.20