当前位置: 首页>>代码示例>>PHP>>正文


PHP Event::stopPropagation方法代码示例

本文整理汇总了PHP中Cake\Event\Event::stopPropagation方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::stopPropagation方法的具体用法?PHP Event::stopPropagation怎么用?PHP Event::stopPropagation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Event\Event的用法示例。


在下文中一共展示了Event::stopPropagation方法的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;
 }
开发者ID:Adnan0703,项目名称:Throttle,代码行数:8,代码来源:ThrottleFilter.php

示例2: 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;
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:25,代码来源:OfficersTable.php

示例3: 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());
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:13,代码来源:EventTest.php

示例4: beforeDelete

 /**
  * Checks if deletion is allowed
  *
  * @param \Cake\Event\Event $event The beforeDelete event that was fired
  * @param \Cake\ORM\Entity $entity The entity that is going to be deleted
  * @param \ArrayObject $options the options passed to the delete method
  * @return void|false
  */
 public function beforeDelete(Event $event, Entity $entity, ArrayObject $options)
 {
     if ($this->config('preventDeletion') === true || is_array($this->config('preventDeletion')) && in_array($entity->{$this->config('fields.key')}, $this->config('preventDeletion'))) {
         $event->stopPropagation();
         return false;
     }
 }
开发者ID:jorisvaesen,项目名称:cakephp-keyvalue-pairs,代码行数:15,代码来源:KeyValuePairsBehavior.php

示例5: beforeDispatch

 /**
  * Checks if request is for a compiled asset, otherwise skip any operation
  *
  * @param Event $event containing the request and response object
  * @throws \Cake\Network\Exception\NotFoundException
  * @return \Cake\Network\Response|null Response if the client is requesting a recognized asset, null otherwise
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     $config = $this->_getConfig();
     $production = !Configure::read('debug');
     if ($production && !$config->general('alwaysEnableController')) {
         return null;
     }
     // Make sure the request looks like an asset.
     $targetName = $this->getName($config, $request->url);
     if (!$targetName) {
         return null;
     }
     if (isset($request->query['theme'])) {
         $config->theme($request->query['theme']);
     }
     $factory = new Factory($config);
     $assets = $factory->assetCollection();
     if (!$assets->contains($targetName)) {
         return null;
     }
     $build = $assets->get($targetName);
     try {
         $compiler = $factory->cachedCompiler();
         $contents = $compiler->generate($build);
     } catch (Exception $e) {
         throw new NotFoundException($e->getMessage());
     }
     $response->type($build->ext());
     $response->body($contents);
     $event->stopPropagation();
     return $response;
 }
开发者ID:markstory,项目名称:asset_compress,代码行数:41,代码来源:AssetCompressorFilter.php

示例6: 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'];
         }
     }
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:36,代码来源:CacheDispatcher.php

示例7: 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;
 }
开发者ID:dereuromark,项目名称:cakephp-cache,代码行数:39,代码来源:CacheFilter.php

示例8: beforeDispatch

 public function beforeDispatch(Event $event)
 {
     if ($event->data['request']->url !== 'robots.txt') {
         return;
     }
     $event->stopPropagation();
     return new Response(['body' => "User-Agent: *\nDisallow: /", 'status' => 200, 'type' => 'txt']);
 }
开发者ID:surjit,项目名称:filters,代码行数:8,代码来源:RobotsFilter.php

示例9: matchRoute

 public function matchRoute(Event $event, array $url)
 {
     if (!isset($url['model']) || $url['model'] !== 'Wasabi/Cms.Pages') {
         return;
     }
     $RoutesTable = TableRegistry::get('Wasabi/Core.Routes');
     $route = $RoutesTable->find()->select(['url'])->where(['model' => $url['model'], 'foreign_key' => $url['foreign_key'] ?? 0, 'language_id' => $url['language_id'] ?? 0, 'redirect_to IS' => null])->hydrate(false)->first();
     if (!empty($route)) {
         $event->result = $route['url'];
         $event->stopPropagation();
     }
 }
开发者ID:wasabi-cms,项目名称:cms,代码行数:12,代码来源:RouteListener.php

示例10: beforeDispatch

 /**
  * beforeDispatch.
  *
  * @param Cake\Event\Event $event Event instance
  * @return mixed Cake\Network\Response when limit is reached, void otherwise
  */
 public function beforeDispatch(Event $event)
 {
     $this->_setIdentifier($event->data['request']);
     $this->_initCache();
     $this->_count = $this->_touch($event->data['request']);
     // client has not exceeded rate limit
     if ($this->_count <= $this->config('limit')) {
         $this->_setHeaders($event->data['response']);
         return;
     }
     // client has reached rate limit
     $event->stopPropagation();
     $response = new Response(['body' => $this->config('message')]);
     $response->httpCodes([429 => 'Too Many Requests']);
     $response->statusCode(429);
     return $response;
 }
开发者ID:nielin,项目名称:Throttle,代码行数:23,代码来源:ThrottleFilter.php

