{"id":18904453,"url":"https://github.com/oopsguy/pconfig","last_synced_at":"2025-08-21T23:27:34.754Z","repository":{"id":57031935,"uuid":"86837808","full_name":"oopsguy/pconfig","owner":"oopsguy","description":"A PHP library for parsing and persisting configuration files (json, yaml, ini, xml and php).  一个 PHP 配置文件工具库，可解析和持久化配置文件内容，简化文件操作。","archived":false,"fork":false,"pushed_at":"2019-07-01T12:12:41.000Z","size":54,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T03:49:09.100Z","etag":null,"topics":["config","configuration","ini","json","lib","parser","php","php-array","php-library","php-utility","utils","xml","yaml"],"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/oopsguy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-31T16:10:57.000Z","updated_at":"2019-07-18T16:03:47.000Z","dependencies_parsed_at":"2022-08-23T20:50:15.606Z","dependency_job_id":null,"html_url":"https://github.com/oopsguy/pconfig","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/oopsguy/pconfig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oopsguy%2Fpconfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oopsguy%2Fpconfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oopsguy%2Fpconfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oopsguy%2Fpconfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oopsguy","download_url":"https://codeload.github.com/oopsguy/pconfig/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oopsguy%2Fpconfig/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265808823,"owners_count":23831772,"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","configuration","ini","json","lib","parser","php","php-array","php-library","php-utility","utils","xml","yaml"],"created_at":"2024-11-08T09:08:34.881Z","updated_at":"2025-08-21T23:27:34.722Z","avatar_url":"https://github.com/oopsguy.png","language":"PHP","readme":"# PConfig\n\nPConfig is a PHP library for parsing configuration. \nIt is lightweight and easy to use.\n\n## Supported formats\n\n- php\n- json\n- xml\n- yaml\n- ini\n\n## Installation\n\n```bash\ncomposer require oopsguy/pconfig\n```\n\n## Usage\n\n```php\n\u003c?php\nuse pconfig\\PConfig;\nuse pconfig\\provider\\impl\\FileProvider;\nuse pconfig\\serializer\\impl\\JSONSerializer;\n\n$config = new PConfig('config-file.json');\n\n$config = new PConfig([\n    'file' =\u003e 'config-file.json'\n]);\n\n$config = new PConfig([\n    'data' =\u003e [\n        'key' =\u003e 'value'\n        // more...\n    ]\n]);\n$config-\u003esetSerializer(new JSONSerializer());\n$config-\u003esetProvider(new FileProvider('config/a.json'));\n\n$config = new PConfig([\n   'file' =\u003e 'config-file.json',\n   'serializer' =\u003e new JSONSerializer(),\n]);\n\n$config = new PConfig([\n    'serializer' =\u003e new JSONSerializer(),\n    'provider' =\u003e new FileProvider('config-file.json'),\n]);\n```\n\n```php\n\u003c?php\nuse pconfig\\PConfig;\nuse pconfig\\serializer\\impl\\YAMLSerializer;\nuse pconfig\\provider\\impl\\FileProvider;\n\n// PHP array\n// Automatically detect file extension and select a suitable serializer\n$config = new PConfig(\"config/config.php\");\necho $config-\u003eget(\"app\");\n$config-\u003edelete(\"version\");\n$config-\u003eset('debug', false);\n$config-\u003eset(\"settings.key\", \"new value\");\n$config-\u003esave();\n\n// handle JSON\n$jsonConfig = new PConfig('config/config.json');\n$jsonConfig-\u003eset('homepage', 'https://github.com');\n// Save as temp.json file\n$jsonConfig-\u003esetFile('config/temp.json');\n$jsonConfig-\u003esave();\n\n// Parsing YAML\n// Explicitly specify a YAML serializer\n$serializer = new YAMLSerializer();\n$provider = new FileProvider('config/settings.yaml');\n$extConfig = new PConfig([\n        'provider' =\u003e $provider,\n        'serializer' =\u003e $serializer\n    ]);\n$extConfig-\u003eset('type', 'yaml');\n$extConfig-\u003esave();\n```\n\nThe default key separator is a dot-notation `.`.\n\n```\nkey1.key2.key3\n```\n\nYou can use `PConfig::CONFIG_KEY_EXTRACT_SEPARATOR` to custom your own separator.\n\n```\nPConfig::CONFIG_KEY_EXTRACT_SEPARATOR =\u003e '-',\n```\n\n```\nkey1-key2-key3\n```\n\n```php\n\u003c?php\nuse pconfig\\PConfig;\nuse pconfig\\provider\\impl\\FileProvider;\nuse pconfig\\serializer\\impl\\JSONSerializer;\n\n$config = new PConfig([\n        // Specify the serializer\n        'serializer' =\u003e new JSONSerializer(),\n        'provider' =\u003e new FileProvider('config/config.php'),\n        'config' =\u003e [\n                // Set the key separator\n                PConfig::CONFIG_KEY_EXTRACT_SEPARATOR =\u003e '-', \n            ]\n    ]);\n```\n\n## ArrayAccess\n\n`PConfig` has implemented `ArrayAccess` interface, you can access configuration by array operations.\n\n```php\n\u003c?php\nuse pconfig\\PConfig;\n\n// Access by index\n$json = new PConfig('./config/arrayaccess.json');\n$json['status'] = true;\n$json['data'] = [\n    'page' =\u003e 1,\n    'pageSize' =\u003e 10,\n    'pages' =\u003e 2,\n    'total' =\u003e 13,\n    'list' =\u003e [\n        [\n            'username' =\u003e 'oopsguy',\n            'gender' =\u003e '男'\n        ]\n    ]\n];\n$json['msg'] = 'ok';\n$json['delData'] = 'XHSYSYSDkoksoada8dsaidsa9d8adsa';\n\n// unset and isset API\nvar_dump(isset($json['delData']));\nunset($json['delData']);\nvar_dump(isset($json['delData']));\n\n// Save to file\n$json-\u003esave();\n```\n\nNested configuration.\n\n```php\n$config-\u003eset('level1.level2.level3', \"Level end\");\n$config-\u003edelete('level1.level2');\n```\n\n## APIs\n\n- `set($key, $value)`\n- `get($key[, $defult])`\n- `delete($key)`\n- `exists($key)`\n- `getConfig($key)`\n- `setConfig($key, $value)`\n- `setProvider($provider)`\n- `setSerializer($serializer)`\n- `setFile($path)`\n- `reload()`\n- `clear()`\n- `save()`\n\n## Licence\n\nMIT Licence\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foopsguy%2Fpconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foopsguy%2Fpconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foopsguy%2Fpconfig/lists"}