Path: blob/master/externals/stripe-php/lib/Stripe/Util.php
12256 views
<?php12abstract class Stripe_Util3{4/**5* Whether the provided array (or other) is a list rather than a dictionary.6*7* @param array|mixed $array8* @return boolean True if the given object is a list.9*/10public static function isList($array)11{12if (!is_array($array))13return false;1415// TODO: generally incorrect, but it's correct given Stripe's response16foreach (array_keys($array) as $k) {17if (!is_numeric($k))18return false;19}20return true;21}2223/**24* Recursively converts the PHP Stripe object to an array.25*26* @param array $values The PHP Stripe object to convert.27* @return array28*/29public static function convertStripeObjectToArray($values)30{31$results = array();32foreach ($values as $k => $v) {33// FIXME: this is an encapsulation violation34if ($k[0] == '_') {35continue;36}37if ($v instanceof Stripe_Object) {38$results[$k] = $v->__toArray(true);39} else if (is_array($v)) {40$results[$k] = self::convertStripeObjectToArray($v);41} else {42$results[$k] = $v;43}44}45return $results;46}4748/**49* Converts a response from the Stripe API to the corresponding PHP object.50*51* @param array $resp The response from the Stripe API.52* @param string $apiKey53* @return Stripe_Object|array54*/55public static function convertToStripeObject($resp, $apiKey)56{57$types = array(58'card' => 'Stripe_Card',59'charge' => 'Stripe_Charge',60'customer' => 'Stripe_Customer',61'list' => 'Stripe_List',62'invoice' => 'Stripe_Invoice',63'invoiceitem' => 'Stripe_InvoiceItem',64'event' => 'Stripe_Event',65'transfer' => 'Stripe_Transfer',66'plan' => 'Stripe_Plan',67'recipient' => 'Stripe_Recipient',68'refund' => 'Stripe_Refund',69'subscription' => 'Stripe_Subscription'70);71if (self::isList($resp)) {72$mapped = array();73foreach ($resp as $i)74array_push($mapped, self::convertToStripeObject($i, $apiKey));75return $mapped;76} else if (is_array($resp)) {77if (isset($resp['object'])78&& is_string($resp['object'])79&& isset($types[$resp['object']])) {80$class = $types[$resp['object']];81} else {82$class = 'Stripe_Object';83}84return Stripe_Object::scopedConstructFrom($class, $resp, $apiKey);85} else {86return $resp;87}88}89}909192