Braintree\Util::extractAttributeAsArray PHP Method

extractAttributeAsArray() public static method

extracts the requested element from an array, and converts the contents of its child arrays to objects of type $attributeName, or returns an array with a single element containing the value of that array element
public static extractAttributeAsArray ( array &$attribArray, string $attributeName ) : array
$attribArray array attributes from a search response
$attributeName string indicates which element of the passed array to extract
return array array of $attributeName objects, or a single element array
    public static function extractAttributeAsArray(&$attribArray, $attributeName)
    {
        if (!isset($attribArray[$attributeName])) {
            return [];
        }
        // 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 [$data];
        }
        unset($attribArray[$attributeName]);
        return $objectArray;
    }

Usage Example

 public function fetch($query, $ids)
 {
     $criteria = [];
     foreach ($query as $term) {
         $criteria[$term->name] = $term->toparam();
     }
     $criteria["ids"] = SubscriptionSearch::ids()->in($ids)->toparam();
     $path = $this->_config->merchantPath() . '/subscriptions/advanced_search';
     $response = $this->_http->post($path, ['search' => $criteria]);
     return Util::extractAttributeAsArray($response['subscriptions'], 'subscription');
 }
All Usage Examples Of Braintree\Util::extractAttributeAsArray