Download the PHP package hassankhan/config without Composer
On this page you can find all versions of the php package hassankhan/config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hassankhan/config
More information about hassankhan/config
Files in hassankhan/config
Package config
Short Description Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
License MIT
Homepage http://hassankhan.me/config/
Informations about the package config
Config
Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and strings.
Requirements
Config requires PHP 7.4+.
IMPORTANT: If you want to use YAML files or strings, require the Symfony Yaml component in your
composer.json
.
Installation
The supported way of installing Config is via Composer.
Usage
Config is designed to be very simple and straightforward to use. All you can do with it is load, get, and set.
Loading files
The Config
object can be created via the factory method load()
, or
by direct instantiation:
Files are parsed and loaded depending on the file extension or specified parser. If the parser is specified, it will be used for all files. Note that when loading multiple files, entries with duplicate keys will take on the value from the last loaded file.
When loading a directory, the path is glob
ed and files are loaded in by
name alphabetically.
Warning: Do not include untrusted configuration in PHP format. It could contain and execute malicious code.
Loading string
Configuration from string can be created via the factory method load()
or
by direct instantiation, with argument $string
set to true
:
Warning: Do not include untrusted configuration in PHP format. It could contain and execute malicious code.
Getting values
Getting values can be done in three ways. One, by using the get()
method:
The second method, is by using it like an array:
The third method, is by using the all()
method:
Setting values
Although Config supports setting values via set()
or, via the
array syntax, any changes made this way are NOT reflected back to the
source files. By design, if you need to make changes to your
configuration files, you have to do it manually.
Saving config
It is possible to save the config back to a file in any of the supported formats except PHP.
Using with default values
Sometimes in your own projects you may want to use Config for storing
application settings, without needing file I/O. You can do this by extending
the AbstractConfig
class and populating the getDefaults()
method:
Merging instances
You may want merging multiple Config instances:
Examples of supported configuration files
Examples of simple, valid configuration files can be found here.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Hassan Khan
- All Contributors
License
The MIT License (MIT). Please see License File for more information.