for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author: jiangyi
* @date: 下午5:25 2018/11/28
*/
namespace Hello;
class Subject
{
protected $observers = [];
protected $name;
public function __construct($name)
$this->name = $name;
}
public function getName()
return $this->name;
public function attach(Observer $observer)
$this->observers[] = $observer;
public function doSomething()
// 做点什么
// ...
// 通知观察者发生了些什么
$this->notify('something');
public function doSomethingBad()
foreach ($this->observers as $observer) {
$observer->reportError(42, 'Something bad happened', $this);
protected function notify($argument)
$observer->update($argument);