/** * 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 xdrRetriveExternal($strURL, $strType = 'plain', $strMethod = 'open') { // TESTING: $this->probe('xdrRetriveExternal', 'Trying to load the external resource now: '.$strURL.'; Method: '.$strMethod.'; Type: '.$strType, 4); $strData = null; $strMethod = strtolower($strMethod); switch ($strMethod) { case 'get': if (class_exists('\\REST\\Client')) { $req = new \REST\Client($strURL); $strData = $req->post(); } else { // If the REST library is not present, simply use file_get_contents $strData = file_get_contents($strURL); } break; case 'post': if (!class_exists('\\REST\\Client')) { throw new Exception('Class REST\\Client not found. Please include the library from https://github.com/zeyon/rest'); } $req = new \REST\Client($strURL); $strData = $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; } }
/** * 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; } }