Provide fluent interface #6

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

Comments

Projects
None yet
2 participants

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.

Owner

cpliakas commented Mar 13, 2012

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