浏览代码

monitor headers

Mark Scherer 11 年之前
父节点
当前提交
435c6ff68d
共有 3 个文件被更改,包括 42 次插入17 次删除
  1. 19 0
      Controller/MyController.php
  2. 16 17
      README.md
  3. 7 0
      docs/Features.md

+ 19 - 0
Controller/MyController.php

@@ -51,4 +51,23 @@ class MyController extends Controller {
 		return parent::paginate($object, $scope, $whitelist);
 		return parent::paginate($object, $scope, $whitelist);
 	}
 	}
 
 
+	/**
+	 * Hook to monitor headers being sent.
+	 *
+	 * @return void
+	 */
+	public function afterFilter() {
+		parent::afterFilter();
+
+		if (Configure::read('App.monitorHeaders') && $this->name !== 'CakeError') {
+			if (headers_sent($filename, $linenum)) {
+				$message = sprintf('Headers already sent in %s on line %s', $filename, $linenum);
+				if (Configure::read('debug')) {
+					throw new CakeException($message);
+				}
+				trigger_error($message);
+			}
+		}
+	}
+
 }
 }

+ 16 - 17
README.md

@@ -1,33 +1,30 @@
 # CakePHP Tools Plugin
 # CakePHP Tools Plugin
+
 [![Build Status](https://api.travis-ci.org/dereuromark/cakephp-tools.png?branch=master)](https://travis-ci.org/dereuromark/cakephp-tools)
 [![Build Status](https://api.travis-ci.org/dereuromark/cakephp-tools.png?branch=master)](https://travis-ci.org/dereuromark/cakephp-tools)
 [![Latest Stable Version](https://poser.pugx.org/dereuromark/cakephp-tools/v/stable.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 [![Latest Stable Version](https://poser.pugx.org/dereuromark/cakephp-tools/v/stable.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 [![Coverage Status](https://coveralls.io/repos/dereuromark/cakephp-tools/badge.png)](https://coveralls.io/r/dereuromark/cakephp-tools)
 [![Coverage Status](https://coveralls.io/repos/dereuromark/cakephp-tools/badge.png)](https://coveralls.io/r/dereuromark/cakephp-tools)
-[![Minimum PHP Version](http://img.shields.io/badge/php-%3E%3D%205.3-8892BF.svg)](https://php.net/)
 [![License](https://poser.pugx.org/dereuromark/cakephp-tools/license.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 [![License](https://poser.pugx.org/dereuromark/cakephp-tools/license.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 [![Total Downloads](https://poser.pugx.org/dereuromark/cakephp-tools/d/total.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 [![Total Downloads](https://poser.pugx.org/dereuromark/cakephp-tools/d/total.png)](https://packagist.org/packages/dereuromark/cakephp-tools)
 
 
 A CakePHP 2.x Plugin containing several useful tools that can be used in many projects.
 A CakePHP 2.x Plugin containing several useful tools that can be used in many projects.
-This plugin requires PHP5.3+.
+This plugin requires PHP5.3+
 
 
-Please note: New functionality has been tested against 2.x (current master branch) only.
-Please upgrade your app to latest CakePHP 2.x if possible.
-User a different 2.x branch if you need temporary support for older versions.
+Please note: New functionality has been tested against 2.x (current master and dev) only. Please upgrade if possible.
 
 
 ## How to include
 ## How to include
 Installing the Plugin is pretty much as with every other CakePHP Plugin.
 Installing the Plugin is pretty much as with every other CakePHP Plugin.
 
 
-* Put the files in `APP/Plugin/Tools`.
-* Make sure you have `CakePlugin::load('Tools')` or `CakePlugin::loadAll()` in your bootstrap.
+* Put the files in `APP/Plugin/Tools`
+* Make sure you have `CakePlugin::load('Tools')` or `CakePlugin::loadAll()` in your bootstrap
 
 
-You should use composer/packagist now @ https://packagist.org/packages/dereuromark/cakephp-tools
+Tip: You can also use packagist now @ https://packagist.org/packages/dereuromark/cakephp-tools
 
 
 ```
 ```
 "require": {
 "require": {
-	"dereuromark/cakephp-tools": "[version].*"
+	"dereuromark/cakephp-tools": "dev-master"
 }
 }
 ```
 ```
-With `0.5` as `[version]`, for example, it would be: `0.5.*`.
-The `*` asserts that you get all bugfix versions if existing.
+or use the tags, e.g. `0.4` directly.
 
 
 That's it. It should be up and running.
 That's it. It should be up and running.
 
 
@@ -47,6 +44,8 @@ CakePlugin::loadAll(array(
 ));
 ));
 ```
 ```
 
 
+
+
 MyModel can be extended to use more powerful validation and other improvements:
 MyModel can be extended to use more powerful validation and other improvements:
 
 
 ```php
 ```php
@@ -119,8 +118,7 @@ public $helpers = array(
 * Disable cache also works for older IE versions.
 * Disable cache also works for older IE versions.
 * Default settings for Paginator, ... can be set using Configure.
 * Default settings for Paginator, ... can be set using Configure.
 * RSS and Ajax Views for better responses (Ajax also comes with an optional component).
 * RSS and Ajax Views for better responses (Ajax also comes with an optional component).
-* testAction() defaults to GET.
-* [Shims](docs/Shims.md) to write cutting edge 2.x code - and prepare for 3.x.
+* testAction() defaults to GET
 
 
 A full list of fixes and useful migration tweaks towards the next major version see [here](https://github.com/dereuromark/cakephp-tools/wiki/Included-fixes-and-migration-tweaks).
 A full list of fixes and useful migration tweaks towards the next major version see [here](https://github.com/dereuromark/cakephp-tools/wiki/Included-fixes-and-migration-tweaks).
 
 
@@ -143,7 +141,7 @@ A full list of fixes and useful migration tweaks towards the next major version
 * GoogleMapV3, Gravatar, Qrcode, Timeline, Typography, Ical, Hcard provide additional helper functionality.
 * GoogleMapV3, Gravatar, Qrcode, Timeline, Typography, Ical, Hcard provide additional helper functionality.
 * NEW: Backported StringTemplate class (from CakePHP3.0) can be used to use template based rendering of HTML tags.
 * NEW: Backported StringTemplate class (from CakePHP3.0) can be used to use template based rendering of HTML tags.
 * NEW: Backported password_hash() functionality via Tools.Modern PasswordHasher and Passwordable out of the box.
 * NEW: Backported password_hash() functionality via Tools.Modern PasswordHasher and Passwordable out of the box.
-
+* NEW: Monitor the headers sent and allow actions to be refactored cleanly using Response class.
 and much more
 and much more
 
 
 
 
@@ -154,7 +152,7 @@ If you are able to help on that one, that would be awesome.
 
 
 ### Branching strategy
 ### Branching strategy
 The master branch is the currently active and maintained one and works with the current 2.x stable version.
 The master branch is the currently active and maintained one and works with the current 2.x stable version.
-Older versions might be found in their respective branches (2.0, 2.4, ...).
+Older versions might be found in their respective branches (1.3, 2.0, 2.3, ...).
 Please provide PRs mainly against master branch then.
 Please provide PRs mainly against master branch then.
 
 
 For details on how to contribute please read the [CONTRIBUTING page](CONTRIBUTING.md).
 For details on how to contribute please read the [CONTRIBUTING page](CONTRIBUTING.md).
@@ -166,7 +164,8 @@ For details on how to contribute please read the [CONTRIBUTING page](CONTRIBUTIN
 
 
 ### Recent changes (possibly BC breaking)
 ### Recent changes (possibly BC breaking)
 
 
+* 2014-01 Changed Garbige to Garbage in method names.
+* 2014-02 Qlogin now uses Token model instead of deprecated CodeKey per default.
+* 2014-07 Packagist package name has been renamed to "cakephp-tools".
 * 2014-11 All translations now use the `tools` domain; development messages are not translated anymore
 * 2014-11 All translations now use the `tools` domain; development messages are not translated anymore
 * 2014-12 Some model validations have also been transformed from generic `validation` into `tools` domain.
 * 2014-12 Some model validations have also been transformed from generic `validation` into `tools` domain.
-* 2014-12 All `tools` domain translations need to exist in `APP/Locale` due to a core issue in `CakePHP <= 2.5` when trying to overwrite them in the application.
-* 2015-01 With CakePHP2.6 support now we can re-add the Locale files again. Use `App.preferApp` Configure key to overwrite the plugin's locale files.

+ 7 - 0
docs/Features.md

@@ -0,0 +1,7 @@
+## Useful Features
+
+### Debugging
+Use `Configure::write('App.monitorHeader', true);` to assert, that all controller actions don't (accidently) sent any headers prior
+to the actual response->send() call. It will throw an exception in debug mode, and trigger an error in productive mode.
+
+Make sure your AppController extends the Tools plugin MyController.