public function __construct($filename, DiffMonitor $monitor)
 {
     $factory = Inject::the(new SSLRepo());
     $monitor->setFilename($filename);
     $monitor->setPrototype($factory->newHistoryIndexDom());
     $monitor->setDiffDelegate($this);
 }
 protected function checkForNewFilename()
 {
     $got_new_file = parent::checkForNewFilename();
     if ($got_new_file) {
         unset($this->tail_parser);
     }
     return $got_new_file;
 }
 /**
  * The main entry point to the application. Start here!
  * When this returns, the program is done.
  * 
  * Program flow:
  * * Parse options
  * * Set up logging, if requested
  * * Ask plugins to do any early setup - this is where Last.fm / Twitter do OAuth etc
  * * If no filename was supplied, either wait for a new one to be created in the default 
  *   ScratchLive history folder (polls every 2 seconds), or go for the most recent 
  *   (when --immediate is specified). 
  * * If --dump was specified, display the structure of the file and exit. (Very useful for
  *   probing ScratchLive files).
  * * Otherwise, start monitoring the file.
  * 
  * @param $argc (from GLOBAL)
  * @param $argv (from GLOBAL)
  */
 public function main($argc, array $argv)
 {
     date_default_timezone_set('UTC');
     mb_internal_encoding('UTF-8');
     try {
         $this->parseOptions($argv);
         // do this as early as possible, but not before parsing options which may affect it.
         $this->setupLogging();
         if ($this->help) {
             $this->usage($this->appname, $argv);
             return;
         }
         // yield CLI configured plugins.
         foreach ($this->cli_plugins as $plugin) {
             /* @var $plugin CLIPlugin */
             $plugin->addPluginsTo($this->plugin_manager);
         }
         $this->cli_plugins = array();
         $this->plugin_manager->onSetup();
         $filename = $this->filename;
         if (empty($filename)) {
             // guess history file (always go for the most recently modified)
             $this->historydir = $this->getDefaultHistoryDir();
             if ($this->wait_for_file) {
                 echo "Waiting for new session file...\n";
                 // find the most recent file, then wait for a new one to be created and use that.
                 $first_filename = $this->getMostRecentFile($this->historydir, 'session');
                 $second_filename = $first_filename;
                 while ($second_filename == $first_filename) {
                     sleep($this->sleep);
                     $second_filename = $this->getMostRecentFile($this->historydir, 'session');
                 }
                 $filename = $second_filename;
             } else {
                 $filename = $this->getMostRecentFile($this->historydir, 'session');
             }
             echo "Using file {$filename} ...\n";
         }
         if (!file_exists($filename)) {
             throw new InvalidArgumentException("No such file {$filename}.");
         }
         if (!is_readable($filename)) {
             throw new InvalidArgumentException("File {$filename} not readable.");
         }
         if ($this->dump_and_exit) {
             $monitor = new DiffMonitor();
             switch ($this->dump_type) {
                 case 'sessionfile':
                     $hfm = new SSLHistoryFileMonitor($filename, $monitor);
                     break;
                 case 'sessionindex':
                     $hfm = new SSLHistoryIndexFileMonitor($filename, $monitor);
                     break;
                 case 'library':
                     $hfm = new SSLLibraryFileMonitor($filename, $monitor);
                     break;
                 default:
                     throw new RuntimeException('Unknown dump type. Try sessionfile, sessionindex, library');
             }
             $monitor->dump();
             return;
         }
         if ($this->post_process) {
             $this->post_process($filename);
         } else {
             // start monitoring.
             $this->monitor($filename);
         }
     } catch (Exception $e) {
         echo $e->getMessage() . "\n";
         if ($this->verbosity > L::INFO) {
             echo $e->getTraceAsString() . "\n";
         }
         echo "Try {$this->appname} --help\n";
     }
 }