<?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($wvO30) { $this->addVariables(array('jsonMode' => $wvO30)); return $this; } public function editorHeight($wvO30) { $this->addVariables(array('editorHeight' => $wvO30)); return $this; } public function unserializeValue($wvO30, AbstractField $Lgjfa) { if (null === $wvO30) { return $wvO30; } return @json_decode($wvO30, true); } public function serializeValue($wvO30, $w5oww) { return json_encode($wvO30, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function prepareInput($wvO30, $w5oww) { goto FlL0T; aL1Fm: return $f8Hsc; goto fr9iu; hUJQT: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $wvO30 && null === $f8Hsc); goto aL1Fm; FlL0T: $f8Hsc = @json_decode($wvO30, true); goto hUJQT; fr9iu: } public static function executeApi($wvO30) { goto iNViy; PliGS: return $pTwJr; goto Xl7D9; azve6: $yFteQ['header'] = array(); goto ZqU9l; AH7Qo: $yFteQ = array(); goto ww7yK; I5grg: BizException::throwsIf('enctype错误', empty($wvO30['enctype']) || !in_array($wvO30['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto tqflv; ZqU9l: if (!empty($wvO30['headers'])) { foreach ($wvO30['headers'] as $uTz0e) { $yFteQ['header'][$uTz0e['key']] = $uTz0e['value']; } } goto s1lIo; tqflv: $oK4I3 = array(); goto AH7Qo; iNViy: BizException::throwsIf('url为空', empty($wvO30['url'])); goto zV9uo; ww7yK: $yFteQ['returnHeader'] = true; goto FRnaA; zV9uo: BizException::throwsIf('method错误', empty($wvO30['method']) || !in_array($wvO30['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto I5grg; FRnaA: $yFteQ['method'] = $wvO30['method']; goto azve6; s1lIo: if (!empty($wvO30['query'])) { goto v6WCi; s01fO: foreach ($wvO30['query'] as $uTz0e) { $hAzJ1[$uTz0e['key']] = $uTz0e['value']; } goto YVoXm; YVoXm: $oK4I3 = $hAzJ1; goto aLpnr; v6WCi: $hAzJ1 = array(); goto s01fO; aLpnr: } goto dmDeg; zTgKG: $pTwJr = CurlUtil::request($wvO30['url'], $oK4I3, $yFteQ); goto PliGS; dmDeg: switch ($yFteQ['method']) { case 'POST': switch ($wvO30['enctype']) { case 'FormData': goto JL5Xm; JL5Xm: $oK4I3 = array(); goto LQbCc; rOAG0: break; goto Mlmxz; LQbCc: if (!empty($wvO30['bodyParam'])) { foreach ($wvO30['bodyParam'] as $uTz0e) { $oK4I3[$uTz0e['key']] = $uTz0e['value']; } } goto e_stx; e_stx: $yFteQ['header']['Content-Type'] = 'multipart/form-data'; goto rOAG0; Mlmxz: case 'UrlEncoded': goto LaR8c; zXoOh: if (!empty($wvO30['bodyParam'])) { foreach ($wvO30['bodyParam'] as $uTz0e) { $oK4I3[$uTz0e['key']] = $uTz0e['value']; } } goto kqz80; kqz80: $yFteQ['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto duPb2; duPb2: break; goto x2R6N; LaR8c: $oK4I3 = array(); goto zXoOh; x2R6N: case 'Json': goto bDisW; Bv9_5: break; goto Omfzb; oJNXY: $yFteQ['header']['Content-Type'] = 'application/json'; goto Bv9_5; bDisW: $oK4I3 = $wvO30['bodyRaw']; goto oJNXY; Omfzb: } break; } goto zTgKG; Xl7D9: } }