コード例 #1
0
ファイル: Object.php プロジェクト: sunxguo/platform
 /**
  * Refreshes this object using the provided values.
  *
  * @param stdObject $values
  * @param string $apiKey
  * @param boolean $partial Defaults to false.
  */
 public function refreshFrom($values, $apiKey, $partial = false)
 {
     $this->_apiKey = $apiKey;
     // Wipe old state before setting new.  This is useful for e.g. updating a
     // customer, where there is no persistent card parameter.  Mark those values
     // which don't persist as transient
     if ($partial) {
         $removed = new Pingpp_Util_Set();
     } else {
         $removed = array_diff(array_keys($this->_values), array_keys(get_object_vars($values)));
     }
     foreach ($removed as $k) {
         if (self::$permanentAttributes->includes($k)) {
             continue;
         }
         unset($this->{$k});
     }
     foreach ($values as $k => $v) {
         if (self::$permanentAttributes->includes($k)) {
             continue;
         }
         if (self::$nestedUpdatableAttributes->includes($k) && is_object($v)) {
             $this->_values[$k] = Pingpp_Object::scopedConstructFrom('Pingpp_AttachedObject', $v, $apiKey);
         } else {
             $this->_values[$k] = Pingpp_Util::convertToPingppObject($v, $apiKey);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }
コード例 #2
0
ファイル: Util.php プロジェクト: sunxguo/platform
 /**
  * Converts a response from the Pingpp API to the corresponding PHP object.
  *
  * @param stdObject $resp The response from the Pingpp API.
  * @param string $apiKey
  * @return Pingpp_Object|array
  */
 public static function convertToPingppObject($resp, $apiKey)
 {
     $types = array('charge' => 'Pingpp_Charge', 'list' => 'Pingpp_List', 'refund' => 'Pingpp_Refund');
     if (self::isList($resp)) {
         $mapped = array();
         foreach ($resp as $i) {
             array_push($mapped, self::convertToPingppObject($i, $apiKey));
         }
         return $mapped;
     } else {
         if (is_object($resp)) {
             if (isset($resp->object) && is_string($resp->object) && isset($types[$resp->object])) {
                 $class = $types[$resp->object];
             } else {
                 $class = 'Pingpp_Object';
             }
             return Pingpp_Object::scopedConstructFrom($class, $resp, $apiKey);
         } else {
             return $resp;
         }
     }
 }