annotate vendor/zendframework/zend-stdlib/src/Guard/ArrayOrTraversableGuardTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 7a779792577d
children
rev   line source
Chris@0 1 <?php
Chris@0 2 /**
Chris@0 3 * Zend Framework (http://framework.zend.com/)
Chris@0 4 *
Chris@0 5 * @link http://github.com/zendframework/zf2 for the canonical source repository
Chris@0 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
Chris@0 7 * @license http://framework.zend.com/license/new-bsd New BSD License
Chris@0 8 */
Chris@0 9
Chris@0 10 namespace Zend\Stdlib\Guard;
Chris@0 11
Chris@0 12 use Traversable;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Provide a guard method for array or Traversable data
Chris@0 16 */
Chris@0 17 trait ArrayOrTraversableGuardTrait
Chris@0 18 {
Chris@0 19 /**
Chris@0 20 * Verifies that the data is an array or Traversable
Chris@0 21 *
Chris@0 22 * @param mixed $data the data to verify
Chris@0 23 * @param string $dataName the data name
Chris@0 24 * @param string $exceptionClass FQCN for the exception
Chris@0 25 * @throws \Exception
Chris@0 26 */
Chris@0 27 protected function guardForArrayOrTraversable(
Chris@0 28 $data,
Chris@0 29 $dataName = 'Argument',
Chris@0 30 $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException'
Chris@0 31 ) {
Chris@12 32 if (! is_array($data) && ! ($data instanceof Traversable)) {
Chris@0 33 $message = sprintf(
Chris@0 34 "%s must be an array or Traversable, [%s] given",
Chris@0 35 $dataName,
Chris@0 36 is_object($data) ? get_class($data) : gettype($data)
Chris@0 37 );
Chris@0 38 throw new $exceptionClass($message);
Chris@0 39 }
Chris@0 40 }
Chris@0 41 }