{"id":15029143,"url":"https://github.com/theiconic/config","last_synced_at":"2025-04-09T20:32:53.998Z","repository":{"id":57068027,"uuid":"60538629","full_name":"theiconic/config","owner":"theiconic","description":"PHP configuration handler for file based configuration","archived":false,"fork":false,"pushed_at":"2018-06-19T20:16:20.000Z","size":78,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":81,"default_branch":"master","last_synced_at":"2025-03-23T22:26:30.610Z","etag":null,"topics":["configuration","library","php","php7"],"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/theiconic.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-06-06T15:22:55.000Z","updated_at":"2022-02-12T12:31:01.000Z","dependencies_parsed_at":"2022-08-24T14:54:09.133Z","dependency_job_id":null,"html_url":"https://github.com/theiconic/config","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theiconic","download_url":"https://codeload.github.com/theiconic/config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107726,"owners_count":21048988,"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","php","php7"],"created_at":"2024-09-24T20:09:49.535Z","updated_at":"2025-04-09T20:32:53.968Z","avatar_url":"https://github.com/theiconic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# theiconic/config\n\nGeneral purpose config manager for file-based configuration.\n\n[![Build Status](https://travis-ci.org/theiconic/config.svg?branch=master)](https://travis-ci.org/theiconic/config)\n[![Coverage Status](https://coveralls.io/repos/github/theiconic/config/badge.svg?branch=master)](https://coveralls.io/github/theiconic/config?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/config/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/theiconic/config/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/theiconic/config/v/stable)](https://packagist.org/packages/theiconic/config)\n[![Total Downloads](https://poser.pugx.org/theiconic/config/downloads)](https://packagist.org/packages/theiconic/config)\n[![License](https://poser.pugx.org/theiconic/config/license)](https://packagist.org/packages/theiconic/config)\n[![Dependency Status](https://www.versioneye.com/user/projects/5927a989f5a9a60048c5a326/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5927a989f5a9a60048c5a326)\n\n## Setup\n```$php\ncomposer require theiconic/config\n```\n\n## Concepts\n\n### Spaces\nConfiguration is grouped into configuration spaces.\nSpaces are managed by the configuration factory.\n\n### Multi-file \u0026 multi-section configuration\nA configuration space can read configuration from several\nfiles. The configuration is merged and then flattened by\nsection.\n\n### Placeholders\nDuring parsing, pre-defined placeholders will be replaced\nwith the configured replacement values.\n\n### Example\nSo the basic setup looks something like this (modified example based on alice):\n```\n// get the factory instance\n$factory = Factory::getInstance();\n\n// set the current environment\n$factory-\u003esetEnvironment(APPLICATION_ENV);\n\n// configure cache path\n$factory-\u003esetCachePath(sprintf('%s/config', APPLICATION_TMP));\n\n// instanciate and configure the application config space\n$factory-\u003egetSpace('application')\n    -\u003esetPaths([\n        '/etc/iconic.ini',\n        $basePath . 'application.ini',\n        $basePath . 'application.local.ini',\n    ])\n    -\u003esetSections([\n        'default',\n        'production',\n    ])\n    -\u003esetPlaceholders([\n        '%APPLICATION_ENV%' =\u003e APPLICATION_ENV,\n        '%APPLICATION_ROOT%' =\u003e APPLICATION_ROOT,\n        '%APPLICATION_TMP%' =\u003e APPLICATION_TMP,\n    ]);\n\n```\n\n## Multi-section config format\n\nConfiguration files must contain configuration sections.\nThis is the sections in .ini files and the first level array/object\nitems in .php or .json config files.\n\nNo sections are pre-selected by default. You will need to explicitly\nstate the sections in code, like so:\n```$php\n$factory-\u003egetSpace('myConfig')\n    -\u003esetSections(['main', 'development', 'testing']);\n```\n\nSections will be merged in the order specified, i.e. entries in later\nsections will override those in earlier sections.\n\n## Caching\n\nAll configuration is parsed into multidimensional PHP arrays.\nThe arrays are then stored in cache files so that expensive\nparsing is bypassed.\n\nCache keys are determined based on\n- the list of source files names\n- the list on section names.\n\nCache is automatically validated based on file modification timestamps.\nHence, the cache will automatically update itself whenever\nany of the source configuration files changes.\n\n## Parsing\n\nExtendable parsers are used to parse different file formats.\nCurrently implemented parsers are:\n* Ini (for .ini files)\n* Json (for .json files)\n* Php (for .php files)\n* Autodetect (automatically picks the right parser based on extension)\n* Dummy (for unit tests etc.)\n\n## Accessing configuration values\n\nConfiguration can be accessed via dot-paths.\nThese paths are dynamically resolved against the internal\narray-representation of configuration.\nThis allows retrieving individual entries as well as\ncollections of entries.\n\n```\nFactory::getInstance()-\u003egetSpace('application')-\u003eget('redis.retries', 3);\nFactory::getInstance()-\u003egetSpace('application')-\u003eget('redis.hosts', 'localhost');\n \nFactory::getInstance()-\u003egetSpace('application')-\u003eget('redis', ['retries': 3, 'hosts': 'localhost]);\n```\n\nYou can also retrieve the configuration as a flat array of\ndot-path to value mappings:\n\n```\nFactory::getInstance()-\u003egetSpace('application')-\u003eflatten();\n```\n\n## Using environment variables\n\nThere is no explicit functionality to handle environment variables, however\nthey can be dynamically used in the configurations via the placeholders mechanism:\n```\n$space = Factory::getInstance()-\u003egetSpace('application');\nforeach ($_ENV as $key =\u003e $value) {\n    $placeholder = sprintf('%%ENV_%s%%', strtoupper(str_replace('%', '_', $key)));\n    $space-\u003eaddPlaceholder($placeholder, $value);\n}\n```\nWith these few lines in place, a configuration file could look like this:\n```\n[main]\nuser.name = %ENV_USER%\nuser.home = %ENV_HOME%\n```\n\n## License\n\nTHE ICONIC config library for PHP is released under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheiconic%2Fconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheiconic%2Fconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheiconic%2Fconfig/lists"}