4 * @see https://github.com/laminas/laminas-stdlib for the canonical source repository
5 * @copyright https://github.com/laminas/laminas-stdlib/blob/master/COPYRIGHT.md
6 * @license https://github.com/laminas/laminas-stdlib/blob/master/LICENSE.md New BSD License
9 namespace Laminas\Stdlib\Guard;
14 * Provide a guard method for array or Traversable data
16 trait ArrayOrTraversableGuardTrait
19 * Verifies that the data is an array or Traversable
21 * @param mixed $data the data to verify
22 * @param string $dataName the data name
23 * @param string $exceptionClass FQCN for the exception
26 protected function guardForArrayOrTraversable(
28 $dataName = 'Argument',
29 $exceptionClass = 'Laminas\Stdlib\Exception\InvalidArgumentException'
31 if (! is_array($data) && ! ($data instanceof Traversable)) {
33 "%s must be an array or Traversable, [%s] given",
35 is_object($data) ? get_class($data) : gettype($data)
37 throw new $exceptionClass($message);