Commit 9535e519 authored by yosymfony's avatar yosymfony
Browse files

TomlBuilder does not throw a DumpException anymore when the character "#" appears in a quoted key.

The method addArrayTables from the class TomlBuilder has been declared as deprecated. Use the method addArrayOfTable instead.
parent 23c81b1d
CHANGELOG
=========
1.0.3
-----
* `TomlBuilder` does not throw a `DumpException` anymore when the character "#" appears in a quoted key.
* The method `addArrayTables` from the class `TomlBuilder` has been declared as deprecated. Use `addArrayOfTable` instead.
1.0.2 (2018-06-29)
------------------
* Fixed the bug #23: "Unable to parse ArrayTables that contain Tables".
......
......@@ -94,15 +94,15 @@ You can create a TOML string with TomlBuilder. TomlBuilder uses a *fluent interf
->addComment('Array of tables')
->addArrayTables('fruit') // Row
->addArrayOfTable('fruit') // Row
->addValue('name', 'apple')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'red delicious')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'granny smith')
->addArrayTables('fruit') // Row
->addArrayOfTable('fruit') // Row
->addValue('name', 'banana')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'plantain')
->getTomlString(); // Generate the TOML string
......@@ -156,6 +156,11 @@ The result:
[[fruit.variety]]
name = "plantain"
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.
......
......@@ -32,9 +32,9 @@ class TomlBuilder
protected $prefix = '';
protected $output = '';
protected $currentLine = 0;
protected $keyList = array();
protected $keyListArryOfTables = array();
protected $keyListInvalidArrayOfTables = array();
protected $keyList = [];
protected $keyListArryOfTables = [];
protected $keyListInvalidArrayOfTables = [];
protected $currentTable = '';
protected $currentArrayOfTables = '';
protected $currentKey = null;
......@@ -60,10 +60,6 @@ class TomlBuilder
*/
public function addValue(string $key, $val, string $comment = null) : TomlBuilder
{
if (strpos($key, '#')) {
throw new DumpException(sprintf('Character "#" is not valid for the key.'));
}
if (preg_match('/^([-A-Z_a-z0-9]+)$/', $key) === 0) {
$key = '"'.$key.'"';
}
......@@ -115,13 +111,22 @@ class TomlBuilder
}
/**
* Adds an array of tables
* This method has been marked as deprecated and will be deleted in version 2.0.0
* @deprecated 2.0.0 Use the method "addArrayOfTable" instead
*/
public function addArrayTables(string $key) : TomlBuilder
{
return $this->addArrayOfTable($key);
}
/**
* Adds an array of tables element
*
* @param string $key The name of the array of tables
*
* @return TomlBuilder The TomlBuilder itself
*/
public function addArrayTables(string $key) : TomlBuilder
public function addArrayOfTable(string $key) : TomlBuilder
{
$addPreNewline = $this->currentLine > 0 ? true : false;
......
......@@ -101,16 +101,6 @@ class TomlBuilderInvalidTest extends TestCase
->getTomlString();
}
/**
* @expectedException Yosymfony\Toml\Exception\DumpException
*/
public function testInvalidKey()
{
$tb = new TomlBuilder();
$tb->addValue('value#1', '2')
->getTomlString();
}
/**
* @expectedException Yosymfony\Toml\Exception\DumpException
*/
......@@ -127,9 +117,9 @@ class TomlBuilderInvalidTest extends TestCase
public function testTableArrayImplicit()
{
$tb = new TomlBuilder();
$tb->addArrayTables('albums.songs')
$tb->addArrayOfTable('albums.songs')
->addValue('name', 'Glory Days')
->addArrayTables('albums')
->addArrayOfTable('albums')
->addValue('name', 'Born in the USA')
->getTomlString();
}
......@@ -140,9 +130,9 @@ class TomlBuilderInvalidTest extends TestCase
public function testTableArrayWithSomeNameOfTable()
{
$tb = new TomlBuilder();
$tb->addArrayTables('fruit')
$tb->addArrayOfTable('fruit')
->addValue('name', 'apple')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'red delicious')
->addTable('fruit.variety')
->addValue('name', 'granny smith')
......
......@@ -201,16 +201,16 @@ class TomlBuilderTest extends TestCase
{
$tb = new TomlBuilder();
$result = $tb->addArrayTables('fruit')
$result = $tb->addArrayOfTable('fruit')
->addValue('name', 'apple')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'red delicious')
->addArrayTables('fruit.variety')
->addArrayOfTable('fruit.variety')
->addValue('name', 'granny smith')
->addArrayTables('fruit')
->addArrayOfTable('fruit')
->addValue('name', 'banana')
->addArrayTables('fruit.variety')
->addValue('name', 'platain')
->addArrayOfTable('fruit.variety')
->addValue('name', 'plantain')
->getTomlString();
$this->assertNotNull(Toml::Parse($result));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment