yii2架構隨筆19

來源:互聯網
上載者:User

標籤:

    public function canGetProperty($name, $checkVars = true)    {        // property_exists — 檢查對象或類是否具有該屬性        return method_exists($this, ‘get‘ . $name) || $checkVars && property_exists($this, $name);    }    /**     * Returns a value indicating whether a property can be set.     * 返回一個值指示是否可以設定一個屬性。     * A property is writable 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);     *     * 檢查對象或類是否能夠設定 $name 屬性,如果 $checkVars 為 true,則不局限於是否有 setter     *     * @param string $name the property name     * @param boolean $checkVars whether to treat member variables as properties     * @return boolean whether the property can be written     * @see canGetProperty()     */    public function canSetProperty($name, $checkVars = true)    {        return method_exists($this, ‘set‘ . $name) || $checkVars && property_exists($this, $name);//檢查對象或類是否能夠設定 $name 屬性,返回Boolean值。    }    /**     * Returns a value indicating whether a method is defined.     * 返回一個值指示是否定義了一個方法。     * The default implementation is a call to php function `method_exists()`.     * You may override this method when you implemented the php magic method `__call()`.     *     * 檢查對象或類是否具有 $name 方法     *     * @param string $name the method name     * @return boolean whether the method is defined     */    public function hasMethod($name)    {        return method_exists($this, $name);//返回Boolean值。    }    }

下面來介紹console/Controller.php

<?php/** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yii Software LLC * @license http://www.yiiframework.com/license/ */namespace yii\console;use Yii;use yii\base\Action;use yii\base\InlineAction;use yii\base\InvalidRouteException;use yii\helpers\Console;/** * Controller is the base class of console command classes. * 控制器是控制台命令類的基類. * * A console controller consists of one or several actions known as sub-commands. * 一個控制台控制器由一個或幾個動作稱為sub-commands。 * Users call a console command by specifying the corresponding route which identifies a controller action. * 使用者調用一個控制台命令通過指定相應的路線確定控制器動作 * The `yii` program is used when calling a console command, like the following: * yii的程式調用時使用控制台命令,如下: * * ~~~ * yii <route> [--param1=value1 --param2 ...] * ~~~ * * * @property string $help This property is read-only. * @property string $helpSummary This property is read-only. * * @author Qiang Xue <[email protected]> * @since 2.0 */class Controller extends \yii\base\Controller{    const EXIT_CODE_NORMAL = 0;    const EXIT_CODE_ERROR = 1;    /**     * @var boolean whether to run the command interactively.     * 是否運行該命令互動     */    public $interactive = true;    /**     * @var boolean whether to enable ANSI color in the output.     * 是否支援ANSI顏色在輸出     * If not set, ANSI color will only be enabled for terminals that support it.     * 如果沒有設定,ANSI顏色只會支援終端支援它。     */    public $color;  /**     * Runs an action with the specified action ID and parameters.     * 運行一個動作與ID指定的操作和參數。     * If the action ID is empty, the method will use [[defaultAction]].     * 如果行動ID為空白,該方法將使用[[defaultAction]]。     * @param string $id the ID of the action to be executed.     * @param array $params the parameters (name-value pairs) to be passed to the action.     * @return integer the status of the action execution. 0 means normal, other values mean abnormal.     * @throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.     * @throws Exception if there are unknown options or missing arguments     * @see createAction     */    public function runAction($id, $params = [])    {        if (!empty($params)) {            // populate options here so that they are available in beforeAction().            // 擷取允許的參數,可以在beforeAction中拿到            $options = $this->options($id);            foreach ($params as $name => $value) {                if (in_array($name, $options, true)) {                    // 如果參數在允許的options,才會將值賦給controller的屬性                    $default = $this->$name;                    // 如果該屬性的預設值是數組,就根據逗號和空格(包含" ", \r, \t, \n, \f)的組合分隔value值                    $this->$name = is_array($default) ? preg_split(‘/\s*,\s*/‘, $value) : $value;                    unset($params[$name]);                } elseif (!is_int($name)) {                    throw new Exception(Yii::t(‘yii‘, ‘Unknown option: --{name}‘, [‘name‘ => $name]));                }            }        }        return parent::runAction($id, $params);    }

 

yii2架構隨筆19

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.