public static function getProductListByDistributer($distributerId) { Result::initializeStaticObjects(); $params = array('do' => 'getProductList', 'distributerId' => $distributerId); $curlResult = Curl::get_data(Config::JSON_URL . ProductList::SERVICE, http_build_query($params), ContentType::header_content_urlencoded); return json_encode($curlResult); }
/** * @param $url * @param $params * @param $ct * @return mixed * * This function returns Result Object */ public static function get_data($url, $params, $ct) { $ch = curl_init(); $connectionTimeout = 5; $timeout = 15; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connectionTimeout); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array($ct, "ACCEPT: */*")); $data = curl_exec($ch); curl_close($ch); $resultObj = Result::constructor_from_string($data); return $resultObj; }
/** * * @param type $obj * @return type * * This function removes null values from object */ static function object_unset_nulls($obj) { $arrObj = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($arrObj as $key => $val) { $val = is_array($val) || is_object($val) ? Result::object_unset_nulls($val) : $val; if (is_array($obj)) { $obj[$key] = $val; } else { $obj->{$key} = $val; } if ($val == null) { unset($obj->{$key}); } } return $obj; }