jamesmoss / toml
A parser for TOML implemented in PHP.
Installs: 22 830
Dependents: 14
Suggesters: 12
Security: 0
Stars: 32
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-11-20 21:28:01 UTC
README
A parser for TOML written in PHP. Currently supports 100% of the TOML spec: dates, multiline arrays, key groups - the lot (including all of the more minor restrictions such as same-type arrays and key group override rules).
Requirements
- PHP 5.3
- Composer
Installation
Use Composer to install the Toml package. Package details can be found on Packagist.org.
Add the following to your composer.json
and run composer update
.
"require": {
//...
"jamesmoss/toml": "dev-master"
}
You can use this lib without Composer but you'll need to provide your own PSR-0 compatible autoloader. Really, you should just use Composer.
Use
Toml\Parser
has two static methods fromString
and fromFile
, which are self explanatory. Both return an associative array. If your TOML doc can't be parsed an Exception
will be thrown with a useful error message.
use Toml\Parser;
// Load directly from a string
$toml = Parser::fromString('name = "James Moss"');
var_dump($toml['name']); // outputs 'James Moss'.
// Load from a file instead
$toml = Parser::fromFile(__DIR__ . '/config.toml');
Running tests
There is 100% test coverage at the moment. If you'd like to run the tests yourself, use the following:
$ composer update
$ phpunit
Contributing
The TOML spec is changing often as it's in its infancy; if you spot something I've missed fork this repo, create a new branch and submit a pull request. Make sure any features you add are covered by unit tests.
Todo
- Better documentation and docblocks
- More semantic exceptions to be thrown, standardise the error message format.