{"id":47603741,"url":"https://github.com/php-collective/toml","last_synced_at":"2026-04-02T13:27:07.617Z","repository":{"id":346685619,"uuid":"1190854609","full_name":"php-collective/toml","owner":"php-collective","description":"PHP library for encoding and decoding TOML","archived":false,"fork":false,"pushed_at":"2026-03-25T09:46:23.000Z","size":258,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-26T06:47:45.583Z","etag":null,"topics":["configuration","php","toml"],"latest_commit_sha":null,"homepage":"https://php-collective.github.io/toml/","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/php-collective.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-24T17:24:10.000Z","updated_at":"2026-03-25T09:45:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/php-collective/toml","commit_stats":null,"previous_names":["php-collective/toml"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/php-collective/toml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Ftoml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Ftoml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Ftoml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Ftoml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-collective","download_url":"https://codeload.github.com/php-collective/toml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-collective%2Ftoml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31307069,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"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":["configuration","php","toml"],"created_at":"2026-04-01T19:00:25.359Z","updated_at":"2026-04-02T13:27:07.611Z","avatar_url":"https://github.com/php-collective.png","language":"PHP","funding_links":[],"categories":["Table of Contents"],"sub_categories":["Configuration"],"readme":"# PHP Toml\n\n[![CI](https://img.shields.io/github/actions/workflow/status/php-collective/toml/ci.yml?branch=master\u0026style=flat-square)](https://github.com/php-collective/toml/actions)\n[![Latest Stable Version](https://img.shields.io/packagist/v/php-collective/toml?style=flat-square)](https://packagist.org/packages/php-collective/toml)\n[![Total Downloads](https://img.shields.io/packagist/dt/php-collective/toml?style=flat-square)](https://packagist.org/packages/php-collective/toml)\n[![PHPStan](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat-square)](https://phpstan.org/)\n[![PHP Version](https://img.shields.io/badge/php-%3E%3D8.2-8892BF.svg?style=flat-square)](https://php.net)\n[![Software License](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)\n\nA [TOML](https://toml.io/) (v1.0 and v1.1) parser and encoder for PHP with AST access and collected parse errors.\n\n**[Documentation](https://php-collective.github.io/toml/)**\n\n## Features\n\n- Strict validation for malformed keys, tables, strings, numbers, and datetimes\n- Error recovery with multiple error collection for tooling workflows\n- Clean architecture with separate Lexer, Parser, and AST\n- Zero required extensions (optional php-ds for performance)\n- AST access for analysis or editor integrations\n- Explicit local date/time/datetime value objects for encoding\n\n## Requirements\n\n- PHP 8.2 or higher\n\n## Installation\n\n```bash\ncomposer require php-collective/toml\n```\n\n## Demo\n\n- [Interactive Playground](https://sandbox.dereuromark.de/sandbox/toml) - Full-featured sandbox with all options.\n\n## Quick Start\n\n```php\nuse PhpCollective\\Toml\\Toml;\nuse PhpCollective\\Toml\\TomlVersion;\n\n// Decode TOML to PHP array\n$config = Toml::decode(\u003c\u003c\u003c'TOML'\n[database]\nhost = \"localhost\"\nport = 5432\nTOML);\n\necho $config['database']['host']; // \"localhost\"\n\n// Opt into strict TOML 1.0 parsing/decoding\n$strict = Toml::decode('time = 07:32:00', TomlVersion::V10);\n\n// Encode PHP array to TOML\n$toml = Toml::encode([\n    'server' =\u003e [\n        'host' =\u003e '0.0.0.0',\n        'port' =\u003e 8080,\n    ],\n]);\n```\n\n## API Reference\n\n### Decoding\n\n```php\n// Decode string - throws ParseException on error\n$array = Toml::decode($tomlString);\n\n// Decode file\n$array = Toml::decodeFile('/path/to/config.toml');\n\n// Parse without throwing - for tooling\n$result = Toml::tryParse($tomlString);\nif ($result-\u003eisValid()) {\n    $array = $result-\u003egetValue();\n} else {\n    foreach ($result-\u003egetErrors() as $error) {\n        echo $error-\u003eformat($tomlString);\n    }\n}\n\n// Parse to AST for analysis\n$document = Toml::parse($tomlString);\n\n// Parse without exceptions and keep diagnostics + partial AST\n$result = Toml::tryParse($tomlString);\n$document = $result-\u003egetDocument();\n```\n\n### Encoding\n\n```php\nuse PhpCollective\\Toml\\Encoder\\DocumentFormattingMode;\nuse PhpCollective\\Toml\\Encoder\\EncoderOptions;\nuse PhpCollective\\Toml\\Ast\\Value\\StringStyle;\nuse PhpCollective\\Toml\\Ast\\Value\\StringValue;\nuse PhpCollective\\Toml\\TomlVersion;\n\n// Encode to TOML string\n$toml = Toml::encode($array);\n\n// Encode directly to file\nToml::encodeFile('/path/to/config.toml', $array);\n\n// With options - e.g. omit nulls instead of throwing\n$toml = Toml::encode($array, new EncoderOptions(skipNulls: true));\n\n// Strict TOML 1.0 output\n$toml = Toml::encode($array, new EncoderOptions(version: TomlVersion::V10));\n\n// encodeDocument() is normalized by default\n$document = Toml::parse($tomlString, true);\n$toml = Toml::encodeDocument($document);\n\n// Encode document directly to file\nToml::encodeDocumentFile('/path/to/output.toml', $document);\n\n// Opt into source-aware formatting for minimal-diff AST re-encoding\n$document = Toml::parse($tomlString, true);\n$document-\u003eitems[0]-\u003evalue = new StringValue('new value');\n$toml = Toml::encodeDocument(\n    $document,\n    new EncoderOptions(documentFormatting: DocumentFormattingMode::SourceAware),\n);\n```\n\n`DocumentFormattingMode::SourceAware` is lossless for unchanged parsed regions and uses local fallback rules for edited ones. See the [Compatibility](https://php-collective.github.io/toml/reference/compatibility) page for the exact editing contract.\n`skipNulls` lets `encode()` omit nulls instead of throwing.\n\n## Error Handling\n\nThe parser provides detailed error messages:\n\n```\nParse error: unterminated string\n\n  3 | name = \"value\n    |        ^\n  4 | other = 123\n\nHint: Did you forget to close the string with \"?\n```\n\nFor tooling, use `tryParse()` to collect all errors:\n\n```php\n$result = Toml::tryParse($input);\nforeach ($result-\u003egetErrors() as $error) {\n    // $error-\u003emessage - Error description\n    // $error-\u003espan    - Position (line, column, offset)\n    // $error-\u003ehint    - Optional suggestion\n}\n```\n\n## Supported Syntax\n\nThe library currently supports:\n\n- All string types (basic, literal, multi-line)\n- Integers (decimal, hex, octal, binary)\n- Floats (including inf, nan)\n- Booleans\n- Dates and times (offset, local datetime, local date, local time)\n- Arrays (including multiline arrays and trailing commas)\n- Inline tables (including multiline inline tables and trailing commas in TOML 1.1)\n- Tables and array of tables\n- Dotted keys\n\nSee the [Support Matrix](https://php-collective.github.io/toml/reference/support-matrix) for current coverage and known gaps.\n\nVersioned behavior is available through `TomlVersion` and `EncoderOptions(version: ...)`. The default remains TOML 1.1-compatible; use `TomlVersion::V10` when you need strict TOML 1.0 parsing or output rules.\n\nFor explicit local temporal encoding, use:\n\n- `PhpCollective\\Toml\\Value\\LocalDate`\n- `PhpCollective\\Toml\\Value\\LocalTime`\n- `PhpCollective\\Toml\\Value\\LocalDateTime`\n\n## Comparison with Other PHP Libraries\n\n| Feature | php-collective/toml | Others |\n|---------|---------------------|--------|\n| Error Recovery | Yes | No |\n| Multiple Errors | Yes | No |\n| AST Access | Yes | Limited/No |\n| Round-trip formatting preservation | Partial | Varies |\n\nSee [Limitations](https://php-collective.github.io/toml/reference/limitations) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-collective%2Ftoml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-collective%2Ftoml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-collective%2Ftoml/lists"}