{"id":19483276,"url":"https://github.com/yosymfony/config-loader","last_synced_at":"2025-04-25T16:31:59.028Z","repository":{"id":18800903,"uuid":"22015005","full_name":"yosymfony/config-loader","owner":"yosymfony","description":"An agnostics configuration loader with built-in loaders for YAML, TOML and JSON.","archived":false,"fork":false,"pushed_at":"2019-04-15T09:26:10.000Z","size":68,"stargazers_count":10,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-07T10:56:50.460Z","etag":null,"topics":["config","configuration","json","php","toml","yaml"],"latest_commit_sha":null,"homepage":"","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/yosymfony.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-19T17:21:43.000Z","updated_at":"2023-11-08T06:45:01.000Z","dependencies_parsed_at":"2022-09-25T02:30:24.257Z","dependency_job_id":null,"html_url":"https://github.com/yosymfony/config-loader","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosymfony%2Fconfig-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosymfony%2Fconfig-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosymfony%2Fconfig-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yosymfony%2Fconfig-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yosymfony","download_url":"https://codeload.github.com/yosymfony/config-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224007877,"owners_count":17240294,"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","configuration","json","php","toml","yaml"],"created_at":"2024-11-10T20:14:16.172Z","updated_at":"2024-11-10T20:14:17.547Z","avatar_url":"https://github.com/yosymfony.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Config loader for PHP\n=====================\n\nAn agnostics configuration loader with built-in loaders for YAML, TOML and JSON.\n\n[![Build Status](https://travis-ci.org/yosymfony/config-loader.png?branch=master)](https://travis-ci.org/yosymfony/config-loader)\n[![Latest Stable Version](https://poser.pugx.org/yosymfony/config-loader/v/stable.png)](https://packagist.org/packages/yosymfony/config-loader)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yosymfony/Config-loader/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yosymfony/Config-loader/?branch=master)\n\nInstallation\n------------\n\n**Requires PHP \u003e= 7.2.**\n\nUse [Composer](http://getcomposer.org/) to install this package:\n\n```bash\ncomposer require yosymfony/config-loader\n```\n\nUsage\n-----\n\n### Initialization\nThe class `ConfigLoader` let you load your configuration resources. It expects a list of\nloaders in the constructor so you can pass to it only those ones you need:\n\n```php\nuse Yosymfony\\ConfigLoader\\FileLocator;\nuse Yosymfony\\ConfigLoader\\ConfigLoader;\n\n// The file locator uses an array of pre-defined paths to find files:\n$locator = new FileLocator(['/path1', '/path2']);\n\n// Set up the ConfigLoader to work with YAML and TOML configuration files:\n$config = new ConfigLoader([\n    new YamlLoader($locator),\n    new TomlLoader($locator),\n]);\n```\n\n### Available loaders\n#### Yaml loader\n  **Requires**: [Symfony YAML](https://github.com/symfony/yaml) component:\n  ```bash\n  composer require symfony/yaml\n  ```\n\n  Initialization:\n  ```php\n  $config = new ConfigLoader([\n    new YamlLoader($locator),\n  ]);\n  ```\n\n#### Toml loader\n  **Requires**: [Toml](https://github.com/yosymfony/toml) component:\n  ```bash\n  composer require yosymfony/toml\n  ```\n\n  Initialization:\n  ```php\n  $config = new ConfigLoader([\n    new TomlLoader($locator),\n  ]);\n  ```\n#### Json loader\n  Initialization:\n  ```php\n  $config = new ConfigLoader([\n    new JsonLoader($locator),\n  ]);\n  ```\n### Loading configuration files:\n\n```php\n// Search this file in \"path1\" and \"path2\":\n$config-\u003eload('user.yml');\n// or load a file using its absolute path:\n$config-\u003eload('/var/config/user1.yml');\n```\n\n#### *.dist* files\n\nThis library has support for `.dist` files. The filename is resolved following the next hierarchy:\n\n1. filename.ext\n2. filename.ext.dist (if `filename.ext` does not exist)\n\n### Loading inline configuration:\n\nTo parse inline configurations you just need to set the configuration text as first argument instead of the filename \nand set the format type as second one:\n\n```php    \n$repository = $config-\u003eload('server: \"your-name.com\"', YamlLoader::TYPE);\n```\n\n### Importing files\n\nThis library has support for importing files.\nThe example below shows a YAML file importing three files:\n\n```yaml\n---\nimports:\n  - config-imported.yml\n  - config-imported.toml\n  - config-imported.json\n```\n\nSimilar example using JSON syntax:\n\n```json\n{\n  \"imports\": [\n    \"config.json\"\n  ]\n}\n```\n\nAn example using TOML syntax:\n\n```\nimports = [\n    \"config.toml\"\n]\n```\n\nRepository\n----------\n\nA configuration file is loaded into a repository. A repository is a wrapper\nthat implements the [ArrayAccess interface](http://php.net/manual/en/class.arrayaccess.php) and exposes methods for working\nwith configuration values.\n\n```php\n// Returns the value associeted with key \"name\" or the default value in case not found\n$repository-\u003eget('name', 'default');\n\n// Do the same that the previous sentence but using array notation\n$repository['name'];\n```\n\n### Operations\n\n#### Unions\n\nYou can performs the union of a repository A with another B into C as result:\n\n```php\n$resultC = $repositoryA-\u003eunion($repositoryB);\n```\n\nThe values of `$repositoryB` have less priority than values in `$repositoryA`.\n\n#### Intersections\n\nYou can performs the intersection of a repository A with another B into C as result:\n```php\n$resultC = $repositoryA-\u003eintersection($repositoryB);\n```\n\nThe values of `$repositoryB` have less priority than values in `$repositoryA`.\n\n### Creating a blank repository\n\nCreating a blank repository is too easy. You just need to create a instance of\na `Repository` class:\n\n```php\nuse Yosymfony\\Config-loader\\Repository;\n\n//...\n\n$repository = new Repository([\n  'name' =\u003e 'Yo! Symfony',\n]);\n\n$repository-\u003eset('server', 'your-name.com');\n```\n\nUnit tests\n----------\n\nYou can run the unit tests with the following command:\n\n```bash\n$ cd toml\n$ composer test\n```\n\nLicense\n-------\n\nThis library is open-sourced software licensed under the\n[MIT license](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosymfony%2Fconfig-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyosymfony%2Fconfig-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosymfony%2Fconfig-loader/lists"}