PEAR logo

PHP_CompatInfo : The Definitive Guide

Name

PHP_CompatInfo::addListener — Registers a new listener

Synopsis

    require_once 'PHP/CompatInfo.php';
   
void PHP_CompatInfo::addListener ( $callback,  
  $nName = EVENT_DISPATCHER_GLOBAL );  
mixed   $callback ;
string   $nName = EVENT_DISPATCHER_GLOBAL ;

Description

Registers a new listener with the given criteria

Parameter

mixed $callback

A PHP callback

string $nName

(optional) Expected notification name

Return value

returns void

Throws

throws no exceptions thrown

Since

since version 1.8.0b3 (2008-06-07)

Note

This function can not be called statically.

Example

Attach a simple function that will listen all PHP_CompatInfo events, which write start and end audit results in a flat file defined by a php constant.

  1. <?php
  2. require_once 'PHP/CompatInfo.php';
  3.  
  4. define('DEST_PCI_LOG', '/var/log/pciEvents.log');
  5.  
  6. function debugNotify(&$auditEvent)
  7. {
  8.     $notifyName = $auditEvent->getNotificationName();
  9.     $notifyInfo = $auditEvent->getNotificationInfo();
  10.  
  11.     if ($notifyName == PHP_COMPATINFO_EVENT_AUDITSTARTED) {
  12.         error_log($notifyName.':'. PHP_EOL .
  13.                   var_export($notifyInfo, true) . PHP_EOL,
  14.                   3, DEST_PCI_LOG);
  15.  
  16.     } elseif ($notifyName == PHP_COMPATINFO_EVENT_AUDITFINISHED) {
  17.         error_log($notifyName.':'. PHP_EOL .
  18.                   var_export($notifyInfo, true) . PHP_EOL,
  19.                   3, DEST_PCI_LOG);
  20.     }
  21. }
  22.  
  23. $cbObserver = 'debugNotify';
  24.  
  25. $pci = new PHP_CompatInfo();
  26. $pci->addListener($cbObserver);
  27. // ...
  28. $source  = '';      // <- identify the date source to parse
  29. $options = array(); // <- some parser options
  30.  
  31. $pci->parseData($source, $options);
  32.  
  33. $pci->removeListener($cbObserver);
  34. ?>
PHP_CompatInfo : The Definitive Guide v 1.8.0 : August 1, 2008