public static function post($url, $formData, $formEncoding = null) { $request = new self(); $request->setMethod('POST'); $request->setUrl($url); $request->setFormData($formData, $formEncoding); return $request->exec(); }
public static function fail($obj, array $rules) { $val = new self($obj, $rules); return $val->exec() ? false : $val->getMessages(); }
/** * Creates instance of this class using configuration specified in array. * * $config is array containing these keys: * * - dsn * - username * - password * * Or: * * - driver * - database * - host * - username * - password * * See [PDO](http://www.php.net/manual/en/class.pdo.php) documentation for details. */ public static function createInstanceFromConfig($config) { $driver = isset($config['driver']) ? $config['driver'] : null; $host = isset($config['host']) ? $config['host'] : null; $port = isset($config['port']) ? $config['port'] : null; $database = isset($config['database']) ? $config['database'] : null; $username = isset($config['username']) ? $config['username'] : null; $password = isset($config['password']) ? $config['password'] : null; $log_query = isset($config['log_query']) ? $config['log_query'] : false; $log_explain = isset($config['log_explain']) ? $config['log_explain'] : false; if (isset($config['dsn'])) { $n = new self($config['dsn'], $username, $password, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); } else { if ($driver == 'mysql') { $n = new self("mysql:dbname={$database};host={$host};" . ($port !== null ? "port={$port};" : "") . "charset=UTF8", $username, $password, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); $n->exec("SET NAMES 'UTF8'"); try { $n->exec("SET time_zone = '" . date_default_timezone_get() . "'"); } catch (\Exception $ex) { error_log('Failed to sync timezone in MySQL with PHP: ' . $ex->getMessage()); } } else { if ($driver == 'sphinx') { $n = new self("mysql:dbname={$database};host={$host};port={$port};charset=UTF8", $username, $password, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); $n->exec("SET NAMES 'UTF8'"); $n->no_parenthesis_in_conditions = true; } else { if ($driver == 'sqlite') { $n = new self("sqlite:{$database}", null, null, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); } else { if ($host !== null) { $n = new self("{$driver}:dbname={$database};host={$host};charset=UTF8", $username, $password, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); } else { $n = new self("{$driver}:dbname={$database};charset=UTF8", $username, $password, array(self::ATTR_ERRMODE => self::ERRMODE_EXCEPTION)); } } } } } if ($n === null) { // This should not happen throw new \Exception('Not implemented.'); } $n->log_explain = $log_explain; $n->log_query = $log_query; return $n; }
/** * 静态 HTTP CURL GET 快速用法 * @param string $url 要抓取的URL * @return string 抓取结果 */ public static function xget($url) { $fuckoldphp = new self($url); return $fuckoldphp->exec($url); }
/** * Выполняет запрос с помошью такого же класса установленного на удаленном сервере */ private function requestFromServer() { $config = $this->config; unset($config['server']); unset($config['server_key']); $data = base64_encode( json_encode(array( 'url' => $this->url, 'curl_options' => $this->curl_options, 'config' => $config, 'cookies' => $this->cookies )) ); $signature = md5( $this->config['server_key'] .'-'. $data .'-'. $this->config['server_key'] ); $inCurl = new self(); $inCurl->exec('post', $this->config['server'], array( 'requestData' => $data, 'signature' => $signature )); if (!empty($inCurl->response)) { $request = json_decode($inCurl->response, true); $rSignature = $request['signature']; $request = json_decode(base64_decode($request['requestData']), true); $signature = md5( $this->config['server_key'] .'-'. $request['requestData'] .'-'. $this->config['server_key'] ); if ($signature == $rSignature) { foreach ($request as $k => $v) { $this->{$k} = $v; } } else { $this->error = 'Invalid signature'; } } else { $this->error = 'Invalid response'; } }