/**
  * execute 
  *      Main wrapper command for executing rightscale fetches
  *
  * @param mixed $className 
  * @static
  * @access public
  * @return void
  */
 public static function execute($className, $forceRelogin = false)
 {
     if (!preg_match(self::CLASSNAME_REGEX, $className)) {
         $className = RS_LOC_PREFIX . $className;
     }
     if (!class_exists($className)) {
         throw new RSQueryWrapperException($className . self::MISSING_CLASS);
     } else {
         if ($className == RS_LOC_PREFIX) {
             throw new RSQueryWrapperException(self::COLLISION . RS_LOC_PREFIX);
         }
     }
     $result = null;
     $queryObj = new RSQueryObj();
     $rootClass = new $className($queryObj);
     if ($className == 'RSMultiAD') {
         $rs = new RS(NULL);
         RSDataGrouperCache::init();
         foreach ($queryObj->getArrayLoop() as $loop) {
             $rootClass->buildQueryUrl('array', $queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs);
             $rs->fetch($queryObj);
         }
         foreach ($queryObj->getDeploymentLoop() as $loop) {
             $rootClass->buildQueryUrl('deployment', $queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs);
             $rs->fetch($queryObj);
         }
         $cache = RSDataGrouperCache::getCache(true);
         if (!!($executor = RSArgParser::getExecutor())) {
             $executorObj = new $executor();
             $result = $executorObj->execute($cache);
         }
     } else {
         $rs = new RS(NULL);
         RSDataGrouperCache::init();
         foreach ($queryObj->getLoop() as $loop) {
             $rootClass->buildQueryUrl($queryObj, $loop);
             $rs->addObserver($queryObj);
             RSLoginWrapper::login($rs, $forceRelogin);
             $rs->fetch($queryObj);
         }
         $cache = RSDataGrouperCache::getCache(true);
         if (!!($executor = RSArgParser::getExecutor())) {
             $executorObj = new $executor();
             $result = $executorObj->execute($cache);
         }
     }
     return $result;
 }
示例#2
0
 /**
  * fetch 
  * 
  * get the required data from RightScale by getting the query from
  * the query object
  *
  * @access public
  * @return void
  */
 public function fetch(RSQueryObj $queryObj)
 {
     if (!($queryUrl = $queryObj->getQueryUrl())) {
         throw new RSException(self::BAD_QUERY_URL);
     }
     $httpheader = array("X-API-VERSION:1.5", "Authorization: Bearer {$this->authtoken}");
     /* Initialize Curl and Issue Request */
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $queryUrl);
     curl_setopt($ch, CURLOPT_HEADER, $this->m_curl_opt["header"]);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
     curl_setopt($ch, CURLOPT_USERAGENT, $this->m_curl_opt["user_agent"]);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, $this->m_curl_opt["return_transfer"]);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->m_curl_opt["ssl_verify_peer"]);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->m_curl_opt["ssl_verify_host"]);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->m_curl_opt["timeout"]);
     /* Response or No Response ? */
     $response = curl_exec($ch);
     $errno = curl_errno($ch);
     $errstr = curl_error($ch);
     curl_close($ch);
     if ($errno) {
         throw new RSException(self::BAD_CURL_MSG . $errno . " " . $errstr);
     }
     $result = NULL;
     if ($executor = $queryObj->getExecutorName()) {
         $result = $this->getObserver($executor)->execute($response);
     } else {
         throw new RSException(self::BAD_EXECUTOR_MSG);
     }
     return $result;
 }