*  Dependencies
 */
require_once 'LineCount.php';
/**
 *  The WordCount class wrote its output to a file on the distributed file
 *  system. To find out what the absolute path name of this file is on this
 *  machine, we make use of the Yothalot\Path class to turn the relative name
 *  into an absolute path (GlusterFS must be mounted on this machine)
 *
 *  @var Yothalot\Path
 */
$path = new Yothalot\Path("linecount-results.txt");
/**
 *  Unlink the result upon start, to make sure that we don't display the previous result.
 */
unlink($path->absolute());
/**
 *  Create an instance of the WordCount algorithm
 *  @var WordCount
 */
$wordcount = new LineCount($path->relative());
/**
 *  We want to send this WordCount instance to the Yothalot master. To do this,
 *  we need an instance of this master object.
 *
 *  (Under the hood, you do not connect with the Yothalot master process, but to
 *  a RabbitMQ message queue, the login details are therefore the RabbitMQ
 *  details)
 *
 *  @var Yothalot\Master
 */
 /**
  *  The final step in the reducer process calls the write() method once for
  *  every found key, and for each reduced value.
  *
  *  In this specific WordCount example, the key is a word, and the
  *  value the total number of occurances
  *
  *  @param  mixed       The key for which the result comes in
  *  @param  mixed       Fully reduced value
  */
 function write($key, $value)
 {
     // the output file is stored on the gluster
     $path = new Yothalot\Path($this->output);
     // open an output file
     $output = new Yothalot\Output($path->absolute());
     // add the key and value
     $output->kv($key, $value);
 }
 /**
  *  The final step in the reducer process calls the write() method once for
  *  every found key, and for each reduced value.
  *
  *  In this specific WordCount example, the key is a word, and the
  *  value the total number of occurances
  *
  *  @param  mixed       The key for which the result comes in
  *  @param  mixed       Fully reduced value
  */
 function write($key, $value)
 {
     // the output file is stored on the gluster
     $path = new Yothalot\Path($this->output);
     // write the key value pair to a file
     file_put_contents($path->absolute(), "{$key}: {$value}\n", FILE_APPEND);
 }
 /**
  *  The final step in the reducer process calls the write() method once for
  *  every found key, and for each reduced value.
  *
  *  In this specific WordCount example, the key is a word, and the
  *  value the total number of occurrences
  *
  *  @param  mixed       The key for which the result comes in
  *  @param  mixed       Fully reduced value
  */
 public function write($key, $value)
 {
     // if we've not added the file yet
     if (!$this->file) {
         // the output file is stored on the gluster
         $path = new Yothalot\Path($this->output);
         // open the file
         $this->file = fopen($path->absolute(), "w+");
     }
     // write to the file
     fwrite($this->file, "{$key}: {$value}\n");
 }