Пример #1
0
 public function query($query = null)
 {
     $status = self::STATUS_NOTCONNECTED;
     $context = $this->_connection;
     $wrapper = $this->config('wrapper');
     if ($context) {
         if (DevValue::isNotNull($query)) {
             if (DevArray::isAssoc($query)) {
                 $this->_data = $query;
             } else {
                 if (is_string($query)) {
                     $data = urlencode($query);
                     stream_context_set_option($context, $wrapper, 'content', $data);
                     $this->_result = file_get_contents($target, false, $context);
                     $this->status($this->_result !== false ? self::STATUS_SUCCESS : self::STATUS_FAILED);
                     return true;
                 }
             }
         }
         $data = HTTP::query($this->_data);
         stream_context_set_option($context, $wrapper, 'content', $data);
         $this->_result = file_get_contents($target, false, $context);
         if ($this->_result !== false) {
             $status = self::STATUS_SUCCESS;
         }
     }
     $this->status($status);
 }
Пример #2
0
 public function query($query = null)
 {
     $curl = $this->_connection;
     $method = strtolower($this->config('method'));
     if ($curl) {
         if (DevValue::isNotNull($query)) {
             if (DevArray::isAssoc($query)) {
                 //$this->_data = $query;
                 $this->assign($query);
             }
         }
         $data = $this->_data;
         //set the url, number of POST vars, POST data
         if ($method == 'post') {
             curl_setopt($curl, CURLOPT_POST, count($data));
             curl_setopt($curl, CURLOPT_POSTFIELDS, HTTP::query($data));
         } elseif ($method == 'get') {
             curl_setopt($curl, CURLOPT_URL, $this->config('target') . '/' . HTTP::query($data));
         }
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         //execute post
         $this->_result = curl_exec($curl);
         $status = $this->_result ? self::STATUS_SUCCESS : self::STATUS_FAILED;
     } else {
         $status = self::STATUS_NOTCONNECTED;
     }
     $this->status($status);
 }
Пример #3
0
 public function query($query = null)
 {
     $socket = $this->_connection;
     $status = '';
     if ($socket) {
         $method = $method ? $method : $this->config('method');
         $data = HTTP::query($this->_data);
         $method = strtoupper($method);
         $request = '';
         $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'PHP/' . phpversion();
         if ($method == 'GET') {
             $request .= '/' . $this->_url . '?';
             $request .= $data;
             $request .= "\r\n";
             $request .= "User-Agent: Dev-Elation\r\n";
             $request .= "Connection: Close\r\n";
             $request .= "Content-Length: 0\r\n";
             $cmd = "GET {$request} HTTP/1.0\r\nHost: " . $this->_host . "\r\n\r\n";
         } elseif ($method == 'POSTS') {
             $request .= '/' . $this->_url;
             $request .= "\r\n";
             $request .= "User-Agent: Dev-Elation\r\n";
             $request .= "Content-Type: application/x-www-form-urlencoded\r\n" . ($request .= "Content-Length: " . strlen($data) . "\r\n");
             $request .= $data;
         } else {
             $status = self::STATUS_FAILED;
             $this->status($status);
             return false;
         }
         $cmd = "{$method} {$request} HTTP/1.1\r\nHost: " . $this->_host . "\r\n";
         fputs($sock, $cmd);
         while (!feof($sock)) {
             $data .= fgets($sock, 1024);
         }
         $this->_result = $data;
         $status = $this->_result ? self::STATUS_SUCCESS : self::STATUS_FAILED;
     } else {
         $status = self::STATUS_NOTCONNECTED;
     }
     $this->status($status);
 }
Пример #4
0
 static function query($formdata, $numeric_prefix = null, $key = null)
 {
     if (function_exists('http_build_query') && DevValue::isNull($key)) {
         return http_build_query($formdata, $numeric_prefix);
     }
     $res = array();
     foreach ((array) $formdata as $k => $v) {
         $tmp_key = urlencode(is_int($k) && $numeric_prefix ? $numeric_prefix . $k : $k);
         if ($key) {
             $tmp_key = $key . '[' . $tmp_key . ']';
         }
         if (is_array($v) || is_object($v)) {
             $res[] = HTTP::query($v, null, $tmp_key);
         } else {
             $res[] = $tmp_key . "=" . str_replace('%2F', '/', urlencode($v));
         }
         /*
         If you want, you can write this as one string:
         $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );
         */
     }
     $separator = ini_get('arg_separator.output');
     return implode($separator, $res);
 }