public function init() { $controller = \PMVC\plug('controller'); if (empty($controller)) { return !trigger_error('Need initial controller first', E_USER_WARNING); } $request = $controller->getRequest(); $method = $this->getMethod(); $request->setMethod($method); if ('GET' === $method) { $inputs =& $_GET; } else { $isJsonInput = 'application/json' === getenv('CONTENT_TYPE'); if ($isJsonInput || 'PUT' === $method) { $input = file_get_contents("php://input"); if ($isJsonInput) { $inputs = (array) \PMVC\fromJson($input); } else { parse_str($input, $inputs); } } else { $inputs =& $_POST; } } \PMVC\set($request, $inputs); }
public function request($url, $params = []) { $respond = null; $url->set($this->getBaseUrl()); $header = ['X-Algolia-Application-Id: ' . $this['app'], 'X-Algolia-API-Key: ' . $this['key']]; $params[CURLOPT_HTTPHEADER] = array_merge(\PMVC\value($params, [CURLOPT_HTTPHEADER], []), $header); $curl = \PMVC\plug('curl'); $curl->get((string) $url, function ($r) use(&$respond, $url) { if (500 > $r->code) { $respond = (object) ['header' => $r->header, 'body' => \PMVC\fromJson($r->body), 'code' => $r->code]; } else { return !trigger_error('Get result error. Error Code:' . $r->code . ' url: ' . $url); } })->set($params); $curl->process(); return $respond; }
private function _parseDataType($declaration, $lastColName) { $declaration = preg_split('/[\\s]+/', $declaration); $last = join(' ', array_slice($declaration, 2)); $json = \PMVC\fromJson($last); $declaration = ['type' => $declaration[0], 'name' => $declaration[1]]; if (!is_string($json)) { $declaration = array_replace($declaration, (array) $json); } else { if (is_null($lastColName)) { $declaration[] = $json; } else { $declaration[$lastColName] = $json; } } return $declaration; }
/** * add guess date */ public function addGuessDate($guess_dates, $force = null) { $plugGuid = \PMVC\plug('guid'); $db_images = $plugGuid->getDb('OutSource104Images'); $db_dates = $plugGuid->getDb('OutSource104Dates'); foreach ($guess_dates as $token => $v) { $is_save = false; if (!isset($db_dates[$v['date']]) && !isset($db_images[$token])) { $this->excuteSaveGuessDate($token, $v); $is_save = true; } if ($force && !$is_save) { $origin_date = \PMVC\fromJson($db_images[$token])->date; unset($db_dates[$origin_date]); $this->excuteSaveGuessDate($token, $v); } } }
public function getDimension() { $url = \PMVC\plug('url')->getUrl($this['dimensionUrl']); $url->query = $this['dimensionQuery']; $curl = \PMVC\plug('curl'); $curl->get($url, function ($r) { $json = \PMVC\fromJson($r->body, true); if (is_array($json)) { $this->unsetCli($json); \PMVC\dev(function () use($json) { return $json; }, 'dimension'); \PMVC\option('set', $json); } else { $dot = \PMVC\plug('dotenv'); if ($dot->fileExists($this['env'])) { $dot->toPMVC($this['env']); } } })->set([CURLOPT_CONNECTTIMEOUT => 1]); $curl->process(); }
/** * Return curl execute result * * @return CurlResponder */ public function process(array $more = [], $func = 'curl_exec') { $oCurl = $this->getInstance(); if (!$oCurl) { return !trigger_error('Not set any CURL option yet.'); } $return = call_user_func($func, $oCurl); $r = new CurlResponder($return, $this, $more); \PMVC\dev(function () use($r) { return ['option' => \PMVC\plug('curl')->opt_to_str()->all($this->_opts), 'respond' => $r, 'body' => \PMVC\fromJson($r->body)]; }, 'curl'); if (is_callable($this->_function)) { call_user_func($this->_function, $r, $this); } $this->clean(); return true; }