ActionFilter类
来源:互联网 发布:ios 扑克牌效果源码 编辑:程序博客网 时间:2024/06/03 19:50
操作过滤器基类ActionFilter
yii2\base\ActionFilter.php。
<?php/** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */namespace yii\base;/** * ActionFilter is the base class for action filters. * 是操作过滤器的基类。 * An action filter will participate in the action execution workflow by responding to * the `beforeAction` and `afterAction` events triggered by modules and controllers. * 一个操作过滤器将参与行动的执行工作流程,通过触发模型和控制器的`beforeAction` 和`afterAction` 事件 * Check implementation of [[\yii\filters\AccessControl]], [[\yii\filters\PageCache]] and [[\yii\filters\HttpCache]] as examples on how to use it. * * @author Qiang Xue <qiang.xue@gmail.com> * @since 2.0 */class ActionFilter extends Behavior{ /** * @var array list of action IDs that this filter should apply to. If this property is not set, * then the filter applies to all actions, unless they are listed in [[except]]. * 操作标识列表。如果该属性未设置,过滤器适用于所有的行动,除非它们被列入[[except]]中。 * If an action ID appears in both [[only]] and [[except]], this filter will NOT apply to it. * 如果一个操作ID 出现在[[only]] 和[[except]]中,该筛选器将不适用它 * Note that if the filter is attached to a module, the action IDs should also include child module IDs (if any) * and controller IDs. * 如果过滤器是链接到一个模块,操作检测还应包括子模块和控制器 * * @see except */ public $only; /** * @var array list of action IDs that this filter should not apply to. * 此筛选器不应适用于操作ID。 * @see only */ public $except = []; /** * @inheritdoc * 将行为对象附加到组件。 */ public function attach($owner) { $this->owner = $owner; $owner->on(Controller::EVENT_BEFORE_ACTION, [$this, 'beforeFilter']); } /** * @inheritdoc * 将行为对象和组件分离。 */ public function detach() { if ($this->owner) { $this->owner->off(Controller::EVENT_BEFORE_ACTION, [$this, 'beforeFilter']); $this->owner->off(Controller::EVENT_AFTER_ACTION, [$this, 'afterFilter']); $this->owner = null; } } /** * @param ActionEvent $event 在动作之前调用 */ public function beforeFilter($event) { if (!$this->isActive($event->action)) { return; } $event->isValid = $this->beforeAction($event->action); if ($event->isValid) { // call afterFilter only if beforeFilter succeeds beforeFilter 执行成功调用afterFilter // beforeFilter and afterFilter should be properly nested 两者要配合应用 $this->owner->on(Controller::EVENT_AFTER_ACTION, [$this, 'afterFilter'], null, false); } else { $event->handled = true; } } /** * @param ActionEvent $event */ public function afterFilter($event) { $event->result = $this->afterAction($event->action, $event->result); $this->owner->off(Controller::EVENT_AFTER_ACTION, [$this, 'afterFilter']); } /** * This method is invoked right before an action is to be executed (after all possible filters.) * 此方法是在一个动作之前被调用的( * You may override this method to do last-minute preparation for the action. * @param Action $action the action to be executed.要执行的动作 * @return boolean whether the action should continue to be executed. * 是否应继续执行该动作。 */ public function beforeAction($action) { return true; } /** * This method is invoked right after an action is executed. * 此方法是在执行动作之后调用的。 * You may override this method to do some postprocessing for the action. * @param Action $action the action just executed. 刚刚执行的动作 * @param mixed $result the action execution result 行动执行结果 * @return mixed the processed action result. 处理结果。 */ public function afterAction($action, $result) { return $result; } /** * Returns a value indicating whether the filer is active for the given action. * 返回一个值,给定的过滤器的行动是否为是积极的。 * @param Action $action the action being filtered 被过滤的动作 * @return boolean whether the filer is active for the given action. * 给定的过滤器的行动是否为是积极的。 */ protected function isActive($action) { if ($this->owner instanceof Module) { // convert action uniqueId into an ID relative to the module $mid = $this->owner->getUniqueId(); $id = $action->getUniqueId(); if ($mid !== '' && strpos($id, $mid) === 0) { $id = substr($id, strlen($mid) + 1); } } else { $id = $action->id; } return !in_array($id, $this->except, true) && (empty($this->only) || in_array($id, $this->only, true)); }}
0 0
- ActionFilter类
- Yii2.0的ActionFilter类详细解读
- ActionFilter的执行机制
- 基于rbac的ActionFilter
- ActionFilter递归链剖析
- ActionFilter for MVC asp.net
- MVC四大筛选器—ActionFilter&ResultedFilter
- asp.net mvc 1中ActionFilter的执行层级问题
- 在asp.net mvc中使用ActionFilter防止重复提交
- ASP.NET MVC 通过ActionFilter 实现AOP设计 示例
- asp.net core MVC 过滤器之ActionFilter过滤器(二)
- asp.net core MVC 过滤器之ActionFilter过滤器(二)
- asp.net core MVC 过滤器之ActionFilter过滤器(二)
- 求教各位高手:ASP.net MVC使用ActionFilter判断访问页面的权限怎么实现?
- asp.net mvc 之旅 —— 第六站 ActionFilter的应用及源码分析
- 利用 ActionFilter 为 ASP.NET Web API 添加 GZip 压缩功能
- Asp.Net MVC5代码的筛选器(ActionFilter)执行递归链表分析
- 类
- fork()函数
- Linux Shell 删除一个字符串中的部分字符
- Arranging Coins问题及解法
- 翻转二叉树
- Android 简单的实现WIFI连接
- ActionFilter类
- MyBatis注解映射十种方式
- IOS 属性 协议 Block用法
- 【给将来学神的算法详解--数据结构--线段树】(1)简介
- location-href
- Linux下的lds链接脚本基础
- ScrollView计时器循环滚动
- Proble
- Kconfig Makefile 内核编译