You are here

public static function Braintree_Util::extractAttributeAsArray in Commerce Braintree 7

extracts an attribute and returns an array of objects

extracts the requested element from an array, and converts the contents of its child arrays to objects of type Braintree_$attributeName, or returns an array with a single element containing the value of that array element

Parameters

array $attribArray attributes from a search response:

string $attributeName indicates which element of the passed array to extract:

Return value

array array of Braintree_$attributeName objects, or a single element array

6 calls to Braintree_Util::extractAttributeAsArray()
Braintree_AddOn::all in braintree_php/lib/Braintree/AddOn.php
Braintree_CreditCard::fetchExpiring in braintree_php/lib/Braintree/CreditCard.php
Braintree_Discount::all in braintree_php/lib/Braintree/Discount.php
Braintree_Plan::all in braintree_php/lib/Braintree/Plan.php
Braintree_Subscription::fetch in braintree_php/lib/Braintree/Subscription.php

... See full list

File

braintree_php/lib/Braintree/Util.php, line 29

Class

Braintree_Util
Braintree Utility methods

Code

public static function extractAttributeAsArray(&$attribArray, $attributeName) {
  if (!isset($attribArray[$attributeName])) {
    return array();
  }

  // get what should be an array from the passed array
  $data = $attribArray[$attributeName];

  // set up the class that will be used to convert each array element
  $classFactory = self::buildClassName($attributeName) . '::factory';
  if (is_array($data)) {

    // create an object from the data in each element
    $objectArray = array_map($classFactory, $data);
  }
  else {
    return array(
      $data,
    );
  }
  unset($attribArray[$attributeName]);
  return $objectArray;
}