/** * Fetches an external dataset. * * @param string $strURL The URL or directory of the file * @param string strType Declares the type of data (plain*, xml, bean, json) * @param string $strMethod Loading method for the external resource: open*, get, post * @return object|string */ private function xdr_external($strURL, $strType = 'plain', $strMethod = 'open') { // TESTING: $this->probe('xdr_external', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4); $strData = null; $strMethod = strtolower($strMethod); switch ($strMethod) { case 'get': case 'post': if (class_exists('\\REST\\Client')) { $req = new \REST\Client($strURL); $strData = $strMethod == 'get' ? $req->get() : $req->post(); } break; default: $strData = is_readable(self::$basepath . $strURL) ? file_get_contents(self::$basepath . $strURL) : false; break; } if (!$strData) { return; } if ($strType == 'xml') { return Xml::create($strData); } elseif ($strType == 'bean') { return Bean::create($strData); } elseif ($strType == 'json') { return json_decode($strData, 1); } else { return $strData; } }