{"id":36993453,"url":"https://github.com/miladrahimi/phpconfig","last_synced_at":"2026-01-13T23:45:38.619Z","repository":{"id":34448250,"uuid":"38383018","full_name":"miladrahimi/phpconfig","owner":"miladrahimi","description":"A configuration service for your PHP projects!","archived":true,"fork":false,"pushed_at":"2018-09-24T18:36:59.000Z","size":26,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-18T21:04:28.424Z","etag":null,"topics":["config","configuration","configuration-files","configuration-management","php","phpconfig"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"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/miladrahimi.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-07-01T16:45:17.000Z","updated_at":"2024-11-26T12:43:16.000Z","dependencies_parsed_at":"2022-08-17T20:45:12.102Z","dependency_job_id":null,"html_url":"https://github.com/miladrahimi/phpconfig","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/miladrahimi/phpconfig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miladrahimi","download_url":"https://codeload.github.com/miladrahimi/phpconfig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miladrahimi%2Fphpconfig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","configuration-files","configuration-management","php","phpconfig"],"created_at":"2026-01-13T23:45:38.554Z","updated_at":"2026-01-13T23:45:38.606Z","avatar_url":"https://github.com/miladrahimi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/miladrahimi/phpconfig.svg?branch=master)](https://travis-ci.com/miladrahimi/phpconfig)\n\n# PhpConfig\nA PHP configuration tool\n\n## Overview\nPhpConfig is a minimal package for adding configuration tool to your PHP project.\nIt provides different types of config repositries such as runtime array, php file, directory of php files, json file and directory of json files.\n\n## Installation\nRun following command in the root directory of your project:\n\n```bash\ncomposer require miladrahimi/phpconfig\n```\n\n## Getting started\n\nFirst of all, you need to provide configuration data to PhpConfig. It supports different types of repositories like php file, json file, and you can use anyone you are interested in.\n\nAs an example we use array repository as the configuration data source. The following example demonstrates how to use an array of data as the data source, how to access data in your code and also how to go deeper using `.` operator.\n\n```php\nuse MiladRahimi\\PhpConfig\\Config;\nuse MiladRahimi\\PhpConfig\\Repositories\\ArrayRepository;\n\n$data = [\n    'name' =\u003e 'MyProject',\n    'mysql' =\u003e [\n        'hostname' =\u003e '127.0.0.1',\n        'username' =\u003e 'root',\n        'password' =\u003e 'secret',\n        'database' =\u003e 'my_database'\n    ]\n];\n\n$repository = new ArrayRepository($data);\n$config = new Config($repository);\n\n$name = $config-\u003eget('name'); // \"MyProject\"\n$mysql_username = $config-\u003eget('mysql.username', 'root'); // \"root\"\n$mysql_password =\u003e $config-\u003eget('mysql.password', ''); // \"secret\"\n$locale = $config-\u003eget('locale', 'en'); // \"en\" (Default)\n\n// Runtime config setting/manipulating\n$config-\u003eset('locale', 'fa');\n\n$locale = $config-\u003eget('locale', 'en'); // \"fa\"\n\n```\n\n## Repositories\n\nThe example above illustrates how to use a defined array as the respository for PhpConfig. In this section, we introduce some other repositories.\n\n### Config PHP File\n\nYou can put the data array into a separate PHP file this way:\n\n```php\n\u003c?php\n\nreturn [\n    'name' =\u003e 'MyProject',\n    'mysql' =\u003e [\n        'hostname' =\u003e '127.0.0.1',\n        'username' =\u003e 'root',\n        'password' =\u003e 'secret',\n        'database' =\u003e 'my_database'\n    ]\n];\n```\n\nAnd to use the config file:\n\n```php\nuse MiladRahimi\\PhpConfig\\Config;\nuse MiladRahimi\\PhpConfig\\Repositories\\FileRepository;\n\n$repository = new FileRepository('config.php');\n$config = new Config($repository);\n\n$mysql_username = $config-\u003eget('mysql.username');\n```\n\n### Config Directory\n\nYou probably need to split your configuration data into multiple files in a larger scale. Don't worry about it, it will be handled so easy!\n\nConsider the config files in a directory like this:\n\n```\nProject\n- index.php\n- configs\n- - app.php\n- - mysql.php\n```\n\nAnd `app.php` :\n\n```php\n\u003c?php\n    \nreturn [\n    'name' =\u003e 'MyProject',\n    'locale' =\u003e [\n        'code' =\u003e 'fa',\n        'name' =\u003e 'Farsi (Persian)',\n    ],\n    'url' =\u003e 'https://example.com'\n];\n```\n\nAnd `mysql.php`:\n\n```php\n\u003c?php\n\nreturn [\n    'hostname' =\u003e '127.0.0.1',\n    'username' =\u003e 'root',\n    'password' =\u003e 'secret',\n    'database' =\u003e 'my_database'\n];\n```\n\nAnd the main code:\n\n```php\nuse MiladRahimi\\PhpConfig\\Config;\nuse MiladRahimi\\PhpConfig\\Repositories\\DirectoryRepository;\n\n$config = new Config(new DirectoryRepository('configs'));\n\n$app_locale_code = $config-\u003eget('app.locale.code', 'en');\n$mysql_username = $config-\u003eget('mysql.username', 'default-username');\n```\n\n### Config JSON File\n\nPHP array syntax looks very nice but you may prefer JSON, if so, there's a good news, you can write your configs in JSPN format like the following example.\n\nThe `config.json`:\n\n```json\n{\n    \"app\": {\n        \"name\": \"MyProject\",\n        \"locale\": {\n            \"code\": \"fa\",\n            \"name\": \"Farsi (Persian)\"\n        }\n    }\n}\n```\n\nAnd the main code:\n\n```php\nuse MiladRahimi\\PhpConfig\\Config;\nuse MiladRahimi\\PhpConfig\\Repositories\\JsonFileRepository;\n\n$config = new Config(new JsonFileRepository('config.json'));\n\n$app_locale_code = $config-\u003eget('app.locale.code', 'en'); // \"fa\"\n```\n\n### Config JSON Directory\n\nA Single JSON configuration file still has the same single php file problem, so we have implemented another repository type for multiple JSON files.\n\nConsider the config files in a directory like this:\n\n```\nProject\n- index.php\n- configs\n- - app.json\n- - mysql.json\n```\n\nAnd `app.json` :\n\n```json\n{\n    \"name\": \"MyProject\",\n    \"locale\": {\n        \"code\": \"fa\",\n        \"name\": \"Farsi (Persian)\"\n    }\n}\n```\n\nAnd `mysql.json`:\n\n```json\n{\n    \"hostname\": \"localhost\",\n    \"username\": \"root\",\n    \"password\": \"secret\",\n    \"database\": \"my_project_db\"\n}\n```\n\nAnd the main code:\n\n```php\nuse MiladRahimi\\PhpConfig\\Config;\nuse MiladRahimi\\PhpConfig\\Repositories\\JsonDirectoryRepository;\n\n$config = new Config(new JsonDirectoryRepository('configs'));\n\n$app_locale_code = $config-\u003eget('app.locale.code', 'en'); // \"fa\"\n$mysql_username = $config-\u003eget('mysql.username', 'default-username');\n```\n\n### Custom Repositories\n\nYou can also make your own repositories by implementing following interface:\n\n```php\n\u003c?php\n    \nnamespace MiladRahimi\\PhpConfig\\Repositories;\n\ninterface Repository\n{\n    /**\n     * Get configuration data\n     *\n     * @return array\n     */\n    public function getData(): array;\n}\n```\n\n## License\nPhpConfig is initially created by [Milad Rahimi](http://miladrahimi.com) and released under the [MIT License](http://opensource.org/licenses/mit-license.php).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladrahimi%2Fphpconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiladrahimi%2Fphpconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiladrahimi%2Fphpconfig/lists"}