本文整理匯總了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);
}