3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Stdlib\Guard;
15 * Provide a guard method for array or Traversable data
17 trait ArrayOrTraversableGuardTrait
20 * Verifies that the data is an array or Traversable
22 * @param mixed $data the data to verify
23 * @param string $dataName the data name
24 * @param string $exceptionClass FQCN for the exception
27 protected function guardForArrayOrTraversable(
29 $dataName = 'Argument',
30 $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException'
32 if (! is_array($data) && ! ($data instanceof Traversable)) {
34 "%s must be an array or Traversable, [%s] given",
36 is_object($data) ? get_class($data) : gettype($data)
38 throw new $exceptionClass($message);