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