本文整理匯總了PHP中Observer::trigger方法的典型用法代碼示例。如果您正苦於以下問題:PHP Observer::trigger方法的具體用法?PHP Observer::trigger怎麽用?PHP Observer::trigger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Observer
的用法示例。
在下文中一共展示了Observer::trigger方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __call
/**
* Catch all calls, fire events and remap to real instance
*
* @access public
* @param string $method
* @param array $args
* @return mixed
*/
public function __call($method, array $args = array())
{
$event = $this->observer->createEvent()->setMethod($method)->setParams($args)->setInstance($this)->setType('before');
$before = $this->observer->trigger()->getResult();
if ($event->isPropagationStopped()) {
return $before;
}
/** @var \Closure $closure */
if ($closure = $this->observer->bound($method)) {
$callback = $closure->bindTo($this, $this);
$result = Executor::callClosure($callback, $event->getParams());
} else {
$result = Executor::call($this(true), $method, $event->getParams());
}
$event->setType('after')->setResult($result);
return $this->observer->trigger()->getResult();
}
示例2: testBindByObject
public function testBindByObject()
{
$stdMock = $this->getMock('\\StdClass', ['test']);
$stdMock->expects($this->once())->method('test');
$callback = function () use($stdMock) {
$stdMock->test();
};
$obj = new \StdClass();
$observer = new Observer([[$obj, 'test', $callback]]);
$observer->trigger($obj, 'test');
}