mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-28 10:40:17 +02:00
30 lines
536 B
PHP
30 lines
536 B
PHP
<?php
|
|
|
|
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;
|
|
}
|
|
}
|