mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-24 16:51:19 +02:00
33 lines
576 B
PHP
33 lines
576 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DesignPatterns\Behavioral\Observer;
|
|
|
|
use SplObserver;
|
|
use SplSubject;
|
|
|
|
class UserObserver implements SplObserver
|
|
{
|
|
/**
|
|
* @var SplSubject[]
|
|
*/
|
|
private array $changedUsers = [];
|
|
|
|
/**
|
|
* It is called by the Subject, usually by SplSubject::notify()
|
|
*/
|
|
public function update(SplSubject $subject): void
|
|
{
|
|
$this->changedUsers[] = clone $subject;
|
|
}
|
|
|
|
/**
|
|
* @return SplSubject[]
|
|
*/
|
|
public function getChangedUsers(): array
|
|
{
|
|
return $this->changedUsers;
|
|
}
|
|
}
|