Action::__call PHP Method

__call() public method

魔术方法 有不存在的操作的时候
public __call ( string $method, array $parms ) : mix
$method string 方法名
$parms array
return mix
    public function __call($method, $parms)
    {
        if (0 === strcasecmp($method, ACTION_NAME)) {
            // 检查扩展操作方法
            $_action = C('_actions_');
            if ($_action) {
                // 'module:action'=>'callback'
                if (isset($_action[MODULE_NAME . ':' . ACTION_NAME])) {
                    $action = $_action[MODULE_NAME . ':' . ACTION_NAME];
                } elseif (isset($_action[ACTION_NAME])) {
                    // 'action'=>'callback'
                    $action = $_action[ACTION_NAME];
                }
                if (!empty($action)) {
                    call_user_func($action);
                    return;
                }
            }
            // 如果定义了_empty操作 则调用
            if (method_exists($this, '_empty')) {
                $this->_empty($method, $parms);
            } else {
                // 检查是否存在默认模版 如果有直接输出模版
                $this->display();
            }
        } elseif (in_array(strtolower($method), array('ispost', 'isget', 'ishead', 'isdelete', 'isput'))) {
            return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2));
        } else {
            throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
        }
    }

Usage Example

コード例 #1
0
ファイル: Controller.php プロジェクト: medz/thinksns-4
 /**
  * 重载方法
  *
  * @param string $method 方法名称
  * @param array  $params 方法参数
  * @author Seven Du <*****@*****.**>
  **/
 public final function __call($method, array $params = array())
 {
     /* class 重载之前 */
     $notCallOld = null;
     method_exists($this, 'classCallBefore') && ($notCallOld = $this->classCallBefore($method, $params));
     if ($notCallOld === null || $notCallOld === false) {
         parent::__call($method, $params);
     }
     /* class 重载之后 */
     method_exists($this, 'classCallAfter') && $this->classCallAfter($method, $params);
 }