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

Provide fluent interface #6

Open
ebeyrent opened this issue Mar 13, 2012 · 1 comment
Open

Provide fluent interface #6

ebeyrent opened this issue Mar 13, 2012 · 1 comment

Comments

@ebeyrent
Copy link

It'd be nice if the Parser provided a fluent interface so you could do:

<?php
  $document = new SimpleXMLElement(Nagiostatus_Parser::instance('/usr/local/nagios/var/status.dat')
    ->render('xml', true));
?>

You could also chain your registerPlugin() calls instead of making them static methods.

@cpliakas
Copy link
Owner

I like the getInstance() pattern and think that would be a good addition. In regards to the registerPlugin() method, it is static because it is designed to register plugins across all parser instances. For example, let's say you have 4 monitoring servers with 4 different files that you wanted to output as CSV files (CSV doesn't really make sense, but bear with me). With the static method you can register the plugin once and have it be available to all instances. In addition, you can set the default plugin to be "csv" so that you only have to call $parser->render(). If you decide to change the output to XML down the road, you can set the default plugin in one place and have all parsers effected.

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

No branches or pull requests

2 participants