Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-stdlib/src/Guard/NullGuardTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Zend Framework (http://framework.zend.com/) | |
4 * | |
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 | |
8 */ | |
9 | |
10 namespace Zend\Stdlib\Guard; | |
11 | |
12 /** | |
13 * Provide a guard method against null data | |
14 */ | |
15 trait NullGuardTrait | |
16 { | |
17 /** | |
18 * Verify that the data is not null | |
19 * | |
20 * @param mixed $data the data to verify | |
21 * @param string $dataName the data name | |
22 * @param string $exceptionClass FQCN for the exception | |
23 * @throws \Exception | |
24 */ | |
25 protected function guardAgainstNull( | |
26 $data, | |
27 $dataName = 'Argument', | |
28 $exceptionClass = 'Zend\Stdlib\Exception\InvalidArgumentException' | |
29 ) { | |
30 if (null === $data) { | |
31 $message = sprintf('%s cannot be null', $dataName); | |
32 throw new $exceptionClass($message); | |
33 } | |
34 } | |
35 } |