2017 © Pedro Peláez
 

library toml

A PHP parser for TOML compatible with specification 0.4.0

image

yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  • Thursday, August 2, 2018
  • by yosymfony
  • Repository
  • 5 Watchers
  • 101 Stars
  • 89,485 Installations
  • PHP
  • 23 Dependents
  • 7 Suggesters
  • 13 Forks
  • 3 Open issues
  • 13 Versions
  • 5 % Grown

The README.md

TOML parser for PHP

A PHP parser for TOML compatible with TOML v0.4.0., (*1)

Build Status Latest Stable Version Total Downloads, (*2)

Support:, (*3)

Gitter, (*4)

Installation

Requires PHP >= 7.1., (*5)

Use Composer to install this package:, (*6)

composer require yosymfony/toml

Usage

You can parse an inline TOML string or from a file:, (*7)

To parse an inline TOML string:, (*8)

use Yosymfony\Toml\Toml;

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

print_r($array);

To parse a TOML file:, (*9)

$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., (*10)

$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:, (*11)

    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:, (*12)

#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., (*13)

Deprecated method

The following method will be eliminated in version 2.0.0 * [TomlBuilder] addArrayTables, (*14)

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., (*15)

Unit tests

You can run the unit tests with the following command:, (*16)

$ cd toml
$ composer test

License

This library is open-sourced software licensed under the MIT license., (*17)

The Versions

02/08 2018

dev-master

9999999-dev http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

 

The Development Requires

parser toml mojombo

31/07 2018

v1.0.3

1.0.3.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

 

The Development Requires

parser toml mojombo

30/06 2018

v1.0.2

1.0.2.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

 

The Development Requires

parser toml mojombo

05/02 2018

v1.0.1

1.0.1.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

 

parser toml mojombo

19/11 2017

0.x-dev

0.9999999.9999999.9999999-dev http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

18/11 2017

v1.0.0

1.0.0.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

 

parser toml mojombo

24/08 2015

v0.3.3

0.3.3.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

09/03 2015

v0.3.2

0.3.2.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

07/03 2015

v0.3.1

0.3.1.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

06/03 2015

v0.3.0

0.3.0.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

03/05 2014

v0.2.0

0.2.0.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with specification 0.2.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

14/12 2013

v0.1.1

0.1.1.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with TOML v0.1.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

parser toml mojombo

02/06 2013

v0.1.0

0.1.0.0 http://github.com/yosymfony/toml

A PHP parser for TOML compatible with TOML v0.1.0

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

toml