<?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($cBDsM) { $this->addVariables(array('jsonMode' => $cBDsM)); return $this; } public function editorHeight($cBDsM) { $this->addVariables(array('editorHeight' => $cBDsM)); return $this; } public function unserializeValue($cBDsM, AbstractField $Ldet7) { if (null === $cBDsM) { return $cBDsM; } return @json_decode($cBDsM, true); } public function serializeValue($cBDsM, $GMqtO) { return SerializeUtil::jsonEncode($cBDsM); } public function prepareInput($cBDsM, $GMqtO) { goto SMPyx; y2NYr: return $fgYNs; goto vkD4u; SMPyx: $fgYNs = @json_decode($cBDsM, true); goto RNUDC; RNUDC: BizException::throwsIf($this->label . ' ' . L('Json Format Error'), $cBDsM && null === $fgYNs); goto y2NYr; vkD4u: } public static function executeApi($cBDsM) { goto WBYd3; w2v3E: if (!empty($cBDsM['query'])) { goto pmSAk; T0XRz: $mattM = $nYIOS; goto kj3sn; pmSAk: $nYIOS = array(); goto MJNPE; MJNPE: foreach ($cBDsM['query'] as $knQyJ) { $nYIOS[$knQyJ['key']] = $knQyJ['value']; } goto T0XRz; kj3sn: } goto jB4lw; Dpkrb: $bCCWW = CurlUtil::request($cBDsM['url'], $mattM, $vFR1v); goto CuYkR; CuYkR: return $bCCWW; goto MC2W1; mFGN3: if (!empty($cBDsM['headers'])) { foreach ($cBDsM['headers'] as $knQyJ) { $vFR1v['header'][$knQyJ['key']] = $knQyJ['value']; } } goto w2v3E; cbaAX: BizException::throwsIf('method错误', empty($cBDsM['method']) || !in_array($cBDsM['method'], array('GET', 'POST', 'PUT', 'DELETE'))); goto uN069; knFeW: $vFR1v['method'] = $cBDsM['method']; goto CHCea; CHCea: $vFR1v['header'] = array(); goto mFGN3; NuYV5: $mattM = array(); goto Mv7Zf; WBYd3: BizException::throwsIf('url为空', empty($cBDsM['url'])); goto cbaAX; Mv7Zf: $vFR1v = array(); goto gI0dn; gI0dn: $vFR1v['returnHeader'] = true; goto knFeW; uN069: BizException::throwsIf('enctype错误', empty($cBDsM['enctype']) || !in_array($cBDsM['enctype'], array('FormData', 'UrlEncoded', 'Json'))); goto NuYV5; jB4lw: switch ($vFR1v['method']) { case 'POST': switch ($cBDsM['enctype']) { case 'FormData': goto a81Mf; dmSZY: break; goto OTSCa; MdZdK: if (!empty($cBDsM['bodyParam'])) { foreach ($cBDsM['bodyParam'] as $knQyJ) { $mattM[$knQyJ['key']] = $knQyJ['value']; } } goto etfly; a81Mf: $mattM = array(); goto MdZdK; etfly: $vFR1v['header']['Content-Type'] = 'multipart/form-data'; goto dmSZY; OTSCa: case 'UrlEncoded': goto Ptn5f; Ua3Qk: $vFR1v['header']['Content-Type'] = 'application/x-www-form-urlencoded'; goto SrZ04; cV71b: if (!empty($cBDsM['bodyParam'])) { foreach ($cBDsM['bodyParam'] as $knQyJ) { $mattM[$knQyJ['key']] = $knQyJ['value']; } } goto Ua3Qk; Ptn5f: $mattM = array(); goto cV71b; SrZ04: break; goto mA1CX; mA1CX: case 'Json': goto gpBo2; fijpD: $vFR1v['header']['Content-Type'] = 'application/json'; goto SJrPc; SJrPc: break; goto H9TSc; gpBo2: $mattM = $cBDsM['bodyRaw']; goto fijpD; H9TSc: } break; } goto Dpkrb; MC2W1: } }