PHP code example of onoi / message-reporter

1. Go to this page and download the library: Download onoi/message-reporter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onoi / message-reporter example snippets


use Onoi\MessageReporter\MessageReporterFactory;
use Onoi\MessageReporter\MessageReporterAware;
use Onoi\MessageReporter\MessageReporterAwareTrait;

class Bar implements MessageReporterAware {

	use MessageReporterAwareTrait;

	public function __construct() {
		$this->messageReporter = MessageReporterFactory::getInstance()->newNullMessageReporter();
	}

	public function doSomething() {
		$this->messageReporter->reportMessage( 'Doing ...' );
	}
}

use Onoi\MessageReporter\MessageReporterFactory;
use Onoi\MessageReporter\MessageReporter;

class Foo implements MessageReporter {

	public function reportMessage( $message ) {
		// output
	}
}

$foo = new Foo();

$messageReporterFactory = new MessageReporterFactory();

$observableMessageReporter = $messageReporterFactory->newObservableMessageReporter();
$observableMessageReporter->registerReporterCallback( array( $foo, 'reportMessage' ) );

or

// If the class implements the MessageReporter
$observableMessageReporter->registerMessageReporter( $foo );

$bar = new Bar();
$bar->setMessageReporter( $observableMessageReporter );