Curl\Curl::setJsonDecoder PHP Method

setJsonDecoder() public method

Set JSON Decoder
public setJsonDecoder ( $function )
$function
    public function setJsonDecoder($function)
    {
        if (is_callable($function)) {
            $this->jsonDecoder = $function;
        }
    }

Usage Example

Exemplo n.º 1
0
 public static function run($method, $params = [])
 {
     self::$defaultParam = ['method' => $method, 'module' => 'API', 'token_auth' => STAT_API_TOKEN, 'format' => 'JSON', 'expanded ' => true, 'idSite' => 1, 'filter_offset' => \yii::$app->request->get('filter_offset', 0), 'filter_limit' => \yii::$app->request->get('filter_limit', 50)];
     $params['formatDate'] = isset($params['formatDate']) ? $params['formatDate'] : null;
     if ($params['formatDate'] !== false) {
         self::formatDate();
     }
     unset($params['formatDate']);
     $params = array_merge(self::$defaultParam, $params);
     $params = array_filter($params);
     $curl = new Curl();
     $curl->setJsonDecoder(function ($response) {
         $json_obj = json_decode($response, true);
         if (!($json_obj === null)) {
             $response = $json_obj;
         }
         return $response;
     });
     $curl->get(STAT_API_URL, $params);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
All Usage Examples Of Curl\Curl::setJsonDecoder