colly_wyx
2018-05-18 50a53f7db63c5729b0ddbc93367117cf35ccf03c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
 * PhalApi_Response_JsonP JSON响应类
 *
 * @package     PhalApi\Response
 * @license     http://www.phalapi.net/license GPL 协议
 * @link        http://www.phalapi.net/
 * @author      dogstar <chanzonghuang@gmail.com> 2015-02-09
 */
 
class PhalApi_Response_JsonP extends PhalApi_Response {
 
    protected $callback = '';
 
    /**
     * @param string $callback JS回调函数名
     */
    public function __construct($callback) {
        $this->callback = $this->clearXss($callback);
 
        $this->addHeaders('Content-Type', 'text/javascript; charset=utf-8');
    }
 
    /**
     * 对回调函数进行跨站清除处理
     *
     * - 可使用白名单或者黑名单方式处理,由接口开发再实现
     */
    protected function clearXss($callback) {
        return $callback;
    }
 
    protected function formatResult($result) {
        echo $this->callback . '(' . json_encode($result) . ')';
    }
}