本文整理汇总了PHP中Subject::detach方法的典型用法代码示例。如果您正苦于以下问题:PHP Subject::detach方法的具体用法?PHP Subject::detach怎么用?PHP Subject::detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject::detach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testObserverCanBeAttachedAndDetach
/**
*
*/
public function testObserverCanBeAttachedAndDetach()
{
$subject = new Subject();
$observerA = $this->getMockForAbstractClass('\\SplObserver');
$subject->attach($observerA);
$observerB = $this->getMockForAbstractClass('\\SplObserver');
$subject->attach($observerB);
$subject->detach($observerB);
$this->assertContains($observerA, $subject->getObservers());
$this->assertNotContains($observerB, $subject->getObservers());
}
示例2: __construct
public function __construct()
{
$subject = new Subject();
$o1 = new Observer1();
$o2 = new Observer2();
$o3 = new Observer3();
$subject->setData('Data for each 3 attached observers!');
$subject->attach($o1);
$subject->attach($o2);
$subject->attach($o3);
$subject->notify();
$subject->detach($o3);
$subject->setData('Data not for 3rd detached one!');
$subject->notify();
}
示例3: Subject
<?php
namespace Observer;
require_once 'AbstractObserver.php';
require_once 'AbstractSubject.php';
require_once 'Observer.php';
require_once 'Subject.php';
$patternGossiper = new Subject();
$patternGossipFan = new Observer();
$patternGossiper->attach($patternGossipFan);
$patternGossiper->updateFavorites('abstract factory, decorator, visitor');
$patternGossiper->updateFavorites('abstract factory, observer, decorator');
$patternGossiper->detach($patternGossipFan);
$patternGossiper->updateFavorites('abstract factory, observer, paisley');
示例4: detach
/**
* Same as {@link Subject::detach}, but it takes only one argument
* and that argument must be a class which implements the SplObserver interface.
*/
public function detach(SplObserver $obj)
{
return parent::detach($obj);
}