mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 01:32:22 +01:00
31 lines
575 B
PHP
31 lines
575 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;
|
|
}
|
|
}
|