joomla/registry
Key-value registry and configuration store for PHP. Load data from strings, files, arrays, or objects; access and modify values with getters/setters and dot-paths for nested keys; remove entries; ArrayAccess support; import/export across formats like JSON and XML.
Start by installing the package via Composer with composer require joomla/registry "^4.0", ensuring you meet the minimum PHP 8.3 requirement. The Registry class is the core interface—create instances with new Registry($data) where $data can be a string (JSON/XML/YAML/INI), array, or object. For immediate use, load config from files or strings:
$registry = new Registry();
$registry->loadFile('config.json'); // default JSON format
$registry->loadString('<root><node name="key">value</node></root>', 'xml');
Then access values using dot-notation paths like $registry->get('parent.child.key') or via array syntax ($registry['parent']['child']['key']). The fastest first use case: replacing a hardcoded config array with a JSON file and using loadFile() for centralized configuration management.
Registry instance (not a true singleton—create per-request), e.g., $registry->loadFile(__DIR__ . '/config/app.yaml') and access via $registry->get('database.host').load*() calls to merge configs (later loads override earlier) or use merge($otherRegistry) for structured overrides—e.g., merge base config + environment-specific overrides (config.json + config.local.json).flatten() for simple iteration (returns ['nested.key' => 'value']) or iterate directly via ArrayAccess.loadObject($typedObject) or loadArray($typedArray).FormatInterface for bespoke formats (e.g., TOML) and register via Factory::getFormat('toml', ['format_namespace' => 'App\\Format']).'parent.child') for paths—set('parent.child', $val) expects dot-delimited strings, not arrays. Avoid mixing array access with dot paths in the same workflow to prevent confusion.<node name="..."> structure; misformatted XML (e.g., missing name attributes) causes silent failures. Use loadString($xml, 'xml', ['nodeName' => 'custom']) to customize element names.merge($source) is recursive by default; pass false for flat (only top-level) merging. Verify behavior with print_r($registry->toArray()) after merging."false" as string in INI) may still coerce—test edge cases like empty strings vs null.set()/loadArray() and strict string input for stringToObject().Registry has no getInstance()—each instance is standalone. Avoid repeated file loads in tight loops; cache parsed data externally if performance-critical.How can I help you explore Laravel packages today?