本文整理匯總了PHP中Cake\Event\Event::data方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::data方法的具體用法?PHP Event::data怎麽用?PHP Event::data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Event\Event
的用法示例。
在下文中一共展示了Event::data方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: afterCasAuthenticate
public function afterCasAuthenticate(Event $event)
{
$user = $event->data();
if (empty($user['username'])) {
return null;
}
if (!array_key_exists('id', $user)) {
$user['id'] = $user['username'];
}
$localUser = TableRegistry::get('Users')->findOrCreateByNetid($user['username'], true);
//force PersonSummary update check
if (empty($localUser)) {
return null;
}
$user['id'] = $localUser->id;
if (empty($user['name']) && !empty($localUser->name)) {
$user['name'] = $localUser->name;
}
if (empty($user['byuId']) && !empty($localUser->byu_id)) {
$user['byuId'] = $localUser->byu_id;
}
$user['officers'] = TableRegistry::get('Officers')->listUserActive($localUser->id);
$user['advisors'] = TableRegistry::get('Advisors')->listUserApproved($localUser->id);
$user['members'] = TableRegistry::get('Members')->listActiveClubs($localUser->id);
$user['roles'] = TableRegistry::get('Roles')->listByUser($localUser->id);
$user['roles']['dean'] = TableRegistry::get('Departments')->listByDean($user['username']);
$homePrefixes = ['admin', 'dean', 'risk', 'review'];
//roles that have a default home, in descending preference order
foreach ($homePrefixes as $prefix) {
if (!empty($user['roles'][$prefix])) {
$user['default_home'] = ['prefix' => $prefix, 'controller' => 'clubs', 'action' => 'index'];
}
}
return $user;
}
示例2: _callListener
/**
* Calls a listener.
*
* Direct callback invocation is up to 30% faster than using call_user_func_array.
* Optimize the common cases to provide improved performance.
*
* @param callable $listener The listener to trigger.
* @param \Cake\Event\Event $event Event instance.
* @return mixed The result of the $listener function.
*/
protected function _callListener(callable $listener, Event $event)
{
$data = $event->data();
$length = count($data);
if ($length) {
$data = array_values($data);
}
switch ($length) {
case 0:
return $listener($event);
case 1:
return $listener($event, $data[0]);
case 2:
return $listener($event, $data[0], $data[1]);
case 3:
return $listener($event, $data[0], $data[1], $data[2]);
default:
array_unshift($data, $event);
return call_user_func_array($listener, $data);
}
}