use Cognesy\Config\ConfigEntry;// Returned by Config::load() and ConfigLoader::load()$entry->key(); // string — dot-notation key derived from file path$entry->sourcePath(); // string — absolute path to the source file$entry->toArray(); // array — the resolved config data
use Cognesy\Config\Env;// Get an environment variable (checks getenv, $_ENV, $_SERVER)$value = Env::get('API_KEY');$value = Env::get('API_KEY', 'default-value');// Configure .env file paths and namesEnv::set('/path/to/project');Env::set(['/path1', '/path2'], ['.env', '.env.local']);// Force reloadEnv::load();
EnvTemplate — resolve ${VAR} placeholders in config data¶
use Cognesy\Config\EnvTemplate;$template = new EnvTemplate();// Resolve placeholders in nested arrays$resolved = $template->resolveData([ 'key' => '${API_KEY}', 'url' => '${BASE_URL:-https://default.example.com}',]);// Resolve a single string$resolved = $template->resolveString('Bearer ${TOKEN}');// Resolve a single value (string, array, or passthrough)$resolved = $template->resolveValue($value);// Supported placeholder syntax:// ${VAR} — value of VAR, empty string if unset// ${VAR:-default} — value of VAR, or "default" if unset/empty// ${VAR?} — value of VAR, throws if unset/empty// ${VAR:?message} — value of VAR, throws with message if unset/empty
use Cognesy\Config\BasePath;// Get/resolve the application base path$base = BasePath::get();$base = BasePath::get('config/app.yaml'); // appends relative path$base = BasePath::resolve('config/app.yaml'); // get() is an alias for resolve()// Resolve multiple paths, returning only those that exist$paths = BasePath::all('config', 'resources/config'); // alias for resolveExisting()$paths = BasePath::resolveExisting('config', 'resources/config');// Resolve the first existing path (throws if none exist)$path = BasePath::resolveFirst('config', 'resources/config');// Manually set the base pathBasePath::set('/absolute/path/to/project');// Customize detection method orderBasePath::setDetectionMethods([ 'getBasePathFromEnv', 'getBasePathFromCwd', 'getBasePathFromComposer', 'getBasePathFromServerVars', 'getBasePathFromReflection', 'getBasePathFromFrameworkPatterns',]);
ConfigKey — derive dot-notation keys from file paths¶
use Cognesy\Config\ConfigKey;// Convert a file path to a dot-notation config key// Strips config/ prefix and file extension$key = ConfigKey::fromPath('/app/config/llm/presets/openai.yaml'); // "llm.presets.openai"
ConfigFileSet — ordered collection of config files¶
use Cognesy\Config\ConfigFileSet;// Create from file paths (keys auto-derived via ConfigKey)$fileSet = ConfigFileSet::fromFiles('/path/to/config/a.yaml', '/path/to/config/b.yaml');// Create with explicit keys$fileSet = ConfigFileSet::fromKeyedFiles([ 'llm.openai' => '/path/to/openai.yaml', 'http.curl' => '/path/to/curl.yaml',]);$fileSet->all(); // array<int, string> — file paths$fileSet->keys(); // array<int, string> — config keys$fileSet->keyFor('/path/to/file'); // string — key for a specific file$fileSet->count(); // int$fileSet->isEmpty(); // bool$fileSet->filesHash(); // string — SHA-256 content hash
ConfigBootstrap — build nested config graph from a file set¶
use Cognesy\Config\ConfigBootstrap;use Cognesy\Config\ConfigFileSet;$bootstrap = new ConfigBootstrap();$graph = $bootstrap->bootstrap($fileSet); // array<string, mixed>
ConfigCacheCompiler — compile config graph to a PHP cache file¶
use Cognesy\Config\ConfigCacheCompiler;$compiler = new ConfigCacheCompiler();$compiler->compile( cachePath: '/path/to/cache.php', fileSet: $fileSet, config: $graph, env: ['APP_ENV' => 'production'], // optional schemaVersion: 1, // optional generatedAt: null, // optional, defaults to current time);
use Cognesy\Config\ConfigValidator;// No validation (passthrough)$validator = new ConfigValidator();// With Symfony ConfigurationInterface$validator = new ConfigValidator($configurationInstance);// With callable$validator = new ConfigValidator(fn(array $config) => $config);$validated = $validator->validate($configArray);
CanProvideConfig — interface for config providers¶
use Cognesy\Config\Contracts\CanProvideConfig;// Interface with two methods:// get(string $path, mixed $default = null): mixed// has(string $path): bool