zendframework / zend-config

Config component from Zend Framework
BSD 3-Clause "New" or "Revised" License
90 stars 38 forks source link

Implemented option to process INI sections or not #58

Closed arueckauer closed 5 years ago

arueckauer commented 5 years ago

By default the INI reader is processing sections. It is not possible to merge sections, which is the default behavior of parse_ini_file().

This PR introduces the protected property $processSections with a public getter and setter. It enables users to tell the reader not to process sections by setting $processSections to false. The default behavior of the reader does not change.

Xerkus commented 5 years ago

This PR in fact breaks ini reader. By setting flag to false, top level keys are then processed as sections and since sections are discarded by php function, reader added functionality no longer works.

Xerkus commented 5 years ago

I had to dig through code and I see that sections are not treated differently to regular keys anymore, extending section functionality is gone.

The only case that is affected is when sections using delimited format:

[section.with.subkeys]
key=value

is equivalent to $config['section']['with']['subkeys']['key'] = 'value';

Result with section names like that would be very different from result with sections not processed and merged by parse_ini_*() function.

arueckauer commented 5 years ago

I am not able to follow. How should the corresponding array to the following INI look like? And how does this PR change the current behavior of the Ini Reader?

[section.with.subkeys]
key=value

https://3v4l.org/SlF9Q

Xerkus commented 5 years ago

Here is how it is handled by reader:

$ php -a
Interactive shell

php > require "vendor/autoload.php";
php > $ini = <<<ECS
<<< > [environments.production]
<<< > env='production'
<<< > production_key='foo'
<<< > 
<<< > [environments.staging]
<<< > env='staging'
<<< > staging_key='bar'
<<< > ECS;
php > $reader = new Zend\Config\Reader\Ini();
php > print_r($reader->fromString($ini));
Array
(
    [environments] => Array
        (
            [production] => Array
                (
                    [env] => production
                    [production_key] => foo
                )

            [staging] => Array
                (
                    [env] => staging
                    [staging_key] => bar
                )

        )

)
Xerkus commented 5 years ago

I rebased to current develop and added tests for the nesting in section names. Sorry, I dropped your latest commit in doing so.

Xerkus commented 5 years ago

@arueckauer thank you

arueckauer commented 5 years ago

My pleasure! Thank you for a thorough check and the feedback.