All Projects → yosymfony → Toml

yosymfony / Toml

Licence: mit
A PHP parser for TOML

Projects that are alternatives of or similar to Toml

climatecontrol
Python library for loading settings and config data from files and environment variables
Stars: ✭ 20 (-86.84%)
Mutual labels:  toml, configuration
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (+196.05%)
Mutual labels:  toml, configuration
tomlj
A Java parser for Tom's Obvious, Minimal Language (TOML).
Stars: ✭ 72 (-52.63%)
Mutual labels:  toml, configuration
paerser
No description or website provided.
Stars: ✭ 38 (-75%)
Mutual labels:  toml, configuration
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (-48.68%)
Mutual labels:  toml, configuration
go-config
Configuration file loader for Go
Stars: ✭ 27 (-82.24%)
Mutual labels:  toml, configuration
tomland
🏝 Bidirectional TOML serialization
Stars: ✭ 103 (-32.24%)
Mutual labels:  toml, configuration
parse it
A python library for parsing multiple types of config files, envvars & command line arguments that takes the headache out of setting app configurations.
Stars: ✭ 86 (-43.42%)
Mutual labels:  toml, configuration
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-68.42%)
Mutual labels:  toml, configuration
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+501.97%)
Mutual labels:  toml, configuration
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+48.03%)
Mutual labels:  toml, configuration
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-6.58%)
Mutual labels:  toml, configuration
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (+8.55%)
Mutual labels:  toml, configuration
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-88.16%)
Mutual labels:  toml, configuration
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+399.34%)
Mutual labels:  toml, configuration
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-38.82%)
Mutual labels:  toml, configuration
Staert
Merge your configuration sources
Stars: ✭ 108 (-28.95%)
Mutual labels:  toml, configuration
Config
Manage Laravel configuration by persistent storage
Stars: ✭ 139 (-8.55%)
Mutual labels:  configuration
Gcfg
read INI-style configuration files into Go structs; supports user-defined types and subsections
Stars: ✭ 146 (-3.95%)
Mutual labels:  configuration
Surfingkeys Conf
A SurfingKeys configuration which adds 130+ key mappings for 20+ sites & OmniBar search suggestions for 50+ sites
Stars: ✭ 137 (-9.87%)
Mutual labels:  configuration

TOML parser for PHP

A PHP parser for TOML compatible with TOML v0.4.0.

Build Status Latest Stable Version Total Downloads

Support:

Gitter

Installation

Requires PHP >= 7.1.

Use Composer to install this package:

composer require yosymfony/toml

Usage

You can parse an inline TOML string or from a file:

To parse an inline TOML string:

use Yosymfony\Toml\Toml;

$array = Toml::Parse('key = [1,2,3]');

print_r($array);

To parse a TOML file:

$array = Toml::ParseFile('example.toml');

print_r($array);

Additionally, methods parse and parseFile accept a second argument called resultAsObject to return the result as an object based on stdClass.

$object = Toml::Parse('key = [1,2,3]', true);

TomlBuilder

You can create a TOML string with TomlBuilder. TomlBuilder uses a fluent interface for more readable code:

    use Yosymfony\Toml\TomlBuilder;

    $tb = new TomlBuilder();

    $result = $tb->addComment('Toml file')
        ->addTable('data.string')
        ->addValue('name', "Toml", 'This is your name')
        ->addValue('newline', "This string has a \n new line character.")
        ->addValue('winPath', "C:\\Users\\nodejs\\templates")
        ->addValue('literal', '@<\i\c*\s*>') // literals starts with '@'.
        ->addValue('unicode', 'unicode character: ' . json_decode('"\u03B4"'))

        ->addTable('data.bool')
        ->addValue('t', true)
        ->addValue('f', false)

        ->addTable('data.integer')
        ->addValue('positive', 25, 'Comment inline.')
        ->addValue('negative', -25)

        ->addTable('data.float')
        ->addValue('positive', 25.25)
        ->addValue('negative', -25.25)

        ->addTable('data.datetime')
        ->addValue('datetime', new \Datetime())

        ->addComment('Related to arrays')

        ->addTable('data.array')
        ->addValue('simple', array(1,2,3))
        ->addValue('multiple', array(
            array(1,2),
            array('abc', 'def'),
            array(1.1, 1.2),
            array(true, false),
            array( new \Datetime()) ))

        ->addComment('Array of tables')

        ->addArrayOfTable('fruit')                            // Row
            ->addValue('name', 'apple')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'red delicious')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'granny smith')
        ->addArrayOfTable('fruit')                            // Row
            ->addValue('name', 'banana')
            ->addArrayOfTable('fruit.variety')
                ->addValue('name', 'plantain')
        ->getTomlString();    // Generate the TOML string

The result:

#Toml file

[data.string]
name = "Toml" #This is your name
newline = "This string has a \n new line character."
winPath = "C:\\Users\\nodejs\\templates"
literal = '<\i\c*\s*>'
unicode = "unicode character: δ"

[data.bool]
t = true
f = false

[data.integer]
positive = 25 #Comment inline.
negative = -25

[data.float]
positive = 25.25
negative = -25.25

[data.datetime]
datetime = 2013-06-10T21:12:48Z

#Related to arrays

[data.array]
simple = [1, 2, 3]
multiple = [[1, 2], ["abc", "def"], [1.1, 1.2], [true, false], [2013-06-10T21:12:48Z]]

# Array of tables

[[fruit]]
name = "apple"

[[fruit.variety]]
name = "red delicious"

[[fruit.variety]]
name = "granny smith"

[[fruit]]
name = "banana"

[[fruit.variety]]
name = "plantain"

Limitations

The TomlBuilder class is an utility to get Toml strings that has the following limitations:

  • Only admits basic strings and literal strings.

Deprecated method

The following method will be eliminated in version 2.0.0

  • [TomlBuilder] addArrayTables

Contributing

When Contributing code to this library, you must follow its coding standards. Toml follows PSR-2 coding style. To ensure the CS, you can use the CLI tool PHP-CS-Fixer.

Unit tests

You can run the unit tests with the following command:

$ cd toml
$ composer test

License

This library is open-sourced software licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].