Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.27 KB

README.md

File metadata and controls

59 lines (44 loc) · 1.27 KB

Observer implementations

TAO-Core observer implementations. They support native PHP SplObserver and SplSubject.

LoggerObserver

Used in case you want to notify the subject for logging purposes.

Example

$observer = new \oat\tao\model\Observer\Log\LoggerObserver($logger);

$anySubject = new \oat\tao\model\Observer\Subject(
    [
        'some' => 'data',
        'another' => 'data',
    ]
)
$anySubject->attach($observer);
$anySubject->notify(); // Will log subject data...

PubSubObserver

Used in case you want to notify GCP Pub/Sub service.

Requirements:

Install GCP lib:

php composer.phar require "google/cloud-pubsub":"1.34.*" -vvv

Example

$factory = (new \oat\tao\model\Observer\GCP\PubSubClientFactory())->create();

$observer = new \oat\tao\model\Observer\GCP\PubSubObserver(
    $client,
    $logger,
    [
        \oat\tao\model\Observer\GCP\PubSubObserver::CONFIG_TOPIC => 'my_gcp_topic',
    ]
);

$anySubject = new \oat\tao\model\Observer\Subject(
    [
        'some' => 'data',
        'another' => 'data',
    ]
);
$anySubject->attach($observer);
$anySubject->notify(); // Will send a message to GCP Pub/Sub