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

New Piwik Ini component #6939

Merged
merged 3 commits into from Jan 9, 2015
Merged

New Piwik Ini component #6939

merged 3 commits into from Jan 9, 2015

Conversation

mnapoli
Copy link
Contributor

@mnapoli mnapoli commented Jan 7, 2015

This PR is a suggestion for a new Piwik component to read and write INI configurations.

The new component contains 2 classes:

  • IniReader: content extracted from the shim in upgrade.php that makes it work even if the native PHP function is disabled
  • IniWriter: content extracted from Config (so it clears up this class a little bit)

Just like Symfony Yaml, I think this INI component could be interesting to be shipped as a standalone component. It's a good example of a small reusable one.

Here is the advantages of this component that I would write in its README:

  • allows to read and write (no native PHP function to write INI files)
  • the classes are mockable in unit tests
  • works even if parse_ini_file() is disabled
  • throws exceptions instead of errors (can be easily catched, less if ( === false)…)
  • boolean support when parsing: true, yes, on are actually converted to true instead of 1, same for false, no, off

Here is the advantage for us:

Thoughts?

@mnapoli mnapoli added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Jan 7, 2015
@mnapoli mnapoli self-assigned this Jan 7, 2015
@mattab
Copy link
Member

mattab commented Jan 7, 2015

Great idea, this change makes our code less cluttered and cleaner, and also will benefit the community, it is a great move 👍

(fyi didn't review the code in detail, but I love that we will have tests now!)

@Globulopolis
Copy link
Contributor

@mnapoli you say "works even if parse_ini_file() is disabled" - maybe we need to add some checks if function exists instead of writing own function, because native function much faster.

And $array = @parse_ini_string($ini, true, INI_SCANNER_RAW); what is it? Suppress an error output is bad idea I'm think.

@mnapoli
Copy link
Contributor Author

mnapoli commented Jan 7, 2015

@Globulopolis thanks for the feedback.

It does use the native PHP function, the shim is just used if the function is disabled.

Regarding @parse_ini_string(...) suppressing an error would be bad if it was just suppressed, but:

$array = @parse_ini_string($ini, true, INI_SCANNER_RAW);

if ($array === false) {
    $e = error_get_last();
    throw new IniReadingException('Syntax error in INI configuration: ' . $e['message']);
}

I'm actually checking for the error just afterwards and turning it into an exception. So the error is not silenced, it's turned into an exception.

@mnapoli mnapoli added the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Jan 8, 2015
@mnapoli
Copy link
Contributor Author

mnapoli commented Jan 8, 2015

The new component is here: https://github.com/piwik/component-ini

@mnapoli mnapoli removed the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Jan 8, 2015
@mattab
Copy link
Member

mattab commented Jan 9, 2015

Nice, gotta love new small reusable components keeping the core lean 👍

mattab pushed a commit that referenced this pull request Jan 9, 2015
@mattab mattab merged commit 1289cd9 into master Jan 9, 2015
@mnapoli mnapoli deleted the ini-component branch January 9, 2015 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants