PluginProbe
Media Cloud Sync / 1.2.7
Media Cloud Sync v1.2.7
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / google / gax / src / ValidationTrait.php

ValidationTrait.php in Media Cloud Sync 1.2.7, at includes/sdk/google/google/gax/src/ValidationTrait.php

79 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Copyright 2017 Google LLC
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 namespace Dudlewebs\WPMCS\Google\ApiCore;
34
35 /**
36 * @internal
37 */
38 trait ValidationTrait
39 {
40 /**
41 * @param array $arr Associative array
42 * @param array $requiredKeys List of keys to check for in $arr
43 * @return array Returns $arr for fluent use
44 */
45 public static function validate(array $arr, array $requiredKeys)
46 {
47 return self::validateImpl($arr, $requiredKeys, \true);
48 }
49 /**
50 * @param array $arr Associative array
51 * @param array $requiredKeys List of keys to check for in $arr
52 * @return array Returns $arr for fluent use
53 */
54 public static function validateNotNull(array $arr, array $requiredKeys)
55 {
56 return self::validateImpl($arr, $requiredKeys, \false);
57 }
58 private static function validateImpl($arr, $requiredKeys, $allowNull)
59 {
60 foreach ($requiredKeys as $requiredKey) {
61 $valid = array_key_exists($requiredKey, $arr) && ($allowNull || !is_null($arr[$requiredKey]));
62 if (!$valid) {
63 throw new ValidationException("Missing required argument {$requiredKey}");
64 }
65 }
66 return $arr;
67 }
68 /**
69 * @param string $filePath
70 * @throws ValidationException
71 */
72 private static function validateFileExists(string $filePath)
73 {
74 if (!file_exists($filePath)) {
75 throw new ValidationException("Could not find specified file: {$filePath}");
76 }
77 }
78 }
79