cpliakas / nagiostatus

PHP parser library for the Nagios status.dat file.
GNU General Public License v2.0
1 stars 0 forks source link

Provide fluent interface #6

Open ebeyrent opened 12 years ago

ebeyrent commented 12 years ago

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 commented 12 years ago

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.