Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new function build Toml string from a multidimensional array automatically #26

Closed

Conversation

jkhhjkhiukhjhukjhkh
Copy link

This function used your existed function TomlBuilder.
I also found the bug #24.

Example:

$array = [
        'a1' => [
            'b1' => [
                'c1'=>[
                    'c1'=>[
                        'c1'=>0
                    ]
                ]
            ],
            'b2' => 2,
        ],
        'a2' => [
            [
                'b1' => [
                    'c1' => [
                        'd1'=>[
                            'd1'=>[
                                1,2,3
                            ]
                        ]
                    ],
                    'c2' => 100
                ]
            ],
            [
                'b2' => [
                    'c1' => 200,
                    'c2' => 200,
                ]
            ]
        ],
    ];
    $tbfa = new \Yosymfony\Toml\TomlBuilderFromArray($config);
    $result1 = $tbfa->convert();
    $result2 = \Yosymfony\Toml\Toml::parse($result1);

The result1:

[a1]
b2 = 2

[a1.b1]

[a1.b1.c1]

[a1.b1.c1.c1]
c1 = 0

[[a2]]

[a2.b1]
c2 = 100

[a2.b1.c1]

[a2.b1.c1.d1]
d1 = [1, 2, 3]

[[a2]]

[a2.b2]
c1 = 200
c2 = 200

The result2:

array(
    'a1' =>
        array(
            'b2' => 2,
            'b1' =>
                array(
                    'c1' =>
                        array(
                            'c1' =>
                                array(
                                    'c1' => 0,
                                ),
                        ),
                ),
        ),
    'a2' =>
        array(
            0 =>
                array(
                    'b1' =>
                        array(
                            'c2' => 100,
                            'c1' =>
                                array(
                                    'd1' =>
                                        array(
                                            'd1' =>
                                                array(
                                                    0 => 1,
                                                    1 => 2,
                                                    2 => 3,
                                                ),
                                        ),
                                ),
                        ),
                ),
            1 =>
                array(
                    'b2' =>
                        array(
                            'c1' => 200,
                            'c2' => 200,
                        ),
                ),
        ),
)

* @param $arr array|object
* @return array|object
*/
private static function postProcess(&$arr)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on this bug

@yosymfony
Copy link
Owner

Sorry but I guess It's not so complicated to transform any array into a Toml file using the existing TomlBuilder's methods so to add a new method to build from a multidimensional array automatically is unnecessary.

The bug #24 has already been fixed.

Thanks.

@yosymfony yosymfony closed this Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants