function TestOfResolvePath() { $this->caseTitle('resolvePath'); $test = 'domain.com/dir_1/dir_2/dir_3/./../../../'; $this->log($test); $result = Amslib_File::resolvePath($test); $this->log($result); $this->assertEqual($result, 'domain.com/'); $test = 'domain.com/dir_1/dir_2/dir_3/./../../../test/././../new_dir/'; $this->log($test); $result = Amslib_File::resolvePath($test); $this->log($result); $this->assertEqual($result, 'domain.com/new_dir/'); $test = 'domain.com/dir_1/dir_2/dir_3/./../../../test/dir4/../final'; $this->log($test); $result = Amslib_File::resolvePath($test); $this->log($result); $this->assertEqual($result, 'domain.com/test/final'); }
/** * method: importRouter * * todo: write documentation */ public static function importRouter($import) { $params = self::encodeURLPairs($import, "/", array("output", "url", "name")); // acquire the latest route for the export url and construct the url to call the external remote service $route = self::getRoute("service:framework:router:export:" . $import["output"]); $import["url"] = Amslib_File::resolvePath(Amslib_Website::expandPath($import["url"])); $import["url_full"] = rtrim($import["url"], "/") . rtrim($route["src"]["default"], "/") . "/{$params}/"; if ($import["output"] == "json") { // We are going to install a router using json as a data transfer medium // Acquire the json, decode it and obtain the domain $data = Amslib_File::getContents($import["url_full"], $error); if (strlen($error)) { Amslib_Debug::log("FAILED TO IMPORT ROUTER IN JSON FORMAT, OR OTHER PROBLEM DETECTED", $error, error_get_last()); } $data = json_decode($data, true); $domain = $data["domain"]; // For each route in the cache, create a new route in the local router, giving the name, group, domain and route data // You are not supposed to update the url cache, imported routes are not accessible through url // The reason for this is because it doesnt make sense a url from a remote system will be processed by the local system // All url requests for imported services should goto the remote server directly foreach (Amslib_Array::valid($data["cache"]) as $route) { // We cannot use the service inheritance when importing a remote router unset($route["extend"]); self::setRoute($route["name"], $route["group"], $domain, $route, false); } // Record that we imported something so we can possibly use this information self::setImportData($import["name"], $import); } else { if ($import["output"] == "xml") { $data = Amslib_File::getContents($import["url_full"], $error); if (strlen($error)) { Amslib_Debug::log("FAILED TO IMPORT ROUTER IN XML FORMAT, OR OTHER PROBLEM DETECTED", $error, error_get_last()); } // TODO: implement the logic to import from XML } } }
/** * method: relative * * todo: write documentation */ public static function relative($url = "", $resolve = false) { if (!is_string($url)) { Amslib_Debug::log("stack_trace", $url); return false; } // When the string has this protocol marker, the url part is already relative to the document root if (strpos($url, "://") !== false) { list($protocol, $domain, $url) = self::parseURL($url); // Because we have a url with a protocol, it must mean the url parsed is already relative return $url; } $url = Amslib_File::relative(self::$location . $url); return $resolve ? Amslib_File::resolvePath($url) : $url; }