Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 18854 программиста и 2023 робота. Сейчас ищут 1433 программиста ...
PHP_CompatInfo::addListener
Вернуться к: Observers
PHP_CompatInfo::addListener
PHP_CompatInfo::addListener() – Registers a new listener
Synopsis
require_once 'PHP/CompatInfo.php';
void PHP_CompatInfo::addListener ( mixed $callback , string $nName = EVENT_DISPATCHER_GLOBAL )
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.
<?php
require_once 'PHP/CompatInfo.php';
define('DEST_PCI_LOG', '/var/log/pciEvents.log');
function debugNotify(&$auditEvent)
{
$notifyName = $auditEvent->getNotificationName();
$notifyInfo = $auditEvent->getNotificationInfo();
if ($notifyName == PHP_COMPATINFO_EVENT_AUDITSTARTED) {
error_log($notifyName.':'. PHP_EOL .
var_export($notifyInfo, true) . PHP_EOL,
3, DEST_PCI_LOG);
} elseif ($notifyName == PHP_COMPATINFO_EVENT_AUDITFINISHED) {
error_log($notifyName.':'. PHP_EOL .
var_export($notifyInfo, true) . PHP_EOL,
3, DEST_PCI_LOG);
}
}
$cbObserver = 'debugNotify';
$pci = new PHP_CompatInfo();
$pci->addListener($cbObserver);
// ...
$source = ''; // <- identify the date source to parse
$options = array(); // <- some parser options
$pci->parseData($source, $options);
$pci->removeListener($cbObserver);
?>
Вернуться к: Observers