public function __construct($source = NULL)
 {
     $this->source = false;
     $this->handler = false;
     if ($this->isValid($source)) {
         $this->source = $source;
     } else {
         $session = Amslib_SESSION::get(self::SR, false, $remove);
         if ($this->isValid($session)) {
             $this->source = $session;
         }
     }
 }
 public function execute($raw = false)
 {
     $reply = $exception = false;
     if ($this->debug) {
         $raw = true;
     }
     try {
         if (strlen($this->url) == 0) {
             throw new Exception("webservice url was invalid");
         }
         $curl = curl_init();
         //	This is just the first version of this code, it works, but it's hardly very elegant.
         //	Also, I think I need to merge code from Amslib_Plugin_Service because we seem to be duplicating
         //	it a lot here, perhaps we need to have a common shared object with methods to set and get from
         //	the storage variable
         if ($this->sharedSession) {
             $key_remote = "/amslib/webservice/session/remote/";
             $key_request = "/amslib/webservice/session/request/";
             $id_session = Amslib_SESSION::get($key_remote);
             if ($id_session) {
                 $cookie = "PHPSESSID={$id_session}; path=/";
                 //.Amslib_Router_URL::getFullURL();
                 curl_setopt($curl, CURLOPT_COOKIE, $cookie);
                 Amslib_SESSION::set("REQUEST_COOKIE", $cookie);
             } else {
                 $this->params[$key_request] = true;
             }
         }
         $params = http_build_query(Amslib_Array::valid($this->params));
         if ($this->username && $this->password) {
             curl_setopt($curl, CURLOPT_USERPWD, "{$this->username}:{$this->password}");
         }
         curl_setopt($curl, CURLOPT_URL, $this->url);
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_HTTP_VERSION, 1.0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, false);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
         $reply = curl_exec($curl);
         if (!$reply || !strlen($reply)) {
             Amslib_Debug::log("CURL ERROR", curl_error($curl), Amslib_Debug::dump($reply));
             curl_close($curl);
             return false;
         }
         curl_close($curl);
         $response = new Amslib_Webservice_Response($reply);
         if ($this->sharedSession && !$id_session) {
             $data = $response->getData("amslib");
             if ($value = $data->getKey($key_remote)) {
                 Amslib_SESSION::set($key_remote, $value);
             }
         }
         return $response;
     } catch (Exception $e) {
         $exception = $e->getMessage();
     }
     Amslib_Debug::log("EXCEPTION: ", $exception, "WEBSERVICE URL: ", $this->url, "PARAMS: ", $this->params, "DATA: ", $reply);
     return false;
 }
 /**
  * 	method:	hasData
  *
  * 	todo: write documentation
  */
 public static function hasData($remove = true)
 {
     if (self::$serviceData === NULL || $remove == false) {
         self::$serviceData = Amslib_SESSION::get(self::SR, false, $remove);
     }
     return self::$serviceData ? true : false;
 }
 /**
  * 	method:	getLanguage
  *
  * 	Obtain the language set in the session for the specific type of language "domain" (normally website or content)
  *
  * 	parameters:
  * 		$name - The name of the language to retrieve
  *
  * 	returns:
  * 		Boolean false if obtaining a language has failed, or the 4 character language code, e.g: en_GB, en_ES
  *
  * 	notes:
  *		-	See the notes from the method Amslib_Plugin_Application::setLanguage for what the
  *			language code, domains terms mean.
  * 		-	Remember also, if a language is not found, the first language in the approved list will be
  * 			selected, stored and returned as a sensible default
  */
 public static function getLanguage($name)
 {
     $lang = false;
     if (is_string($name) && strlen($name)) {
         $lang = Amslib_SESSION::get(Amslib_File::reduceSlashes(self::$langKey . "/{$name}"));
     }
     if (!$lang) {
         $lang = self::setLanguage($name, current(self::getLanguageList($name)));
     }
     return $lang;
 }