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

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
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 /**
Chris@0 13 * Provide a guard method against empty data
Chris@0 14 */
Chris@0 15 trait EmptyGuardTrait
Chris@0 16 {
Chris@0 17 /**
Chris@0 18 * Verify that the data is not empty
Chris@0 19 *
Chris@0 20 * @param mixed $data the data to verify
Chris@0 21 * @param string $dataName the data name
Chris@0 22 * @param string $exceptionClass FQCN for the exception
Chris@0 23 * @throws \Exception
Chris@0 24 */
Chris@0 25 protected function guardAgainstEmpty(
Chris@0 26 $data,
Chris@0 27 $dataName = 'Argument',
Chris@0 28 $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException'
Chris@0 29 ) {
Chris@0 30 if (empty($data)) {
Chris@0 31 $message = sprintf('%s cannot be empty', $dataName);
Chris@0 32 throw new $exceptionClass($message);
Chris@0 33 }
Chris@0 34 }
Chris@0 35 }