當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Subject::detach方法代碼示例

本文整理匯總了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());
 }
開發者ID:metabor,項目名稱:statemachine,代碼行數:14,代碼來源:SubjectTest.php

示例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();
 }
開發者ID:rodolfobandeira,項目名稱:observer,代碼行數:15,代碼來源:Client.php

示例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');
開發者ID:robotomize,項目名稱:php-oop-patterns,代碼行數:15,代碼來源:example.php

示例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);
 }
開發者ID:Burgestrand,項目名稱:phplibs,代碼行數:8,代碼來源:SplSubjectAdapter.php


注:本文中的Subject::detach方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。