本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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;
}
}
示例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;
}
示例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'];
}
}
}
示例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;
}
示例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']);
}
示例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();
}
}
示例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;
}
示例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'];
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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.');
}
}