本文整理汇总了PHP中Cake\Event\Event类的典型用法代码示例。如果您正苦于以下问题:PHP Event类的具体用法?PHP Event怎么用?PHP Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeDispatch
public function beforeDispatch(Event $event)
{
$event->stopPropagation();
$response = new Response(['body' => $this->config('message')]);
$response->httpCodes([429 => 'Too Many Requests']);
$response->statusCode(429);
return $response;
}
示例2: 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;
}
示例3: onSuccessRegister
/**
* Send an activation link on success registered user
* @param Event $event
*/
public function onSuccessRegister(Event $event)
{
$controller = $event->subject();
$user = $event->data['user'];
$controller->_sendActivationEmail($user)->template('Bazibartar.register')->subject('فعال سازی حساب کاربری')->send();
$controller->Flash->success(__d('users', 'you are success register, and an activation email has been send, check your email'));
}
示例4: beforeDispatch
/**
* Checks whether the response was cached and set the body accordingly.
*
* @param \Cake\Event\Event $event containing the request and response object
* @return \Cake\Network\Response with cached content if found, null otherwise
*/
public function beforeDispatch(Event $event)
{
if (Configure::read('Cache.check') !== true) {
return;
}
$path = $event->data['request']->here();
if ($path === '/') {
$path = 'home';
}
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views/' . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views/' . $path . '_index.php';
}
if (file_exists($filename)) {
$controller = null;
$view = new View($controller);
$view->response = $event->data['response'];
$result = $view->renderCache($filename, microtime(true));
if ($result !== false) {
$event->stopPropagation();
$event->data['response']->body($result);
return $event->data['response'];
}
}
}
示例5: beforeDispatch
/**
* Checks if a requested cache file exists and sends it to the browser
*
* @param \Cake\Event\Event $event containing the request and response object
*
* @return \Cake\Network\Response|null Response if the client is requesting a recognized cache file, null otherwise
*/
public function beforeDispatch(Event $event)
{
if (Configure::read('Cache.check') === false) {
return null;
}
/* @var \Cake\Network\Request $request */
$request = $event->data['request'];
$url = $request->here();
$url = str_replace($request->base, '', $url);
$file = $this->getFile($url);
if ($file === null) {
return null;
}
$cacheContent = $this->extractCacheContent($file);
$cacheInfo = $this->extractCacheInfo($cacheContent);
$cacheTime = $cacheInfo['time'];
if ($cacheTime < time() && $cacheTime != 0) {
unlink($file);
return null;
}
/* @var \Cake\Network\Response $response */
$response = $event->data['response'];
$event->stopPropagation();
$response->modified(filemtime($file));
if ($response->checkNotModified($request)) {
return $response;
}
$pathSegments = explode('.', $file);
$ext = array_pop($pathSegments);
$this->_deliverCacheFile($request, $response, $file, $ext);
return $response;
}
示例6: startup
/**
* Startup callback.
*
* @param Event $event
*/
public function startup(Event $event)
{
if (!$event->subject()->isAdmin()) {
$this->__setForLayout();
$this->__createModules();
}
}
示例7: beforeSave
public function beforeSave(Event $event, Officer $officer, \ArrayObject $options)
{
if ($officer->isNew()) {
return true;
}
if (!$officer->dirty('member_id')) {
return true;
}
//Ensure no UI screwup tried to move "officer" record to different club
$originalMemberId = $officer->getOriginal('member_id');
$memberId = $officer->get('member_id');
try {
$originalMember = $this->Members->get($originalMemberId);
$member = $this->Members->get($memberId);
} catch (RecordNotFoundException $e) {
$event->stopPropagation();
return false;
}
if ($originalMember->club_id != $member->club_id) {
//Somehow messed up and attempting to switch Officer record to different club
$event->stopPropagation();
return false;
}
return true;
}
示例8: shutdown
/**
* Data collection callback.
*
* @param \Cake\Event\Event $event The shutdown event.
* @return void
*/
public function shutdown(Event $event)
{
/* @var Controller $controller */
$controller = $event->subject();
$request = $controller->request;
$this->_data = ['params' => $request->params, 'query' => $request->query, 'data' => $request->data, 'cookie' => $request->cookies, 'get' => $_GET, 'matchedRoute' => $request->param('_matchedRoute'), 'headers' => ['response' => headers_sent($file, $line), 'file' => $file, 'line' => $line]];
}
示例9: beforeFiler
/**
* beforeFilter initTabsItems
*
* @param Cake/Event/Event $event Event
* @return void
*/
public function beforeFiler(Event $event)
{
$this->setController($event->subject());
if (method_exists($this->Controller, 'initTabsItems')) {
$this->Controller->initTabsItems($event);
}
}
示例10: getFooter
/**
* Method that adds footer element to the Layout.
*
* @param Cake\Event\Event $event Event object
* @return void
*/
public function getFooter(Event $event)
{
if (!$event->subject()->elementExists(static::ELEMENT_FOOTER)) {
return;
}
$event->result = $event->subject()->element(static::ELEMENT_FOOTER);
}
示例11: beforeFilter
/**
* Callback
*
* @param \Cake\Event\Event $event
* @return \Cake\Network\Response|array|null
*/
public function beforeFilter(Event $event)
{
$this->Controller = $event->subject();
if (!$this->config('enabled')) {
return null;
}
if ($actions = $this->config('actions')) {
$action = !empty($this->Controller->request->params['action']) ? $this->Controller->request->params['action'] : '';
if (!in_array($action, $actions)) {
return null;
}
}
$this->Controller->request->params['isJson'] = isset($this->Controller->request->params['url']['_ext']) && $this->Controller->request->params['url']['_ext'] === 'json';
$modelName = $this->config('modelName');
if (empty($modelName)) {
$modelName = $this->Controller->modelClass;
}
list(, $modelName) = pluginSplit($modelName);
$this->config('modelName', $modelName);
if (!$this->Controller->{$modelName}->behaviors()->has('Ratable')) {
$this->Controller->{$modelName}->behaviors()->load('Ratings.Ratable', $this->_config);
}
$this->Controller->helpers[] = 'Ratings.Rating';
$params = $this->request->data + $this->request->query + $this->_config['params'];
if (!method_exists($this->Controller, 'rate')) {
if (isset($params['rate']) && isset($params['rating'])) {
$userId = $this->config('userId') ?: $this->Controller->Auth->user($this->config('userIdField'));
return $this->rate($params['rate'], $params['rating'], $userId, $params['redirect']);
}
}
}
示例12: testPropagation
/**
* Tests the event propagation stopping property
*
* @return void
* @triggers fake.event
*/
public function testPropagation()
{
$event = new Event('fake.event');
$this->assertFalse($event->isStopped());
$event->stopPropagation();
$this->assertTrue($event->isStopped());
}
示例13: shutdown
/**
* Shutdown event
*
* @param \Cake\Event\Event $event The event
* @return void
*/
public function shutdown(Event $event)
{
$controller = $event->subject();
$errors = [];
array_walk_recursive($controller->viewVars, function (&$item) {
// Execute queries so we can show the results in the toolbar.
if ($item instanceof Query) {
$item = $item->all();
}
if ($item instanceof Closure || $item instanceof PDO || $item instanceof SimpleXmlElement) {
$item = 'Unserializable object - ' . get_class($item);
}
if ($item instanceof Exception) {
$item = sprintf('Unserializable object - %s. Error: %s in %s, line %s', get_class($item), $item->getMessage(), $item->getFile(), $item->getLine());
}
return $item;
});
foreach ($controller->viewVars as $k => $v) {
// Get the validation errors for Entity
if ($v instanceof EntityInterface) {
$errors[$k] = $this->_getErrors($v);
} elseif ($v instanceof Form) {
$formError = $v->errors();
if (!empty($formError)) {
$errors[$k] = $formError;
}
}
}
$this->_data = ['content' => $controller->viewVars, 'errors' => $errors];
}
示例14: injectEditor
public function injectEditor(Event $event, $layoutFile)
{
$_view = $event->subject();
$content = $_view->fetch('content');
if (Configure::read('Editorial.autoload')) {
$searchClass = Configure::read('Editorial.autoload');
if (empty($searchClass)) {
$searchClass = 'editor';
}
$plugin = Configure::read('Editorial.editor');
list($vendor, $class) = $this->vendorSplit($plugin);
$searchRegex = '/(<textarea.*class\\=\\".*' . Configure::read('Editorial.class') . '.*\\"[^>]*>.*<\\/textarea>)/isU';
//preg_match_all($searchRegex, $content, $matches);
//debug($matches);
if (Plugin::loaded($plugin) !== false && preg_match_all($searchRegex, $content, $matches)) {
if (!$_view->helpers()->has('Editor')) {
$options['className'] = $class . '.' . $class;
if ($vendor) {
$options['className'] = $vendor . '/' . $options['className'];
}
$options['options'] = $plugin . '.defaults';
if ($editorDefaults = Configure::read('Editorial.' . $class . '.defaults')) {
$options['options'] = $editorDefaults;
}
$_view->loadHelper('Editor', $options);
$_view->Editor->initialize();
}
$_view->Editor->connect($content);
}
}
}
示例15: onBeforeAdminTemplateStructure
/**
* Hook admin actions
* @param Event $event
*/
public function onBeforeAdminTemplateStructure(Event $event)
{
$this->_View = $view = $event->subject();
$this->__hookAdminActions();
$this->__hookAdminBoxes();
$this->__hookAdminForms();
}