本文整理匯總了PHP中UserList::addCustomer方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserList::addCustomer方法的具體用法?PHP UserList::addCustomer怎麽用?PHP UserList::addCustomer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserList
的用法示例。
在下文中一共展示了UserList::addCustomer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addCustomer
}
//實現可被觀察對象
//負責維護關注列表,並發送消息
class UserList implements IObservable
{
private $_observers = array();
public function addCustomer($name)
{
foreach ($this->_observers as $obs) {
$obs->onChanged($this, $name);
}
}
public function addObserver($observer)
{
$this->_observers[] = $observer;
}
}
//實現一個觀察者
class UserListLogger implements IObserver
{
public function onChanged($sender, $args)
{
echo "'{$args}' added to user list\n";
}
}
$ul = new UserList();
//觀察者列表
$ul->addObserver(new UserListLogger());
//添加觀察者至觀察者列表
$ul->addCustomer("Jack");
//添加用戶,並將消息發送給觀察者
示例2: addCustomer
function onChanged($sender, $args);
}
interface IObservable
{
function addObserver($observer);
}
class UserList implements IObservable
{
private $_observers = array();
public function addCustomer($name)
{
foreach ($this->_observers as $obs) {
$obs->onChanged($this, $name);
}
}
public function addObserver($observer)
{
$this->_observers[] = $observer;
}
}
class UserListLogger implements IObserver
{
public function onChanged($sender, $args)
{
echo "'{$args}' added to user list\n";
}
}
$ul = new UserList();
$ul->addObserver(new UserListLogger());
$ul->addCustomer("Nicole Hachey");