{"id":17061798,"url":"https://github.com/phlak/config","last_synced_at":"2025-04-10T03:54:52.996Z","repository":{"id":45177526,"uuid":"66168184","full_name":"PHLAK/Config","owner":"PHLAK","description":"PHP library for simple configuration management","archived":false,"fork":false,"pushed_at":"2024-01-01T19:24:32.000Z","size":260,"stargazers_count":54,"open_issues_count":3,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T03:54:43.805Z","etag":null,"topics":["config","config-management","ini","json","php","php-library","xml","yaml"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/phlak/config","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PHLAK.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"PHLAK","patreon":"PHLAK","custom":"https://paypal.me/ChrisKankiewicz"}},"created_at":"2016-08-20T21:09:30.000Z","updated_at":"2025-02-17T09:09:52.000Z","dependencies_parsed_at":"2022-09-07T02:52:00.850Z","dependency_job_id":"78ae7683-a807-4340-b601-baa5e395b39e","html_url":"https://github.com/PHLAK/Config","commit_stats":{"total_commits":150,"total_committers":4,"mean_commits":37.5,"dds":"0.026666666666666616","last_synced_commit":"55448430f3b926fe05467048ea050217868294d4"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FConfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FConfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FConfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PHLAK%2FConfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PHLAK","download_url":"https://codeload.github.com/PHLAK/Config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248154999,"owners_count":21056542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","config-management","ini","json","php","php-library","xml","yaml"],"created_at":"2024-10-14T10:48:13.102Z","updated_at":"2025-04-10T03:54:52.978Z","avatar_url":"https://github.com/PHLAK.png","language":"PHP","funding_links":["https://github.com/sponsors/PHLAK","https://patreon.com/PHLAK","https://paypal.me/ChrisKankiewicz"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"config.png\" alt=\"Config\" width=\"500\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PHLAK/Config/discussions\"\u003e\u003cimg src=\"https://img.shields.io/badge/Join_the-Community-7b16ff.svg?style=for-the-badge\" alt=\"Join our Community\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/users/PHLAK/sponsorship\"\u003e\u003cimg src=\"https://img.shields.io/badge/Become_a-Sponsor-cc4195.svg?style=for-the-badge\" alt=\"Become a Sponsor\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://paypal.me/ChrisKankiewicz\"\u003e\u003cimg src=\"https://img.shields.io/badge/Make_a-Donation-006bb6.svg?style=for-the-badge\" alt=\"One-time Donation\"\u003e\u003c/a\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Config\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/PHLAK/Config.svg?style=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Config\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/PHLAK/Config.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/PHLAK/Config\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/PHLAK/Config.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/PHLAK/Config/actions/workflows/test-suite.yaml\" alt=\"CI Status\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/PHLAK/Config/test-suite.yaml?style=flat-square\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    PHP library for simple configuration management\n    -- Created by \u003ca href=\"https://www.ChrisKankiewicz.com\"\u003eChris Kankiewicz\u003c/a\u003e\n    (\u003ca href=\"https://twitter.com/PHLAK\"\u003e@PHLAK\u003c/a\u003e)\n\u003c/p\u003e\n\n---\n\nIntroduction\n------------\n\nConfig is a simple PHP configuration management library supporting multiple\nconfiguration file formats and an expressive API.\n\nSupported file formats:\n\n  - PHP\n  - INI\n  - JSON\n  - [TOML](https://github.com/toml-lang/toml)\n  - YAML\n  - XML\n\nRequirements\n------------\n\n  - [PHP](https://php.net) \u003e= 7.1\n\nInstall with Composer\n---------------------\n\n```bash\ncomposer require phlak/config\n```\n\nInitializing the Client\n-----------------------\n\nFirst, import Config:\n\n```php\nuse PHLAK\\Config\\Config;\n```\n\nThen instantiate the class:\n\n```php\n$config = new Config($context, $prefix = null);\n```\n\nWhere `$context` is one of the following:\n\n  - A path to a supported file type\n  - A directory path containing one or more supported file types\n  - An array of configuration options\n\nAnd `$prefix` is a string to be used as a key prefix for options of this Config object.\n\nConfiguration File Formats\n--------------------------\n\n### PHP\n\nA PHP configuration file must have the `.php` file extension, be a valid PHP\nfile and and return a valid PHP array.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample PHP file\u003c/summary\u003e\n\n  ```php\n  \u003c?php\n  \n  return [\n      'driver' =\u003e 'mysql',\n      'drivers' =\u003e [\n          'sqlite' =\u003e [\n              'database' =\u003e 'database.sqlite',\n              'prefix' =\u003e ''\n          ],\n          'mysql' =\u003e [\n              'host' =\u003e 'localhost',\n              'database' =\u003e 'blog',\n              'username' =\u003e 'blogger',\n              'password' =\u003e 'hunter2',\n              'charset' =\u003e 'utf8',\n              'prefix' =\u003e ''\n          ]\n      ]\n  ];\n  ```\n\u003c/details\u003e\n\n### INI\n\nAn INI configuration file must have the `.ini` file extension and be a valid INI\nfile.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample INI file\u003c/summary\u003e\n\n  ```ini\n  driver = mysql\n  \n  [drivers]\n  \n  sqlite[database] =  database.sqlite\n  sqlite[prefix] =\n  \n  mysql[host] = localhost\n  mysql[database] = blog\n  mysql[username] = blogger\n  mysql[password] = hunter2\n  mysql[charset] = utf8\n  mysql[prefix] =\n  ```\n\u003c/details\u003e\n\n### JSON\n\nA JSON configuration file must have the `.json` file extension and contain a\nvalid JSON object.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample JSON file\u003c/summary\u003e\n\n  ```json\n  {\n      \"driver\": \"mysql\",\n      \"drivers\": {\n          \"sqlite\": {\n              \"database\": \"database.sqlite\",\n              \"prefix\": \"\"\n          },\n          \"mysql\": {\n              \"host\": \"localhost\",\n              \"database\": \"blog\",\n              \"username\": \"blogger\",\n              \"password\": \"hunter2\",\n              \"charset\": \"utf8\",\n              \"prefix\": \"\"\n          }\n      }\n  }\n  ```\n\u003c/details\u003e\n\n### TOML\n\nA TOML configuration file must have the `.toml` file extension and be a valid\nTOML file.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample TOML file\u003c/summary\u003e\n\n  ```toml\n  driver = 'mysql'\n  \n  [drivers.sqlite]\n  database = 'database.sqlite'\n  prefix = ''\n  \n  [drivers.mysql]\n  host = 'localhost'\n  database = 'blog'\n  username = 'blogger'\n  password = 'hunter2'\n  charset = 'utf8'\n  prefix = ''\n  ```\n\u003c/details\u003e\n\n### YAML\n\nA YAML configuration file must have the `.yaml` file extension, be a valid YAML\nfile.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample YAML file\u003c/summary\u003e\n\n  ```yaml\n  driver: mysql\n  \n  drivers:\n  \n    sqlite:\n      database: database.sqlite\n      prefix:\n  \n    mysql:\n      host: localhost\n      database: blog\n      username: blogger\n      password: hunter2\n      charset: utf8\n      prefix:\n  ```\n\u003c/details\u003e\n\n### XML\n\nA XML configuration file must have the `.xml` file extension and contain valid\nXML.\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample XML file\u003c/summary\u003e\n\n  ```xml\n  \u003c?xml version='1.0'?\u003e\n  \n  \u003cdatabase\u003e\n      \u003cdriver\u003emysql\u003c/driver\u003e\n      \u003cdrivers\u003e\n          \u003csqlite\u003e\n              \u003cdatabase\u003edatabase.sqlite\u003c/database\u003e\n              \u003cprefix\u003e\u003c/prefix\u003e\n          \u003c/sqlite\u003e\n          \u003cmysql\u003e\n              \u003chost\u003elocalhost\u003c/host\u003e\n              \u003cdatabase\u003eblog\u003c/database\u003e\n              \u003cusername\u003eblogger\u003c/username\u003e\n              \u003cpassword\u003ehunter2\u003c/password\u003e\n              \u003ccharset\u003eutf8\u003c/charset\u003e\n              \u003cprefix\u003e\u003c/prefix\u003e\n          \u003c/mysql\u003e\n      \u003c/drivers\u003e\n  \u003c/database\u003e\n  ```\n\u003c/details\u003e\n\nUsage\n-----\n\n### __construct\n\u003e Create a new Config object.\n\n```php\nConfig::__construct( mixed $context [, string $prefix = null ] ) : Config\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$context\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eRaw array of configuration options or path to a configuration file or directory containing one or more configuration files\u003c/dd\u003e  \n  \n  \u003cdt\u003e\u003ccode\u003e$prefix\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eA key under which the loaded config will be nested\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Examples\n\nCreate a new Config object from a YAML file.\n\n```php\n$config = new Config('path/to/conifg.yaml');\n```\n\nCreate a new Config object from a directory of config files.\n\n```php\n$config = new Config('path/to/conifgs/');\n```\n\nCreate a new Config object from an array.\n\n```php\n$config = new Config([\n    'hostname' =\u003e 'localhost',\n    'port' =\u003e 12345\n]);\n```\n\n---\n\n### set\n\u003e Store a config value with a specified key.\n\n```php\nConfig::set( string $key, mixed $value ) : bool\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$value\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eConfig item value\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\n```php\n$config-\u003eset('hostname', 'localhost');\n$config-\u003eset('port', 12345);\n```\n\n---\n\n### get\n\u003e Retrieve a configuration option via a provided key.\n\n```php\nConfig::get( string $key [, mixed $default = null ] ) : mixed\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$value\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eConfig item value\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Examples\n\n```php\n// Return the hostname option value or null if not found.\n$config-\u003eget('hostname');\n```\n\nDefine a default value to return if the option is not set.\n\n```php\n// Returns 'localhost' if hostname option is not set\n$config-\u003eget('hostname', 'localhost');\n```\n\n---\n\n### has\n\u003e Check for the existence of a configuration item.\n\n```php\nConfig::has( string $key ) : bool\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\n```php\n$config = new Config([\n    'hostname' =\u003e 'localhost'\n]);\n\n$config-\u003ehas('hostname'); // Returns true\n$config-\u003ehas('port');     // Returns false\n```\n\n---\n\n### append\n\u003e Append a value onto an existing array configuration option.\n\n```php\nConfig::append( string $key, mixed $value ) : bool\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$value\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eConfig item value\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\nAppend `baz` to the `tags` config item array.\n\n```php\n$config-\u003eset('tags', ['foo', 'bar'])\n$config-\u003eappend('tags', 'baz'); // ['foo', 'bar', 'baz']\n```\n\n---\n\n### prepend\n\u003e Prepend a value onto an existing array configuration option.\n\n```php\nConfig::append( string $key, mixed $value ) : bool\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$value\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eConfig item value\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\nPrepend `baz` to the `tags` config item array.\n\n```php\n$config-\u003eset('tags', ['foo', 'bar'])\n$config-\u003eappend('tags', 'baz'); // ['baz', 'foo', 'bar']\n```\n\n---\n\n### unset\n\u003e Unset a configuration option via a provided key.\n\n```php\nConfig::unset( string $key ) : bool\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\n```php\n$config-\u003eunset('hostname');\n```\n\n---\n\n### load\n\u003e Load configuration options from a file or directory.\n\n```php\nConfig::load( string $path [, string $prefix = null [, bool $override = true ]] ) : self\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$path\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003ePath to configuration file or directory\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$prefix\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eA key under which the loaded config will be nested\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$override\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eWhether or not to override existing options with values from the loaded file\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Examples\n\nLoad a single additional file.\n\n```php\n$conifg-\u003eload('path/to/config.php');\n```\n\nLoad an additional file with a prefix.\n\n```php\n$config-\u003eload('databaes.php', 'database');\n```\n\nLoad an additional file without overriding existing values.\n\n```php\n$config-\u003eload('additional-options.php', null, false);\n```\n\n---\n\n### merge\n\u003e Merge another Config object into this one.\n\n```php\nConfig::merge( Config $config [, bool $override = true ] ) : self\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$config\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eInstance of Config\u003c/dd\u003e\n  \n  \u003cdt\u003e\u003ccode\u003e$override\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eWhether or not to override existing options with values from the merged config object\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Examples\n\nMerge $anotherConfig into $config and override values in `$config` with values\nfrom `$anotherConfig`.\n\n```php\n$anotherConfig = new Config('some/config.php');\n\n$config-\u003emerge($anotherConfig);\n```\n\nMerge `$anotherConfig` into `$config` without overriding any values. Duplicate\nvalues in `$anotherConfig` will be lost.\n\n```php\n$anotherConfig = new Config('some/config.php');\n\n$config-\u003emerge($anotherConfig, false);\n```\n\n---\n\n### split\n\u003e Split a sub-array of configuration options into it's own Config object.\n\n```php\nConfig::split( string $key ) : Config\n```\n\n\u003cdl\u003e\n  \u003cdt\u003e\u003ccode\u003e$key\u003c/code\u003e\u003c/dt\u003e\n  \u003cdd\u003eUnique configuration option key\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### Example\n\n```php\n$config = new Config([\n    'foo' =\u003e 'foo',\n    'bar' =\u003e [\n        'baz' =\u003e 'barbaz'\n    ],\n]);\n\n$barConfig = $config-\u003esplit('bar');\n\n$barConfig-\u003eget('baz');  // Returns 'barbaz'\n```\n\n---\n\n### toArray\n\u003e Return the entire configuration as an array.\n\n```php\nConfig::toArray( void ) : array\n```\n\n#### Example\n\n```php\n$config = new Config(['foo' =\u003e 'foo']);\n\n$config-\u003etoArray(); // Returns ['foo' =\u003e 'foo']\n```\n\n---\n\nTroubleshooting\n---------------\n\nFor general help and support join our [GitHub Discussion](https://github.com/PHLAK/Config/discussions) or reach out on [Twitter](https://twitter.com/PHLAK).\n\nPlease report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Config/issues).\n\nCopyright\n---------\n\nThis project is liscensed under the [MIT License](https://github.com/PHLAK/Config/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlak%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphlak%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphlak%2Fconfig/lists"}