{"id":27158896,"url":"https://github.com/activecollab/configrepository","last_synced_at":"2025-04-08T22:39:26.589Z","repository":{"id":56940223,"uuid":"48114147","full_name":"activecollab/configrepository","owner":"activecollab","description":"Compose a configuration repository that reads and write options from serveral sources.","archived":false,"fork":false,"pushed_at":"2015-12-17T12:46:56.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T13:03:28.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://labs.activecollab.com","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/activecollab.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2015-12-16T14:10:26.000Z","updated_at":"2017-02-13T02:37:44.000Z","dependencies_parsed_at":"2022-08-21T01:40:25.516Z","dependency_job_id":null,"html_url":"https://github.com/activecollab/configrepository","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fconfigrepository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fconfigrepository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fconfigrepository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fconfigrepository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/activecollab","download_url":"https://codeload.github.com/activecollab/configrepository/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247941718,"owners_count":21022035,"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":[],"created_at":"2025-04-08T22:39:25.891Z","updated_at":"2025-04-08T22:39:26.583Z","avatar_url":"https://github.com/activecollab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configuration Repository\n\n[![Build Status](https://travis-ci.org/activecollab/configrepository.svg?branch=master)](https://travis-ci.org/activecollab/configrepository)\n\nThis package provides a way to compose a configuration repository that reads and write options from serveral sources.\n\nExisting adapters:\n\n1. `DotEnvAdapter` - load environment variables from `.env` file (read-only),\n2. `EtcdAdapter` - read and write options from and to etcd cluster,\n3. `PhpConstantsAdapter` - load options from regular PHP file full of constants. Note that this file is not included, but parsed statically, so you don't need to worry that these constants will be defined in your code.\n\nTo write your own adapters, simply implement `ActiveCollab\\ConfigRepository\\AdapterInterface`.\n\n## Working with data\n\nRepository provides a couple of confenient methods to retrive and set the data:\n\n```php\n\u003c?php\n\nuse ActiveCollab\\ConfigRepository\\ConfigRepository;\nuse ActiveCollab\\ConfigRepository\\Adapter\\PhpConstantsAdapter;\n\n$repository = new ConfigRepository(new PhpConstantsAdapter('/path/to/config.php'));\n\n// Check if option exists in any of the adapters\n$repository-\u003eexists('CONFIG_NAME');\n\n// Get value from first adapter that has it, or return default value if none of the adapters have it\n$repository-\u003eget('CONFIG_NAME', 'default if not found');\n\n// Get value from first adapter that has it, or throw an exception if it is not found in any adapter\n$repository-\u003emustGet('CONFIG_NAME'); // Throws an exception if option is not fpund\n\n// Set value in all adapters where this option exists. Read-only adapters that have this option will throw an exception\n$repository-\u003eset('CONFIG_NAME', 'value to set');\n```\n\nTo work with the data from a particular adapter, find it and use the same methods:\n\n```php\n\u003c?php\n\nuse ActiveCollab\\ConfigRepository\\ConfigRepository;\nuse ActiveCollab\\ConfigRepository\\Adapter\\PhpConstantsAdapter;\n\n$repository = new ConfigRepository(new PhpConstantsAdapter('/path/to/config.php'));\n\n$repository-\u003egetAdapter(PhpConstantsAdapter::class)-\u003eexists('CONFIG_NAME');\n$repository-\u003egetAdapter(PhpConstantsAdapter::class)-\u003eget('CONFIG_NAME', 'default if not found');\n$repository-\u003egetAdapter(PhpConstantsAdapter::class)-\u003emustGet('CONFIG_NAME'); // Throws an exception if option is not fpund\n$repository-\u003egetAdapter(PhpConstantsAdapter::class)-\u003eset('CONFIG_NAME', 'value to set');\n```\n\n## Adapter Composition\n\nWhen constructing a repository instance, you can specify a list of adapters:\n\n```php\n\u003c?php\n\nuse ActiveCollab\\ConfigRepository\\ConfigRepository;\nuse ActiveCollab\\ConfigRepository\\Adapter\\DotEnvAdapter;\nuse ActiveCollab\\ConfigRepository\\Adapter\\PhpConstantsAdapter;\n\n$repository = new ConfigRepository(new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'), new DotEnvAdapter(__DIR__ . '/Resources', '.env'));\n```\n\nAdapters added like this will be indexed by their class names, so instances of the same class can't be added like this. To do that, provide an array, where key is adaper name and value is adapter instance (if key is missing, library will use adapter's class as adapter name):\n\n```php\n\u003c?php\n\nuse ActiveCollab\\ConfigRepository\\ConfigRepository;\nuse ActiveCollab\\ConfigRepository\\Adapter\\DotEnvAdapter;\nuse ActiveCollab\\ConfigRepository\\Adapter\\PhpConstantsAdapter;\n\n$repository = new ConfigRepository([\n    new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'),\n    'second' =\u003e new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'),\n], new DotEnvAdapter(__DIR__ . '/Resources', '.env'));\n\n$repository-\u003egetAdapter(PhpConstantsAdapter::class); // Returns PhpConstantsAdapter instance\n$repository-\u003egetAdapter('second');                   // Returns PhpConstantsAdapter instance\n$repository-\u003egetAdapter(DotEnvAdapter::class);       // Returns DotEnvAdapter instance\n```\n\nAdapters can also be added at any time, using `addAdapter()` method:\n\n```php\n\u003c?php\n\nuse ActiveCollab\\ConfigRepository\\ConfigRepository;\nuse ActiveCollab\\ConfigRepository\\Adapter\\DotEnvAdapter;\nuse ActiveCollab\\ConfigRepository\\Adapter\\PhpConstantsAdapter;\n\n$repository = new ConfigRepository(new PhpConstantsAdapter(__DIR__ . '/Resources/config.simple.php'));\n$repository-\u003eaddAdapter(new DotEnvAdapter($repository-\u003eget('DOT_ENV_DIR_PATH')));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Fconfigrepository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factivecollab%2Fconfigrepository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Fconfigrepository/lists"}