You are here

trait ArrayOrTraversableGuardTrait in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php \Zend\Stdlib\Guard\ArrayOrTraversableGuardTrait

Provide a guard method for array or Traversable data

Hierarchy

File

vendor/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php, line 17

Namespace

Zend\Stdlib\Guard
View source
trait ArrayOrTraversableGuardTrait {

  /**
   * Verifies that the data is an array or Traversable
   *
   * @param  mixed  $data           the data to verify
   * @param  string $dataName       the data name
   * @param  string $exceptionClass FQCN for the exception
   * @throws \Exception
   */
  protected function guardForArrayOrTraversable($data, $dataName = 'Argument', $exceptionClass = 'Zend\\Stdlib\\Exception\\InvalidArgumentException') {
    if (!is_array($data) && !$data instanceof Traversable) {
      $message = sprintf("%s must be an array or Traversable, [%s] given", $dataName, is_object($data) ? get_class($data) : gettype($data));
      throw new $exceptionClass($message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ArrayOrTraversableGuardTrait::guardForArrayOrTraversable protected function Verifies that the data is an array or Traversable