本文整理汇总了PHP中CakeEvent::isStopped方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeEvent::isStopped方法的具体用法?PHP CakeEvent::isStopped怎么用?PHP CakeEvent::isStopped使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeEvent
的用法示例。
在下文中一共展示了CakeEvent::isStopped方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPropagation
/**
* Tests the event propagation stopping property
*
* @return void
* @triggers fake.event
*/
public function testPropagation()
{
$event = new CakeEvent('fake.event');
$this->assertFalse($event->isStopped());
$event->stopPropagation();
$this->assertTrue($event->isStopped());
}
示例2: dispatch
/**
* Dispatches a new event to all configured listeners
*
* @param string|CakeEvent $event the event key name or instance of CakeEvent
* @return CakeEvent
*/
public function dispatch($event)
{
if (is_string($event)) {
$event = new CakeEvent($event);
}
$listeners = $this->listeners($event->name());
if (empty($listeners)) {
return $event;
}
foreach ($listeners as $listener) {
if ($event->isStopped()) {
break;
}
if ($listener['passParams'] === true) {
$result = call_user_func_array($listener['callable'], $event->data);
} else {
$result = call_user_func($listener['callable'], $event);
}
if ($result === false) {
$event->stopPropagation();
}
if ($result !== null) {
$event->result = $result;
}
}
return $event;
}
示例3: dispatch
/**
* Dispatches a new event to all configured listeners
*
* @param string|CakeEvent $event the event key name or instance of CakeEvent
* @return CakeEvent
* @triggers $event
*/
public function dispatch($event)
{
if (is_string($event)) {
$event = new CakeEvent($event);
}
$listeners = $this->listeners($event->name());
if (empty($listeners)) {
return $event;
}
foreach ($listeners as $listener) {
if ($event->isStopped()) {
break;
}
if ($listener['passParams'] === true) {
$result = call_user_func_array($listener['callable'], $event->data);
} else {
$result = call_user_func($listener['callable'], $event);
}
if ($result === false) {
$event->stopPropagation();
}
// CUSTOMIZE ADD 2013/09/23 ryuring
// ObjectCollection を継承しているイベントの場合、
// 複数のオブジェクトに対するイベントの結果が配列で返ってくるが、
// 全ての結果がNULLの場合、その前のイベントの結果が上書きされてしまう。
// 全ての結果がNULLの場合には、結果がNULLとみなし、上書きしない仕様に変更した
// >>>
if (is_array($result) && array_key_exists(0, $result)) {
$notNull = false;
foreach ($result as $key => $val) {
if ($val !== null) {
$notNull = true;
}
}
if (!$notNull) {
$result = null;
}
}
// <<<
if ($result !== null) {
$event->result = $result;
}
}
return $event;
}
示例4: beforeDelete
/**
* beforeDelete
*
* @param CakeEvent $event
* @return boolean
*/
public function beforeDelete(CakeEvent $event)
{
if (!method_exists($event->subject(), 'dispatchEvent')) {
return true;
}
$currentEvent = $event->subject->dispatchEvent('beforeDelete', $event->data);
if ($currentEvent) {
if ($event->isStopped()) {
return false;
}
}
return true;
}
示例5: testStopPropagation
public function testStopPropagation()
{
$this->event->stopPropagation(false);
$this->assertFalse($this->event->isStopped());
}