mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-23 16:21:22 +02:00
31 lines
561 B
PHP
31 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;
|
|
}
|
|
}
|