config = json_decode($config); $this->name = $this->config->name; $this->type = $this->config->type; $this->url = $this->config->url; } public function setOptions() { $this->parameters = func_get_args(); foreach($this->config->required as $option) { $this->options[$option] = array_shift($this->parameters); } if(isset($this->optional)) { foreach($this->optional as $option=>$defaultValue) { $value = array_shift($this->parameters); $this->options[$option] = $value ? $value : $defaultValue; } } $this->fetchRawData(); $this->parseData(); } protected function fetchRawData() { $this->curlRequest(); } protected function parseData() { } // allow force public function getParsedData() { if(!isset($rawData)) { $this->fetchRawData(); } if(empty($parsedData)) { $this->parseData(); } return $this->validateParsedData(); } protected function validateParsedData() { } protected function parsedUrl() { $url = $this->url; foreach($this->options as $option=>$value) { $url = preg_replace("/\{$option\}/","$value",$url); } return $url; } protected function curlRequest() { $this->curl = curl_init(); curl_setopt($this->curl, CURLOPT_URL, $this->parsedUrl()); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); $this->rawData = curl_exec($this->curl); curl_close($this->curl); } protected function urlify($string) { $pattern ="{\\b((https?|telnet|gopher|file|wais|ftp) : [\\w/\\#~:.?+=&%@!\\-]+?) (?= [.:?\\-]* (?:[^\\w/\\#~:.?+=&%@!\\-] |$) ) }x"; return preg_replace($pattern,"$1", $string); } public function debugInformation() { echo '
'; print_r($this->rawData); echo '
'; print_r($this->getParsedData()); echo '