请问下面这3个函数要实现什么功能呢?具体的逻辑是怎么实现的呢?看不太懂,谢谢! /*
   用POST方式向平台请求数据和发送数据  
    
    */
    public function put(){
        return $this->send('post')->getData();
    }    private function send($mode = 'GET') {        $tempParam = $this->_params;
        foreach ($tempParam as $key => $value) {
            $tempParam[$key] = $this->formatUserParam($value);
        }        $systemdefault['key'] = $this->config->key;
        $systemdefault['format'] = strtolower($this->config->format);
        $systemdefault['ts'] = $this->timeStamp;
        $tempParam = array_merge($tempParam,$systemdefault);
        $this->_params = array_merge($this->_params,$systemdefault);        $mode = strtoupper($mode);
        $ReadMode = array_key_exists($mode, $this->config->postMode) ? $this->config->postMode[$mode] : 'postSend';        $this->_data = $this->$ReadMode($tempParam);        return $this;
    }
    private function getData() {
        if (empty($this->_data)) {
            return false;
        }
        $data = $this->formatData($this->_data);
        if ($this->config->format == 'array') {
            return json_decode($data,true);
        }else if($this->config->format == 'xml') {
            return $this->arrayToXml(json_decode($data,true));
        }else {
            return $data;
        }
    }

解决方案 »

  1.   


    用POST方式向平台请求数据和发送数据  
        
        */
        public function put(){
            return $this->send('post')->getData();
        }
    $this->send('post')->getData();为真执行对象的getDate(),假执行send('post')
      

  2.   

    getData是将数据按照config-format中要求的格式重新组织,比如组织成xml或者array.
    send其实还是重组发送数据的格式put函数好像有问题,getData是send()下面的函数?不是这样吧?
      

  3.   

    个人想法:应该就是访问一个数据源(如网址)
    send封装要传的参数。getData是获得返回的数据。并处理成array或xmlsend中还有一个主要的方法:
    $ReadMode = array_key_exists($mode, $this->config->postMode) ? $this->config->postMode[$mode] : 'postSend';$this->_data = $this->$ReadMode($tempParam);
    这个变量打印出来就明白了!
      

  4.   


    <?php
        public function put(){//公共函数,只能从这里调用
            return $this->send('post')->getData();//执行send('post'),并返回$this,再执行$this->getData();
        }
    private function send($mode = 'GET') {        $tempParam = $this->_params;//获取参数
            foreach ($tempParam as $key => $value) {//循环格式化参数
                $tempParam[$key] = $this->formatUserParam($value);
            }        $systemdefault['key'] = $this->config->key;//设置key为配置中的key
            $systemdefault['format'] = strtolower($this->config->format);//设置format的结果类型为配置中的format结果类型
            $systemdefault['ts'] = $this->timeStamp;//设置执行时间
            $tempParam = array_merge($tempParam,$systemdefault);//合并设置,
            $this->_params = array_merge($this->_params,$systemdefault);//合并设置,并赋值到_params属性        $mode = strtoupper($mode);
            $ReadMode = array_key_exists($mode, $this->config->postMode) ? $this->config->postMode[$mode] : 'postSend';
    //根据传如的$mode得到最终获取数据的方式,这里仅仅是得到方法名
            $this->_data = $this->$ReadMode($tempParam);//根据得到的方法名和参数设置,执行该方法,得到返回的数据,并赋值到_data属性        return $this;
        }
        private function getData() {
            if (empty($this->_data)) {//判断是否有数据,无数据直接返回false
                return false;
            }
            $data = $this->formatData($this->_data);//格式化数据
    //下面则是根据config属性里的format设置的数据类型,返回对应的数据
            if ($this->config->format == 'array') {
                return json_decode($data,true);
            }else if($this->config->format == 'xml') {
                return $this->arrayToXml(json_decode($data,true));
            }else {
                return $data;
            }
        }?>
      

  5.   

    好腻歪的代码!    public function put(){
            return $this->send('post')->getData();
        }等价于
        public function put(){
            $t = $this->send('post');
            return $t->getData();
        }其中
    send 完成取回传入数据的任务,传入数据中的缺省项将用用户或系统预置项充填。结果缓存在对象中
    getData 完成取回前述缓存的数据,数据格式在对象实例化时指定
      

  6.   

    send已经完成数据获取了
    getData,实际上是对send的获取的数据,按要求格式返回