本文整理汇总了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');
}