{"id":16126686,"url":"https://github.com/vanodevium/toml","last_synced_at":"2025-09-21T12:32:51.762Z","repository":{"id":252138831,"uuid":"839542477","full_name":"vanodevium/toml","owner":"vanodevium","description":"PHP library for encoding and decoding TOML","archived":false,"fork":false,"pushed_at":"2025-01-11T11:43:02.000Z","size":60,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-11T12:26:00.843Z","etag":null,"topics":[],"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/vanodevium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","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},"funding":{"github":"vanodevium"}},"created_at":"2024-08-07T20:33:54.000Z","updated_at":"2025-01-11T11:43:05.000Z","dependencies_parsed_at":"2024-09-08T12:59:27.120Z","dependency_job_id":"3fe75048-368f-42b5-9203-d2eb194404f1","html_url":"https://github.com/vanodevium/toml","commit_stats":null,"previous_names":["vanodevium/toml"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanodevium%2Ftoml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanodevium%2Ftoml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanodevium%2Ftoml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vanodevium%2Ftoml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vanodevium","download_url":"https://codeload.github.com/vanodevium/toml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233753375,"owners_count":18724823,"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":"2024-10-09T21:39:53.252Z","updated_at":"2025-09-21T12:32:51.751Z","avatar_url":"https://github.com/vanodevium.png","language":"PHP","funding_links":["https://github.com/sponsors/vanodevium"],"categories":["Table of Contents"],"sub_categories":["Globalization"],"readme":"# Stand With Ukraine 🇺🇦\n\n[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://vshymanskyy.github.io/StandWithUkraine/)\n\n# Devium/Toml\n\n[![Tests status](https://img.shields.io/github/actions/workflow/status/vanodevium/toml/ci.yaml?v1.0.6\u0026style=flat-square\u0026label=tests)](https://github.com/vanodevium/toml)\n[![Latest Version](https://img.shields.io/packagist/v/devium/toml?v1.0.6\u0026style=flat-square\u0026label=stable)](https://packagist.org/packages/devium/toml)\n[![Downloads](https://img.shields.io/packagist/dt/devium/toml?v1.0.6\u0026style=flat-square)](https://packagist.org/packages/devium/toml)\n[![License](https://img.shields.io/packagist/l/devium/toml?v1.0.6\u0026style=flat-square)](https://packagist.org/packages/devium/toml)\n\nA robust and efficient PHP library for encoding and decoding [TOML](https://github.com/toml-lang/toml)\ncompatible with [v1.0.0](https://toml.io/en/v1.0.0)\n\n\u003e This library tries to support the TOML specification as much as possible.\n\n## Overview\n\nThis library provides a comprehensive solution for working with TOML in PHP applications\n\n## Features\n\n-   Encoding PHP arrays and objects to TOML format\n-   Decoding TOML strings into PHP data structures\n-   Preserves data types as specified in TOML\n-   Handles complex nested structures\n-   Supports TOML datetime formats\n-   Error handling with informative messages\n\n## Installation\n\nYou can install this library via composer:\n\n```shell\ncomposer require devium/toml\n```\n\n## Usage\n\nDecoding:\n\n```php\n$toml = \u003c\u003c\u003cTOML\n\n# This is a TOML document\n\ntitle = \"TOML Example\"\n\n[owner]\nname = \"Tom Preston-Werner\"\ndob = 1979-05-27T07:32:00-08:00\n\nTOML;\n\ndump(\\Devium\\Toml\\Toml::decode($toml, asArray: true));\ndump(\\Devium\\Toml\\Toml::decode($toml, asArray: false));\n\n// or use global helper\ndump(toml_decode($toml, asArray: false));\ndump(toml_decode($toml, asArray: true));\n```\n\nEncoding:\n\n```php\n$data = [\n  \"title\" =\u003e \"TOML Example\",\n  \"owner\" =\u003e [\n    \"name\" =\u003e \"Tom Preston-Werner\",\n    \"dob\" =\u003e \"1979-05-27T15:32:00.000Z\",\n  ],\n];\n\ndump(\\Devium\\Toml\\Toml::encode($data));\n// or use global helper\ndump(toml_encode($data));\n```\n\n## About TOML datetime formats\n\nThis library tries to parse TOML datetime formats into next variants (according to the specification):\n\n-   `Devium\\Toml\\TomlDateTime` (for the [offset date time](https://toml.io/en/v1.0.0#offset-date-time))\n-   `Devium\\Toml\\TomlLocalDatetime` (for the [local date time](https://toml.io/en/v1.0.0#local-date-time))\n-   `Devium\\Toml\\TomlLocalDate` (for the [local date](https://toml.io/en/v1.0.0#local-date))\n-   `Devium\\Toml\\TomlLocalTime` (for the [local time](https://toml.io/en/v1.0.0#local-time))\n\nExample:\n\n```toml\n\noffset-date-time-1 = 1979-05-27T07:32:00Z\noffset-date-time-2 = 1979-05-27T00:32:00-07:00\noffset-date-time-3 = 1979-05-27T00:32:00.999999-07:00\noffset-date-time-4 = 1979-05-27 07:32:00Z\n\nlocal-date-time-1 = 1979-05-27T07:32:00\nlocal-date-time-2 = 1979-05-27T00:32:00.999999\n\nlocal-date-1 = 1979-05-27\n\nlocal-time-1 = 07:32:00\nlocal-time-2 = 00:32:00.999999\n\n```\n\nIf you use\n\n```php\ndump(toml_decode($toml, true));\n```\n\nTOML will be parsed into array\n\n```php\narray:9 [\n  \"offset-date-time-1\" =\u003e Devium\\Toml\\TomlDateTime @296638320 {#29\n    date: 1979-05-27 07:32:00.0 +00:00\n  }\n  \"offset-date-time-2\" =\u003e Devium\\Toml\\TomlDateTime @296638320 {#35\n    date: 1979-05-27 00:32:00.0 -07:00\n  }\n  \"offset-date-time-3\" =\u003e Devium\\Toml\\TomlDateTime @296638320 {#41\n    date: 1979-05-27 00:32:00.999999 -07:00\n  }\n  \"offset-date-time-4\" =\u003e Devium\\Toml\\TomlDateTime @296638320 {#47\n    date: 1979-05-27 07:32:00.0 +00:00\n  }\n  \"local-date-time-1\" =\u003e Devium\\Toml\\TomlLocalDateTime {#55\n    +year: 1979\n    +month: 5\n    +day: 27\n    +hour: 7\n    +minute: 32\n    +second: 0\n    +millisecond: 0\n  }\n  \"local-date-time-2\" =\u003e Devium\\Toml\\TomlLocalDateTime {#61\n    +year: 1979\n    +month: 5\n    +day: 27\n    +hour: 0\n    +minute: 32\n    +second: 0\n    +millisecond: 999\n  }\n  \"local-date-1\" =\u003e Devium\\Toml\\TomlLocalDate {#59\n    +year: 1979\n    +month: 5\n    +day: 27\n  }\n  \"local-time-1\" =\u003e Devium\\Toml\\TomlLocalTime {#70\n    +millisecond: 0\n    +hour: 7\n    +minute: 32\n    +second: 0\n  }\n  \"local-time-2\" =\u003e Devium\\Toml\\TomlLocalTime {#77\n    +millisecond: 999\n    +hour: 0\n    +minute: 32\n    +second: 0\n  }\n]\n```\n\nEach class implements `Stringable` interface.\n\n`TomlLocal*` classes are marked with `TomlDateTimeInterface` for usability. Each class has public properties.\n\nThere is `TomlDateTime` class to support TOML offset date time format also.\n\nOf course any `DateTimeInterface` or `TomlDateTimeInterface` are encoded into TOML datetime string.\nSo\n\n```php\n$data = [\n    'DateTimeInterface' =\u003e new DateTimeImmutable('1979-05-27T07:32:00Z'),\n    'TomlDateTimeInterface' =\u003e new TomlDateTime('1979-05-27T07:32:00Z'),\n];\n```\n\nwill be encoded into\n\n```toml\nDateTimeInterface = 1979-05-27T07:32:00.000Z\nTomlDateTimeInterface = 1979-05-27T07:32:00.000Z\n```\n\n## About informative errors\n\nIf there is parsing error, `TomlError` has the approximate location of the problem in the message.\nSomething like:\n\n```sh\nInvalid TOML document: unexpected non-numeric value\n\n5:  [owner]\n6:  name = Tom Preston-Werner\n             ^\n7:  dob = 1979-05-31T07:32:00-08:00\n```\n\nElse it has message about whole input.\n\n## About floating-point values\n\nThe decoder returns each floating-point value as a string by default.\n\nYou can force it to return a float type by setting the **$asFloat** argument:\n\n```php\ntoml_decode($toml, asFloat: true);\n// or\n\\Devium\\Toml\\Toml::decode($toml, asFloat: true);\n```\n\n## About NULL\n\n**TOML does not support null values.**\n\nIf the array contains a null value, an exception will be thrown.\n\nThe only thing possible is a null value for the keys in the tables. Such keys are simply skipped during encoding.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request\n\n## License\n\n**devium/toml** is open-sourced software licensed under the [MIT license](./LICENSE.md).\n\n[Vano Devium](https://github.com/vanodevium/)\n\n---\n\nMade with ❤️ in Ukraine\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanodevium%2Ftoml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvanodevium%2Ftoml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvanodevium%2Ftoml/lists"}