Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Implemented option to process INI sections or not #58

Merged
merged 7 commits into from
May 20, 2019
Merged

Implemented option to process INI sections or not #58

merged 7 commits into from
May 20, 2019

Conversation

arueckauer
Copy link
Contributor

@arueckauer arueckauer commented Mar 28, 2019

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.

  • Are you creating a new feature? Yes
    • Why is the new feature needed? What purpose does it serve? See description above
    • How will users use the new feature? See docs/book/reader.md in the INI section
    • Base your feature on the develop branch, and submit against that branch. Check
    • Add only one feature per pull request; split multiple features over multiple pull requests Check
    • Add tests for the new feature. Check
    • Add documentation for the new feature. Check
    • Add a CHANGELOG.md entry for the new feature.

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

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

I think it is nice feature. I like the changes that we are keeping BC and that you've provided the documentation.

We are missing test for fromString method, we should add them as well.

I was checking the php docs and I have found there also 3rd parameter, so maybe we should add it here as well (probably as separate PR later on if we want to have it).

See my small comments in the PR. In general: nice job 👍

@Xerkus Xerkus modified the milestone: 3.3.0 May 14, 2019
@Xerkus
Copy link
Member

Xerkus commented May 20, 2019

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
Copy link
Member

Xerkus commented May 20, 2019

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
Copy link
Contributor Author

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
Copy link
Member

Xerkus commented May 20, 2019

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
Copy link
Member

Xerkus commented May 20, 2019

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

@Xerkus Xerkus added this to the 3.3.0 milestone May 20, 2019
@Xerkus Xerkus merged commit c654be5 into zendframework:develop May 20, 2019
Xerkus added a commit that referenced this pull request May 20, 2019
@Xerkus
Copy link
Member

Xerkus commented May 20, 2019

@arueckauer thank you

@arueckauer
Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants