Beispiel #1
0
 /**
  * 	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
         }
     }
 }