{"id":15025431,"url":"https://github.com/tomwright/phpconfig","last_synced_at":"2025-10-17T14:07:05.277Z","repository":{"id":57071545,"uuid":"73421249","full_name":"TomWright/PHPConfig","owner":"TomWright","description":"A quick and easy Config package designed to pass around a set of values, accessible anywhere in an application.","archived":false,"fork":false,"pushed_at":"2017-11-22T22:54:51.000Z","size":41,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T20:04:04.543Z","etag":null,"topics":["config","php","php-7"],"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/TomWright.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}},"created_at":"2016-11-10T21:12:05.000Z","updated_at":"2020-08-29T07:09:52.000Z","dependencies_parsed_at":"2022-08-24T14:54:28.361Z","dependency_job_id":null,"html_url":"https://github.com/TomWright/PHPConfig","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomWright%2FPHPConfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomWright%2FPHPConfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomWright%2FPHPConfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomWright%2FPHPConfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomWright","download_url":"https://codeload.github.com/TomWright/PHPConfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"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","php","php-7"],"created_at":"2024-09-24T20:02:19.803Z","updated_at":"2025-10-17T14:07:05.186Z","avatar_url":"https://github.com/TomWright.png","language":"PHP","readme":"# Config\n\n[![Build Status](https://travis-ci.org/TomWright/PHPConfig.svg?branch=master)](https://travis-ci.org/TomWright/PHPConfig)\n[![Test Coverage](https://codeclimate.com/github/TomWright/PHPConfig/badges/coverage.svg)](https://codeclimate.com/github/TomWright/PHPConfig/coverage)\n[![Latest Stable Version](https://poser.pugx.org/tomwright/php-config/v/stable)](https://packagist.org/packages/tomwright/php-config)\n[![Total Downloads](https://poser.pugx.org/tomwright/php-config/downloads)](https://packagist.org/packages/tomwright/php-config)\n[![Monthly Downloads](https://poser.pugx.org/tomwright/php-config/d/monthly)](https://packagist.org/packages/tomwright/php-config)\n[![Daily Downloads](https://poser.pugx.org/tomwright/php-config/d/daily)](https://packagist.org/packages/tomwright/php-config)\n[![License](https://poser.pugx.org/tomwright/php-config/license.svg)](https://packagist.org/packages/tomwright/php-config)\n\n## Installation\n\n```\ncomposer require tomwright/php-config\n```\n\n## General Usage\n\nCreate an instance of `Config` to get going:\n```php\n$config = new Config();\n```\n\n### Add values to the config as follows\n```php\n$config-\u003eput('key', 'value');\n```\n\n### Get values from the config as follows\n```php\n$value = $config-\u003eget('key');\n```\n\n## Storing Data\nYou can add separators to the `key` string in order to have the data stored slightly differently.\n\nFor example, let's say we have a contact name and email address. You can set this in any of the following ways:\n\n```php\n$config-\u003eput('contact', [\n    'name' =\u003e 'Tom',\n    'email' =\u003e 'contact@tomwright.me',\n]);\n\n$config-\u003eput('contact.name', 'Tom');\n$config-\u003eput('contact.email', 'contact@tomwright.me');\n```\n\nYou can even mix and match between the above:\n\n```php\n$config-\u003eput('contact', [\n    'name' =\u003e 'Tom',\n]);\n\n$config-\u003eput('contact.email', 'contact@tomwright.me');\n```\n\n## Fetching Data\n\nYou can use the dot separators in a similar way to the above when fetching data too.\n\nAssuming we have the same contact details stored, let's look at the following:\n\n```php\n$config-\u003eget('contact'); // [ 'name' =\u003e 'Tom', 'email' =\u003e 'contact@tomwright.me' ]\n\n$config-\u003eget('contact.name'); // Tom\n$config-\u003eget('contact.email'); // contact@tomwright.me\n```\n\n## Separators\n\nYou can use as many separators in the key as you would like. The following will end up working in the same way as the above, just with a deeper level of storage.\n\n```\n$config-\u003eput('company.person.tom.email', 'contact@tomwright.me');\n$config-\u003eput('company.person.jim.email', 'jim@tomwright.me');\n\n$config-\u003eget('company');\n/*\n[\n    'person' =\u003e [\n        'tom' =\u003e [ 'email' =\u003e 'contact@tomwright.me' ],\n        'jim' =\u003e [ 'email' =\u003e 'jim@tomwright.me' ],\n    ]\n]\n*/\n```\n\nIf you would like to use a separator other than the `.` character, you may set one using the `setSeparator()` method, or by passing it in in the Config constructor.\n\n```php\n$config = new Config([\n    'separator' =\u003e '|', // Equal\n]);\n$config-\u003esetSeparator('|'); // Equal\n\n$config-\u003eput('contact', [\n    'contact' =\u003e [\n        'name' =\u003e 'Tom',\n        'email' =\u003e 'contact@tomwright.me',\n    ],\n]);\n\n$config-\u003eget('contact|name'); // Tom\n$config-\u003eget('contact.email'); // NULL\n```\n\n## Config Readers\n\nConfig readers are classes to help you auto-populate the config object with values.\nTo use a Config Reader, simply pass it into `$config-\u003eread()`.\n\n```\n$config = new Config();\n$config-\u003eread(new SomeConfigReader());\n$config-\u003eget('some.value.from.my.reader');\n```\n\nYou can also pass an array of Config Readers into the Config constructor:\n\n```\n$config = new Config([\n    'readers' =\u003e [\n        new SomeConfigReader(),\n    ],\n]);\n$config-\u003eget('some.value.from.my.reader');\n```\n\n### Existing Config Readers\n\nIf you would like to create a Config Reader please feel free. The only requirement is that you implement the `ConfigReader` interface.\nIf you have already created a Config Reader and would like it to appear here, please submit a pull request.\n\n- [PHPFileReader](/docs/PHPFileReader.md)\n- [JSONFileReader](/docs/JSONFileReader.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomwright%2Fphpconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomwright%2Fphpconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomwright%2Fphpconfig/lists"}