Pingpp\Util\Util::convertToPingppObject PHP Метод

convertToPingppObject() публичный статический Метод

Converts a response from the Pingpp API to the corresponding PHP object.
public static convertToPingppObject ( stdObject $resp, array $opts ) : PingppObject | array
$resp stdObject The response from the Pingpp API.
$opts array
Результат Pingpp\PingppObject | array
    public static function convertToPingppObject($resp, $opts)
    {
        $types = array('red_envelope' => 'Pingpp\\RedEnvelope', 'charge' => 'Pingpp\\Charge', 'list' => 'Pingpp\\Collection', 'refund' => 'Pingpp\\Refund', 'event' => 'Pingpp\\Event', 'transfer' => 'Pingpp\\Transfer', 'customer' => 'Pingpp\\Customer', 'card' => 'Pingpp\\Card', 'sms_code' => 'Pingpp\\SmsCode', 'card_info' => 'Pingpp\\CardInfo', 'token' => 'Pingpp\\Token');
        if (self::isList($resp)) {
            $mapped = array();
            foreach ($resp as $i) {
                array_push($mapped, self::convertToPingppObject($i, $opts));
            }
            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\\PingppObject';
                }
                return $class::constructFrom($resp, $opts);
            } else {
                return $resp;
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * Refreshes this object using the provided values.
  *
  * @param stdObject $values
  * @param array $opts
  * @param boolean $partial Defaults to false.
  */
 public function refreshFrom($values, $opts, $partial = false)
 {
     $this->_opts = $opts;
     // 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 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] = AttachedObject::constructFrom($v, $opts);
         } else {
             $this->_values[$k] = Util\Util::convertToPingppObject($v, $opts);
         }
         $this->_transientValues->discard($k);
         $this->_unsavedValues->discard($k);
     }
 }