<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Field; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\CurlUtil; use ModStart\Core\Util\SerializeUtil; 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($HDpl6) { $this->addVariables(array('jsonMode' => $HDpl6)); return $this; } public function editorHeight($HDpl6) { $this->addVariables(array('editorHeight' => $HDpl6)); return $this; } public function unserializeValue($HDpl6, AbstractField $E8QRJ) { if (null === $HDpl6) { return $HDpl6; } return @json_decode($HDpl6, true); } public function serializeValue($HDpl6, $xTADA) { return SerializeUtil::jsonEncode($HDpl6); } public function prepareInput($HDpl6, $xTADA) { goto mUBp6; YdmD1: return $Ese1E; goto cmi_v; WFjxM: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $HDpl6 && null === $Ese1E); goto YdmD1; mUBp6: $Ese1E = @json_decode($HDpl6, true); goto WFjxM; cmi_v: } public static function executeApi($HDpl6) { goto zZ8cE; y6jNM: if (!empty($HDpl6['headers'])) { foreach ($HDpl6['headers'] as $Q0rz2) { $nZw7W['header'][$Q0rz2['key']] = $Q0rz2['value']; } } goto jH1pO; sTFwq: $nZw7W = array(); goto ILtIv; rFUkj: $nZw7W['header'] = array(); goto y6jNM; zZ8cE: BizException::throwsIf('url为空', empty($HDpl6['url'])); goto dN0Qt; n95Vp: $nZw7W['method'] = $HDpl6['method']; goto rFUkj; km6wY: switch ($nZw7W['method']) { case 'POST': switch ($HDpl6['enctype']) { case 'FormData': goto yJYVw; Tw0Qp: break; goto nhaTF; U5NqR: $nZw7W['header']['Content-Type'] = 'multipart/form-data'; goto Tw0Qp; sgkt_: if (!empty($HDpl6['bodyParam'])) { foreach ($HDpl6['bodyParam'] as $Q0rz2) { $AXgEz[$Q0rz2['key']] = $Q0rz2['value']; } } goto U5NqR; yJYVw: $AXgEz = array(); goto sgkt_; nhaTF: case 'UrlEncoded': goto eMr1K; eMr1K: $AXgEz = array(); goto WHRej; lwvKP: break; goto kFy6z; WHRej: if (!empty($HDpl6['bodyParam'])) { foreach ($HDpl6['bodyParam'] as $Q0rz2) { $AXgEz[$Q0rz2['key']] = $Q0rz2['value']; } } goto s8sMt; s8sMt: $nZw7W['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto lwvKP; kFy6z: case 'Json': goto YrSO3; oBgdo: break; goto Eld5Z; YrSO3: $AXgEz = $HDpl6['bodyRaw']; goto I24cw; I24cw: $nZw7W['header']['Content-Type'] = 'application/json'; goto oBgdo; Eld5Z: } break; } goto dT0p2; dT0p2: $Z5nZL = CurlUtil::request($HDpl6['url'], $AXgEz, $nZw7W); goto r2aFL; ZED1C: BizException::throwsIf('enctype错误', empty($HDpl6['enctype']) || !in_array($HDpl6['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto Dfwos; jH1pO: if (!empty($HDpl6['query'])) { goto vIqI1; vIqI1: $vw3jY = array(); goto Sokr1; xBKpb: $AXgEz = $vw3jY; goto OQLYO; Sokr1: foreach ($HDpl6['query'] as $Q0rz2) { $vw3jY[$Q0rz2['key']] = $Q0rz2['value']; } goto xBKpb; OQLYO: } goto km6wY; r2aFL: return $Z5nZL; goto OgQhi; Dfwos: $AXgEz = array(); goto sTFwq; ILtIv: $nZw7W['returnHeader'] = true; goto n95Vp; dN0Qt: BizException::throwsIf('method错误', empty($HDpl6['method']) || !in_array($HDpl6['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto ZED1C; OgQhi: } }