You are here

class Braintree_Error_ValidationErrorCollection in Commerce Braintree 7

collection of errors enumerating all validation errors for a given request

<b>== More information ==</b>

For more detailed information on Validation errors, see {@link http://www.braintreepayments.com/gateway/validation-errors http://www.braintreepaymentsolutions.com/gateway/validation-errors}

@package Braintree @subpackage Error @copyright 2010 Braintree Payment Solutions

@property-read array $errors @property-read array $nested

Hierarchy

Expanded class hierarchy of Braintree_Error_ValidationErrorCollection

File

braintree_php/lib/Braintree/Error/ValidationErrorCollection.php, line 24

View source
class Braintree_Error_ValidationErrorCollection extends Braintree_Collection {
  private $_errors = array();
  private $_nested = array();

  /**
   * @ignore
   */
  public function __construct($data) {
    foreach ($data as $key => $errorData) {

      // map errors to new collections recursively
      if ($key == 'errors') {
        foreach ($errorData as $error) {
          $this->_errors[] = new Braintree_Error_Validation($error);
        }
      }
      else {
        $this->_nested[$key] = new Braintree_Error_ValidationErrorCollection($errorData);
      }
    }
  }
  public function deepAll() {
    $validationErrors = array_merge(array(), $this->_errors);
    foreach ($this->_nested as $nestedErrors) {
      $validationErrors = array_merge($validationErrors, $nestedErrors
        ->deepAll());
    }
    return $validationErrors;
  }
  public function deepSize() {
    $total = sizeof($this->_errors);
    foreach ($this->_nested as $_nestedErrors) {
      $total = $total + $_nestedErrors
        ->deepSize();
    }
    return $total;
  }
  public function forIndex($index) {
    return $this
      ->forKey("index" . $index);
  }
  public function forKey($key) {
    return isset($this->_nested[$key]) ? $this->_nested[$key] : null;
  }
  public function onAttribute($attribute) {
    $matches = array();
    foreach ($this->_errors as $key => $error) {
      if ($error->attribute == $attribute) {
        $matches[] = $error;
      }
    }
    return $matches;
  }
  public function shallowAll() {
    return $this->_errors;
  }

  /**
   *
   * @ignore
   */
  public function __get($name) {
    $varName = "_{$name}";
    return isset($this->{$varName}) ? $this->{$varName} : null;
  }

  /**
   * @ignore
   */
  public function __toString() {
    $output = array();

    // TODO: implement scope
    if (!empty($this->_errors)) {
      $output[] = $this
        ->_inspect($this->_errors);
    }
    if (!empty($this->_nested)) {
      foreach ($this->_nested as $key => $values) {
        $output[] = $this
          ->_inspect($this->_nested);
      }
    }
    return join(', ', $output);
  }

  /**
   * @ignore
   */
  private function _inspect($errors, $scope = null) {
    $eOutput = '[' . __CLASS__ . '/errors:[';
    foreach ($errors as $error => $errorObj) {
      $outputErrs[] = "({$errorObj->error['code']} {$errorObj->error['message']})";
    }
    $eOutput .= join(', ', $outputErrs) . ']]';
    return $eOutput;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Braintree_Collection::$_collection protected property
Braintree_Collection::add public function Add a value into the collection
Braintree_Collection::count public function Return count of items in collection Implements countable
Braintree_Collection::exists public function Determine if index exists
Braintree_Collection::get public function Return value at index
Braintree_Collection::getIterator public function Return an iterator Implements IteratorAggregate
Braintree_Collection::offsetExists public function Determine if offset exists Implements ArrayAccess
Braintree_Collection::offsetGet public function get an offset's value Implements ArrayAccess
Braintree_Collection::offsetSet public function Set offset to value Implements ArrayAccess
Braintree_Collection::offsetUnset public function Unset offset Implements ArrayAccess
Braintree_Collection::remove public function Remove a value from the collection
Braintree_Collection::set public function Set index's value
Braintree_Error_ValidationErrorCollection::$_errors private property
Braintree_Error_ValidationErrorCollection::$_nested private property
Braintree_Error_ValidationErrorCollection::deepAll public function
Braintree_Error_ValidationErrorCollection::deepSize public function
Braintree_Error_ValidationErrorCollection::forIndex public function
Braintree_Error_ValidationErrorCollection::forKey public function
Braintree_Error_ValidationErrorCollection::onAttribute public function
Braintree_Error_ValidationErrorCollection::shallowAll public function
Braintree_Error_ValidationErrorCollection::_inspect private function @ignore
Braintree_Error_ValidationErrorCollection::__construct public function @ignore
Braintree_Error_ValidationErrorCollection::__get public function @ignore
Braintree_Error_ValidationErrorCollection::__toString public function @ignore