{"id":20910014,"url":"https://github.com/puzzle-org/configuration","last_synced_at":"2025-05-13T07:31:27.088Z","repository":{"id":11912193,"uuid":"14477141","full_name":"puzzle-org/configuration","owner":"puzzle-org","description":"Configuration as a service","archived":false,"fork":false,"pushed_at":"2023-03-28T07:08:09.000Z","size":71,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-22T20:18:19.508Z","etag":null,"topics":["configuration","library","oop","php","yaml"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puzzle-org.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2013-11-17T22:58:15.000Z","updated_at":"2023-03-28T07:07:47.000Z","dependencies_parsed_at":"2024-06-19T01:44:15.178Z","dependency_job_id":null,"html_url":"https://github.com/puzzle-org/configuration","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzle-org%2Fconfiguration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzle-org%2Fconfiguration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzle-org%2Fconfiguration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puzzle-org%2Fconfiguration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puzzle-org","download_url":"https://codeload.github.com/puzzle-org/configuration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225187980,"owners_count":17434980,"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":["configuration","library","oop","php","yaml"],"created_at":"2024-11-18T14:13:38.295Z","updated_at":"2025-05-13T07:31:27.082Z","avatar_url":"https://github.com/puzzle-org.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Puzzle-configuration ![PHP \u003e= 5.6](https://img.shields.io/badge/php-%3E%3D%205.6-blue.svg)\n====================\n\nHide configuration implementation behind common interface. \n\nSome advantages :\n* Application does not depend upon configuration implementation details \n* Application does not have to manage filesystem issues (for filesystem based implementations)\n* Application can be easily tested, even for configuration edge cases (missing or wrong configuration values)\n* Define configuration as a service in your dependency injection container\n\nQA\n--\n\n\nService | Result\n--- | ---\n**CI** | [![CI](https://github.com/puzzle-org/configuration/actions/workflows/ci.yml/badge.svg)](https://github.com/puzzle-org/configuration/actions/workflows/ci.yml)\n**Packagist** | [![Latest Stable Version](https://poser.pugx.org/puzzle/configuration/v/stable.png)](https://packagist.org/packages/puzzle/configuration) [![Total Downloads](https://poser.pugx.org/puzzle/configuration/downloads.svg)](https://packagist.org/packages/puzzle/configuration)\n\nInstallation\n------------\nUse composer :\n```json\n{\n    \"require\": {\n            \"puzzle/configuration\" : \"~8.3\"\n    }\n}\n```\n\n_PHP 8.0 \u0026 8.1 users please use puzzle/configuration 5.x_\n\n_PHP 7.x users please use puzzle/configuration 4.x_\n\n_PHP 5.6 users please use puzzle/configuration 3.x_\n\nDocumentation\n-------------\n\n### Configuration as a service ###\n\n\n```php\n\u003c?php\n\nclass Example\n{\n    public function __construct(Puzzle\\Configuration $config)\n    {\n        $threshold = $config-\u003eread('app/detection/threshold');\n    }\n}\n```\n\nThe way the configuration value is read depends on the chosen implementation.\n\nUp to now, 2 implementations are provided :\n* Memory (for unit testing purpose)\n* Yaml (based on Symfony/Yaml). \n\nFor YAML one, ```'app/detection/threshold'``` means ```detection[thresold]``` in app.yml file. \nWhen you instanciate YamlConfiguration object, you need to provide where yaml files can be found : \n\n```php\n\u003c?php\n\n$fileSystem = new Gaufrette\\Filesystem(\n    new Local('path/to/yaml/files/root/dir')\n);\n$config = new Puzzle\\Configuration\\Yaml($fileSystem);\n\n$example = new Example($config);\n\n```\n\n```yaml\n# app.yml \n\ndetection:\n  threshold: 3\n```\n\n### Unit testing ###\n\n```php\n\u003c?php\n\n$config = new Puzzle\\Configuration\\Memory(array(\n    'app/detection/threshold' =\u003e 2\n);\n\n$example = new ExampleTest($config);\n\n```\n\n### Default values ###\n\n```php\n\u003c?php\n\n$configuration-\u003eread('a/b/c', 'default value if a/b/c does not exist');\n```\n\nBut if ```a/b/c``` is required :\n\n```php\n\u003c?php\n\n// will throw an exception if a/b/c does not exist\n$configuration-\u003ereadRequired('a/b/c');\n```\n\n### Fallback strategy ###\n\n```php\n\u003c?php\n\n// Since 1.5.0\n// returns value associated to first existing key\n// will throw an exception if none exist\n$configuration-\u003ereadFirstExisting('a/b/c', 'd/e/f', 'x/y/z');\n```\n\n### Override configuration ###\n\nIf you need some configuration to (partially or not) override another one :\n```php\n\u003c?php\n\n// Since 1.6.0\n$defaultFileSystem = new Gaufrette\\Filesystem(\n    new Local('path/to/yaml/files/root/dir')\n);\n$defaultConfig = new Puzzle\\Configuration\\Yaml($defaultFileSystem);\n\n$fileSystem = new Gaufrette\\Filesystem(\n    new Local('path/to/another/config/files')\n);\n$localConfig = new Puzzle\\Configuration\\Yaml($fileSystem);\n\n$config = new Puzzle\\Configuration\\Stacked();\n$config-\u003eoverrideBy($defaultConfig)\n       -\u003eoverrideBy($localConfig);\n\n// values will be read in localConfig first. They will be read in default config only if they don't exist in local one.\n```\n\nAnother example : \n```php\n\u003c?php\n\n$fileSystem = new Gaufrette\\Filesystem(\n    new Local('path/to/yaml/files/root/dir')\n);\n$defaultConfig = new Puzzle\\Configuration\\Yaml($fileSystem);\n\n$overrideConfig = new Puzzle\\Configuration\\Memory(array(\n    'app/detection/threshold' =\u003e 2\n);\n\n$config = new Puzzle\\Configuration\\Stacked();\n$config-\u003eoverrideBy($defaultConfig)\n       -\u003eoverrideBy($overrideConfig);\n```\nYou can add as many as configuration instances you want in the stack. The last inserted is the most prioritary.\n\nIf you want to add the least prioritary, use the ```addBase()``` method :\n```php\n\u003c?php\n\n// Since 2.0.0\n$config = new Puzzle\\Configuration\\Stacked();\n$config-\u003eoverrideBy($overrideConfig)\n       -\u003eaddBase($defaultConfig);\n```\n\n### Prefixed configuration ###\n\nYou can use automatic prefix decorator ```PrefixedConfiguration```. It can be useful for \"namespace like\" configurations such as loggers or multiple databases ones.\n\n```yaml\n# logger.yml \n\napp:\n  filename: app.log\n  verbosity: INFO\nusers:\n  filename: users.log\n  verbosity: WARNING\n```\n\n```php\n\u003c?php\n\n// Since 1.7.0\n$fileSystem = new Gaufrette\\Filesystem(\n    new Local('path/to/yaml/files/root/dir')\n);\n$config = new Puzzle\\Configuration\\Yaml($fileSystem);\n$config = new Puzzle\\PrefixedConfiguration($config, \"logger/$loggerName\");\n\n$filename = $config-\u003ereadRequired('filename');\n$verbosity = $config-\u003ereadRequired('verbosity');\n```\n\nChangelog\n---------\n\n**5.x --\u003e 8.3**\n\n- Drop php 8.0 \u0026 8.1 support. Minimal version is 8.3\n- Version names are now match the PHP version as the library does not need to functionaly evolve anymore\n- Get rid of Gaufrette. Own interface is provided, please implements it. A Gaufrette adapter is provided for smooth migration\n\n**4.x --\u003e 5.x**\n\n - Drop php 7 support. Minimal version is 8.0\n \n**3.x --\u003e 4.x**\n\n - Drop php 5.6 \u0026 7.0 support. Minimal version is 7.1.0\n \n **2.x --\u003e 3.x**\n\n - Drop php 5.5 support. Minimal version is 5.6.0\n \n**1.x -\u003e 2.x**\n\n - Drop php 5.4 support. Minimal version is 5.5.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzle-org%2Fconfiguration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuzzle-org%2Fconfiguration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuzzle-org%2Fconfiguration/lists"}