本文整理汇总了PHP中CakeEvent::stopPropagation方法的典型用法代码示例。如果您正苦于以下问题:PHP CakeEvent::stopPropagation方法的具体用法?PHP CakeEvent::stopPropagation怎么用?PHP CakeEvent::stopPropagation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CakeEvent
的用法示例。
在下文中一共展示了CakeEvent::stopPropagation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPropagation
/**
* Tests the event propagation stopping property
*
* @return void
* @triggers fake.event
*/
public function testPropagation()
{
$event = new CakeEvent('fake.event');
$this->assertFalse($event->isStopped());
$event->stopPropagation();
$this->assertTrue($event->isStopped());
}
示例2: beforeDispatch
public function beforeDispatch(CakeEvent $event)
{
$MaintenanceMode = Configure::read('MaintenanceMode');
/* Not in maintenance mode*/
if (!$MaintenanceMode['enabled']) {
return;
}
/* Allow access from following IPS*/
if (!empty($MaintenanceMode['ip_filters'])) {
if (!is_array($MaintenanceMode['ip_filters'])) {
$ips = array($MaintenanceMode['ip_filters']);
} else {
$ips = $MaintenanceMode['ip_filters'];
}
$userIP = $this->_getUserIpAddr();
foreach ($ips as $ip) {
if ($this->_compareIp($userIP, $ip)) {
return;
}
}
}
$statusCode = 503;
$body = 'Currently undergoing maintenance';
if (!empty($MaintenanceMode['code'])) {
$statusCode = $MaintenanceMode['code'];
}
if (!empty($MaintenanceMode['view']['template'])) {
$View = $this->_getView();
$body = $View->render($MaintenanceMode['view']['template'], $MaintenanceMode['view']['layout']);
}
$event->data['response']->statusCode($statusCode);
$event->data['response']->body($body);
$event->stopPropagation();
return $event->data['response'];
}
示例3: beforeDispatch
/**
* Checks whether the response was cached and set the body accordingly.
*
* @param CakeEvent $event containing the request and response object
* @return CakeResponse with cached content if found, null otherwise
*/
public function beforeDispatch(CakeEvent $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' . DS . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . $path . '_index.php';
}
if (file_exists($filename)) {
$controller = null;
$view = new View($controller);
$result = $view->renderCache($filename, microtime(true));
if ($result !== false) {
$event->stopPropagation();
$event->data['response']->body($result);
return $event->data['response'];
}
}
}
示例4: beforeDispatch
/**
* Checks if a requested asset exists and sends it to the browser
*
* @param CakeEvent $event containing the request and response object
* @return mixed The resulting response.
* @throws NotFoundException When asset not found
*/
public function beforeDispatch(CakeEvent $event)
{
$url = urldecode($event->data['request']->url);
if (strpos($url, '..') !== false || strpos($url, '.') === false) {
return;
}
// CUSTOMIZE DELETE 2014/07/02 ryuring
// >>>
/*if ($result = $this->_filterAsset($event)) {
$event->stopPropagation();
return $result;
}*/
// <<<
$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($event->data['request'])) {
return $response;
}
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$this->_deliverAsset($response, $assetFile, $ext);
return $response;
}
示例5: beforeDispatch
/**
* Checks if request is for a compiled asset, otherwise skip any operation
*
* @param CakeEvent $event containing the request and response object
* @throws NotFoundException
* @return CakeResponse if the client is requesting a recognized asset, null otherwise
*/
public function beforeDispatch(CakeEvent $event) {
$url = $event->data['request']->url;
$Config = $this->_getConfig();
$production = !Configure::read('debug');
if ($production && !$Config->general('alwaysEnableController')) {
return;
}
$build = $this->_getBuild($url);
if ($build === false) {
return;
}
if (isset($event->data['request']->query['theme'])) {
$Config->theme($event->data['request']->query['theme']);
}
// Dynamically defined build file. Disabled in production for
// hopefully obvious reasons.
if ($Config->files($build) === array()) {
$files = array();
if (isset($event->data['request']->query['file'])) {
$files = $event->data['request']->query['file'];
}
$Config->files($build, $files);
}
try {
$Compiler = new AssetCompiler($Config);
$mtime = $Compiler->getLastModified($build);
$event->data['response']->modified($mtime);
if ($event->data['response']->checkNotModified($event->data['request'])) {
$event->stopPropagation();
return $event->data['response'];
}
$contents = $Compiler->generate($build);
} catch (Exception $e) {
throw new NotFoundException($e->getMessage());
}
$event->data['response']->type($Config->getExt($build));
$event->data['response']->body($contents);
$event->stopPropagation();
return $event->data['response'];
}
示例6: beforeDispatch
public function beforeDispatch(CakeEvent $event)
{
if (!preg_match("/media\\/router\\/index\\//i", $event->data['request']->url)) {
return;
}
$event->stopPropagation();
$requestData = $event->data['request']->params;
list($type, $id, $size, $filename) = $requestData['pass'];
App::uses('MediaPath', 'Media.Vendor');
$this->PHMedia = new MediaPath();
$fname = $this->PHMedia->getFileName($type, $id, $size, $filename);
$aFName = $this->PHMedia->getFileInfo($filename);
$response = $event->data['response'];
if (!file_exists($fname)) {
$this->_processMedia($requestData['pass'], $fname, $aFName);
}
$this->_deliverMedia($response, $fname, $aFName);
return $response;
}
示例7: beforeDispatch
/**
* Handle OPTIONS requests
*
* If it's an options request, loop on the configured http verbs and add
* an Access-Control-Allow-Methods header with the verbs the application
* is configured to respond to.
*
* @param CakeEvent $event
* @return CakeResponse|null
*/
public function beforeDispatch(CakeEvent $event)
{
$request = $event->data['request'];
if (!$request->is('options')) {
return;
}
$event->stopPropagation();
$url = $request->url;
$verbs = Configure::read('Crud.HttpMethodFilter.verbs') ?: $this->defaultVerbs;
$allowedMethods = array();
foreach ($verbs as $verb) {
$_SERVER['REQUEST_METHOD'] = $verb;
if (Router::parse('/' . $url)) {
$allowedMethods[] = $verb;
}
}
$_SERVER['REQUEST_METHOD'] = 'OPTIONS';
$response = $event->data['response'];
$response->header('Access-Control-Allow-Methods', implode(', ', $allowedMethods));
return $response;
}
示例8: beforeDispatch
/**
* Before Dispatch - Set CORS access control headers
*
* @author Anthony Putignano <anthony@wizehive.com>
* @since 1.0
* @param CakeEvent $event
* @return CakeResponse
*/
public function beforeDispatch(CakeEvent $event)
{
$request = $event->data['request'];
$response = $event->data['response'];
$origin = !empty($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '*';
$response->header('Access-Control-Allow-Origin: ' . $origin);
$response->header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
$response->header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
// Currently exit on all OPTIONS requests
// Fix for swagger-ui CORS preflight requests
if ($request->is('OPTIONS')) {
if (defined('ENVIRONMENT') && ENVIRONMENT === 'development') {
$response->header('Cache-Control: no-cache');
} else {
$response->header('Cache-Control: max-age=3600');
}
$event->stopPropagation();
return $response;
}
}
示例9: beforeDispatch
/**
* Inspects the requests and if the url is the one set for processing the Sendgrid
* webhook, it will convert the payload to one or several SendgridEvent objects and
* trigger the configured callback for each one of them.
*
* @param CakeEvent $event
* @return CakeResponse
*/
public function beforeDispatch(CakeEvent $event)
{
$config = Configure::read('Dispatcher.filters.GridHook');
$endpoint = '/webhook/sendgrid';
if (!empty($config['endpoint'])) {
$endpoint = $config['endpoint'];
}
$request = $event->data['request'];
$response = $event->data['response'];
if ('/' . $request->url !== $endpoint || !$request->is('post')) {
return;
}
$callable = $config['handler'];
if (!is_callable($callable)) {
throw new InvalidArgumentException('Not a valid handler for sendgrid webhooks');
}
$data = ['events' => json_decode($request->input(), true), 'meta' => ['relay' => $request->query('relay')]];
$this->_trigger($callable, $data);
$response->statusCode(200);
$event->stopPropagation();
return $response;
}
示例10: beforeDispatch
/**
* Checks whether the response was cached and set the body accordingly.
*
* @param CakeEvent $event containing the request and response object
* @return CakeResponse with cached content if found, null otherwise
*/
public function beforeDispatch(CakeEvent $event)
{
if (Configure::read('Cache.check') !== true) {
return null;
}
// CUSTOMIZE 2014/08/11 ryuring
// $this->request->here で、URLを取得する際、URL末尾の 「index」の有無に関わらず
// 同一ファイルを参照すべきだが、別々のURLを出力してしまう為、
// 正規化された URLを取得するメソッドに変更
// >>>
//$path = $event->data['request']->here();
// ---
$path = $event->data['request']->normalizedHere();
// <<<
if ($path === '/') {
$path = 'index';
}
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views' . DS . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . $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'];
}
}
}
示例11: stopListener
/**
* Auxiliary function to help in stopPropagation testing
*
* @param CakeEvent $event
* @return void
*/
public function stopListener($event)
{
$event->stopPropagation();
}
示例12: beforeDispatch
public function beforeDispatch(CakeEvent $event)
{
$event->data['response']->statusCode(500);
$event->stopPropagation();
return $event->data['response'];
}
示例13: testStopPropagation
public function testStopPropagation()
{
$this->event->stopPropagation(false);
$this->assertFalse($this->event->isStopped());
}
示例14: imagePath
/**
* Generates the path the image depending on the storage adapter
*
* @param CakeEvent $Event
* @return void
*/
public function imagePath($Event)
{
if ($Event->data['image']['adapter'] == 'Local') {
$Helper = $Event->subject();
extract($Event->data);
$path = $this->_buildPath($image, true, $hash);
$Event->data['path'] = $path;
$Event->stopPropagation();
}
}
示例15: setFlash
/**
* setFlash
*
* An API request doesn't need flash messages - so stop them being processed
*
* @param CakeEvent $event
*/
public function setFlash(CakeEvent $event)
{
$event->stopPropagation();
}