<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\CurlUtil; class Json extends AbstractField { const MODE_API = 'api'; const MODE_DEFAULT = 'default'; protected function setup() { $this->addVariables(array('editorHeight' => '200px', 'jsonMode' => 'default')); } public function jsonMode($mdHu1) { $this->addVariables(array('jsonMode' => $mdHu1)); return $this; } public function editorHeight($mdHu1) { $this->addVariables(array('editorHeight' => $mdHu1)); return $this; } public function unserializeValue($mdHu1, AbstractField $Mk6lP) { if (null === $mdHu1) { return $mdHu1; } return @json_decode($mdHu1, true); } public function serializeValue($mdHu1, $DRh9Q) { return json_encode($mdHu1, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function prepareInput($mdHu1, $DRh9Q) { goto Pq3D0; eXz7t: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $mdHu1 && null === $L3_o5); goto s4V_J; Pq3D0: $L3_o5 = @json_decode($mdHu1, true); goto eXz7t; s4V_J: return $L3_o5; goto wKp3a; wKp3a: } public static function executeApi($mdHu1) { goto t6raq; sFlJS: BizException::throwsIf('method错误', empty($mdHu1['method']) || !in_array($mdHu1['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto BaR81; W1LVv: $pFM9U = array(); goto BI8IX; YqpkS: if (!empty($mdHu1['headers'])) { foreach ($mdHu1['headers'] as $pk5fc) { $Ur1_b['header'][$pk5fc['key']] = $pk5fc['value']; } } goto GF_ri; pnUid: $Ur1_b['header'] = array(); goto YqpkS; gl0RS: $N2Xaa = CurlUtil::request($mdHu1['url'], $pFM9U, $Ur1_b); goto XDAWl; BaR81: BizException::throwsIf('enctype错误', empty($mdHu1['enctype']) || !in_array($mdHu1['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto W1LVv; PppdN: $Ur1_b['method'] = $mdHu1['method']; goto pnUid; KyCrV: switch ($Ur1_b['method']) { case 'POST': switch ($mdHu1['enctype']) { case 'FormData': goto DhfN0; IUyuK: break; goto XepE_; zFP7m: if (!empty($mdHu1['bodyParam'])) { foreach ($mdHu1['bodyParam'] as $pk5fc) { $pFM9U[$pk5fc['key']] = $pk5fc['value']; } } goto fdhJv; DhfN0: $pFM9U = array(); goto zFP7m; fdhJv: $Ur1_b['header']['Content-Type'] = 'multipart/form-data'; goto IUyuK; XepE_: case 'UrlEncoded': goto kHRfW; kHRfW: $pFM9U = array(); goto U5UHz; U5UHz: if (!empty($mdHu1['bodyParam'])) { foreach ($mdHu1['bodyParam'] as $pk5fc) { $pFM9U[$pk5fc['key']] = $pk5fc['value']; } } goto ZP4Dn; ZP4Dn: $Ur1_b['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto jRRbc; jRRbc: break; goto CrN2N; CrN2N: case 'Json': goto DiDqP; uWNG1: break; goto VSlH2; q4A_G: $Ur1_b['header']['Content-Type'] = 'application/json'; goto uWNG1; DiDqP: $pFM9U = $mdHu1['bodyRaw']; goto q4A_G; VSlH2: } break; } goto gl0RS; vbFeY: $Ur1_b['returnHeader'] = true; goto PppdN; GF_ri: if (!empty($mdHu1['query'])) { goto p4XdA; p4XdA: $qeoqS = array(); goto kAxQy; kAxQy: foreach ($mdHu1['query'] as $pk5fc) { $qeoqS[$pk5fc['key']] = $pk5fc['value']; } goto zk89N; zk89N: $pFM9U = $qeoqS; goto m1Cdd; m1Cdd: } goto KyCrV; BI8IX: $Ur1_b = array(); goto vbFeY; XDAWl: return $N2Xaa; goto QVisK; t6raq: BizException::throwsIf('url为空', empty($mdHu1['url'])); goto sFlJS; QVisK: } }