示例11: beforeDispatch

 /**
  * MaintenanceMode::beforeDispatch()
  *
  * @param \Cake\Event\Event $event
  * @return \Cake\Network\Response|null
  */
 public function beforeDispatch(Event $event)
 {
     /* @var \Cake\Http\ServerRequest $request */
     $request = $event->data['request'];
     $ip = $request->clientIp();
     $Maintenance = new Maintenance();
     if (!$Maintenance->isMaintenanceMode($ip)) {
         return null;
     }
     $body = __d('setup', 'Maintenance work');
     $body = $this->_body();
     $event->data['response']->header('Retry-After', HOUR);
     $event->data['response']->statusCode(503);
     $event->data['response']->body($body);
     $event->stopPropagation();
     return $event->data['response'];
 }
开发者ID:dereuromark,项目名称:cakephp-setup,代码行数:23,代码来源:MaintenanceFilter.php

示例12: handle

 /**
  * Handler method that applies before dispatch.
  *
  * @param \Cake\Event\Event $event The event instance.
  * @return mixed
  */
 public function handle(Event $event)
 {
     if (is_file(MAINTENANCE_CONFIG_FILE) && is_readable(MAINTENANCE_CONFIG_FILE)) {
         // stop event
         $event->stopPropagation();
         $request = $event->data['request'];
         $response = $event->data['response'];
         $config = (require MAINTENANCE_CONFIG_FILE);
         $viewClass = $config['viewClass'];
         $view = new $viewClass($request, $response);
         $view->templatePath($config['templatePath']);
         $view->template($config['templateFile']);
         $view->layout($config['templateLayout']);
         $view->set('startAt', \Cake\I18n\Time::createFromFormat('YmdHis', $config['startAt']));
         $view->set('endAt', \Cake\I18n\Time::createFromFormat('YmdHis', $config['endAt']));
         $response->body($view->render());
         return $response;
     }
 }
开发者ID:lemonphp,项目名称:cakeplugin-maintenance-mode,代码行数:25,代码来源:MaintenanceModeFilter.php

示例13: beforeDispatch

 /**
  * Applies Routing and additionalParameters to the request to be dispatched.
  * If Routes have not been loaded they will be loaded, and config/routes.php will be run.
  *
  * @param \Cake\Event\Event $event containing the request, response and additional params
  * @return \Cake\Network\Response|null A response will be returned when a redirect route is encountered.
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     if (Router::getRequest(true) !== $request) {
         Router::setRequestInfo($request);
     }
     try {
         if (empty($request->params['controller'])) {
             $params = Router::parse($request->url, $request->method());
             $request->addParams($params);
         }
     } catch (RedirectException $e) {
         $event->stopPropagation();
         $response = $event->data['response'];
         $response->statusCode($e->getCode());
         $response->header('Location', $e->getMessage());
         return $response;
     }
 }
开发者ID:nrother,项目名称:cakephp,代码行数:26,代码来源:RoutingFilter.php

示例14: beforeDispatch

 /**
  * Checks if a requested asset exists and sends it to the browser
  *
  * @param \Cake\Event\Event $event Event containing the request and response object
  * @return \Cake\Network\Response|null If the client is requesting a recognized asset, null otherwise
  * @throws \Cake\Network\Exception\NotFoundException When asset not found
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     $url = urldecode($request->url);
     if (strpos($url, '..') !== false || strpos($url, '.') === false) {
         return null;
     }
     $assetFile = $this->_getAssetFile($url);
     if ($assetFile === null || !file_exists($assetFile)) {
         return null;
     }
     $response = $event->data['response'];
     $event->stopPropagation();
     $response->modified(filemtime($assetFile));
     if ($response->checkNotModified($request)) {
         return $response;
     }
     $pathSegments = explode('.', $url);
     $ext = array_pop($pathSegments);
     return $this->_deliverAsset($request, $response, $assetFile, $ext);
 }
开发者ID:nrother,项目名称:cakephp,代码行数:28,代码来源:AssetFilter.php

示例15: beforeUsersControllerSignIn

 public function beforeUsersControllerSignIn(Event $event)
 {
     $controller = $event->subject();
     $active = true;
     if ($controller->request->is('post')) {
         $userName = '';
         if ($controller->request->data('username')) {
             $userName = $controller->request->data('username');
         }
         if ($controller->request->data('email')) {
             $userName = $controller->request->data('email');
         }
         if ($userName) {
             $active = $controller->Users->find('all', ['conditions' => ['Users.active' => true, 'OR' => ['Users.email' => $userName, 'Users.username' => $userName]]])->count();
         }
     }
     if (!$active) {
         $event->stopPropagation();
         return __d('passengers', 'Sorry, but your account has been not activated yet.');
     }
 }
开发者ID:mindforce,项目名称:cakephp-passengers,代码行数:21,代码来源:SignInEvent.php


注:本文中的Cake\Event\Event::stopPropagation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。