當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。