博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
yii2框架随笔5
阅读量:5018 次
发布时间:2019-06-12

本文共 6313 字,大约阅读时间需要 21 分钟。

/**     * Returns a value indicating whether a property is defined for this component.     * A property is defined if:     *     * - the class has a getter or setter method associated with the specified name     *   (in this case, property name is case-insensitive);     * - the class has a member variable with the specified name (when `$checkVars` is true);     * - an attached behavior has a property of the given name (when `$checkBehaviors` is true).     *     * 与 Object 中的方法类似,只是添加了是否检测 behavior 的参数(下一篇着重介绍Object.php类)     *     * @param string $name the property name     * @param boolean $checkVars whether to treat member variables as properties     * @param boolean $checkBehaviors whether to treat behaviors' properties as properties of this component     * @return boolean whether the property is defined     * @see canGetProperty()     * @see canSetProperty()     */    public function hasProperty($name, $checkVars = true, $checkBehaviors = true)    {        // $checkVars 标记是否 check 对象的是否具有该属性(不是 getter 和 setter 定义出的属性)        // $checkBehaviors 标记是否 check behavior 中的属性        return $this->canGetProperty($name, $checkVars, $checkBehaviors) || $this->canSetProperty($name, false, $checkBehaviors);    }    /**     * Returns a value indicating whether a property can be read.     * A property can be read if:     *     * - the class has a getter method associated with the specified name     *   (in this case, property name is case-insensitive);     * - the class has a member variable with the specified name (when `$checkVars` is true);     * - an attached behavior has a readable property of the given name (when `$checkBehaviors` is true).     *     * 检查对象或类是否能够获取 $name 属性     *     * @param string $name the property name     * @param boolean $checkVars whether to treat member variables as properties     * @param boolean $checkBehaviors whether to treat behaviors' properties as properties of this component     * @return boolean whether the property can be read     * @see canSetProperty()     */    public function canGetProperty($name, $checkVars = true, $checkBehaviors = true)    {        if (method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name)) {            return true;        } elseif ($checkBehaviors) {            $this->ensureBehaviors();            foreach ($this->_behaviors as $behavior) {                if ($behavior->canGetProperty($name, $checkVars)) {                    // behavior 中存在名为 $name 的可读属性,就认为该对象也存在                    return true;                }            }        }        return false;    }    /**     * Returns a value indicating whether a property can be set.     * A property can be written if:     *     * - the class has a setter method associated with the specified name     *   (in this case, property name is case-insensitive);     * - the class has a member variable with the specified name (when `$checkVars` is true);     * - an attached behavior has a writable property of the given name (when `$checkBehaviors` is true).     *     * 检查对象或类是否能够设置 $name 属性     *     * @param string $name the property name     * @param boolean $checkVars whether to treat member variables as properties     * @param boolean $checkBehaviors whether to treat behaviors' properties as properties of this component     * @return boolean whether the property can be written     * @see canGetProperty()     */    public function canSetProperty($name, $checkVars = true, $checkBehaviors = true)    {        if (method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name)) {            return true;        } elseif ($checkBehaviors) {            $this->ensureBehaviors();            foreach ($this->_behaviors as $behavior) {                if ($behavior->canSetProperty($name, $checkVars)) {                    // behavior 中存在名为 $name 的可写属性,就认为该对象也存在                    return true;                }            }        }        return false;    }    /**     * Returns a value indicating whether a method is defined.     * A method is defined if:     *     * - the class has a method with the specified name     * - an attached behavior has a method with the given name (when `$checkBehaviors` is true).     *     * 检查对象或类是否具有 $name 方法, $checkBehaviors 标记是否 check behavior 中的方法     *     * @param string $name the property name     * @param boolean $checkBehaviors whether to treat behaviors' methods as methods of this component     * @return boolean whether the property is defined     */    public function hasMethod($name, $checkBehaviors = true)    {        if (method_exists($this, $name)) {            return true;        } elseif ($checkBehaviors) {            $this->ensureBehaviors();            foreach ($this->_behaviors as $behavior) {                if ($behavior->hasMethod($name)) {                    // behavior 中存在名为 $name 的方法,就认为该对象也存在                    return true;                }            }        }        return false;    }
/**     * Returns a list of behaviors that this component should behave as.     *     * Child classes may override this method to specify the behaviors they want to behave as.     *     * The return value of this method should be an array of behavior objects or configurations     * indexed by behavior names. A behavior configuration can be either a string specifying     * the behavior class or an array of the following structure:     *     * ~~~     * 'behaviorName' => [     *     'class' => 'BehaviorClass',     *     'property1' => 'value1',     *     'property2' => 'value2',     * ]     * ~~~     *     * Note that a behavior class must extend from [[Behavior]]. Behavior names can be strings     * or integers. If the former, they uniquely identify the behaviors. If the latter, the corresponding     * behaviors are anonymous and their properties and methods will NOT be made available via the component     * (however, the behaviors can still respond to the component's events).     *     * Behaviors declared in this method will be attached to the component automatically (on demand).     *     * 定义该对象中要用到的 behavior,格式如上     *     * @return array the behavior configurations.     */    public function behaviors()    {        return [];//返回一个空数组    }
 

 

 

因为此类继承了Object,下一篇我们着重分析一下Object.php这个类。

转载于:https://www.cnblogs.com/taokai/p/5401073.html

你可能感兴趣的文章
CentOS7安装mysql-server
查看>>
1. sys 模块
查看>>
WinForm 不规则窗体添加任务栏右键菜单
查看>>
从虚拟机copy到u盘的东西,在主机上不能用
查看>>
NRF52832初步使用
查看>>
反射+特性打造简洁的AJAX调用
查看>>
工作中编写存储过程小记
查看>>
CAFFE安装 CentOS无GPU
查看>>
Android的Handler总结
查看>>
Linux下实现免密登录
查看>>
eclipse异常关了,tomcat如何关
查看>>
zookeeper的配置参数详解(zoo.cfg)
查看>>
[转].net 获取远程IP 得到省市
查看>>
Python学习#1
查看>>
计算机操作系统作用讲解
查看>>
模拟字符串处理函数 stuff 的存储过程,对 ntext 字段进行stuff .
查看>>
yarn的笔记
查看>>
PHP实现函数重载
查看>>
SqlServer中查看索引的使用情况
查看>>
将文件夹下的所有txt文件加载到本文档中
查看>>