Commit 104c4fc3 by Qiang Xue

Added support to allow an event handler to be inserted at the beginning of the…

Added support to allow an event handler to be inserted at the beginning of the existing event handler list
parent 9c0f236a
...@@ -186,6 +186,7 @@ Yii Framework 2 Change Log ...@@ -186,6 +186,7 @@ Yii Framework 2 Change Log
- Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue) - Enh: Added `yii\web\Request::getAuthUser()` and `getAuthPassword()` (qiangxue)
- Enh: Added summaryOptions and emptyTextOptions to BaseListView (johonunu) - Enh: Added summaryOptions and emptyTextOptions to BaseListView (johonunu)
- Enh: Implemented Oracle column comment reading from another schema (gureedo, samdark) - Enh: Implemented Oracle column comment reading from another schema (gureedo, samdark)
- Enh: Added support to allow an event handler to be inserted at the beginning of the existing event handler list (qiangxue)
- Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe) - Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
- Chg #735: Added back `ActiveField::hiddenInput()` (qiangxue) - Chg #735: Added back `ActiveField::hiddenInput()` (qiangxue)
- Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue) - Chg #1186: Changed `Sort` to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
......
...@@ -473,12 +473,19 @@ class Component extends Object ...@@ -473,12 +473,19 @@ class Component extends Object
* @param callable $handler the event handler * @param callable $handler the event handler
* @param mixed $data the data to be passed to the event handler when the event is triggered. * @param mixed $data the data to be passed to the event handler when the event is triggered.
* When the event handler is invoked, this data can be accessed via [[Event::data]]. * When the event handler is invoked, this data can be accessed via [[Event::data]].
* @param boolean $append whether to append new event handler to the end of the existing
* handler list. If false, the new handler will be inserted at the beginning of the existing
* handler list.
* @see off() * @see off()
*/ */
public function on($name, $handler, $data = null) public function on($name, $handler, $data = null, $append = true)
{ {
$this->ensureBehaviors(); $this->ensureBehaviors();
$this->_events[$name][] = [$handler, $data]; if ($append || empty($this->_events[$name])) {
$this->_events[$name][] = [$handler, $data];
} else {
array_unshift($this->_events[$name], [$handler, $data]);
}
} }
/** /**
...@@ -498,7 +505,6 @@ class Component extends Object ...@@ -498,7 +505,6 @@ class Component extends Object
} }
if ($handler === null) { if ($handler === null) {
unset($this->_events[$name]); unset($this->_events[$name]);
return true; return true;
} else { } else {
$removed = false; $removed = false;
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
use yii\base\Component;
/**
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ContentTypeNegotiator extends Component
{
/**
* @var array list of supported API version numbers. If the current request does not specify a version
* number, the first element will be used as the [[version|chosen version number]]. For this reason, you should
* put the latest version number at the first. If this property is empty, [[version]] will not be set.
*/
public $supportedVersions = [];
/**
* @var array list of supported response formats. The array keys are the requested content MIME types,
* and the array values are the corresponding response formats. The first element will be used
* as the response format if the current request does not specify a content type.
*/
public $supportedFormats = [
'application/json' => Response::FORMAT_JSON,
'application/xml' => Response::FORMAT_XML,
];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment