|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the browscap package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 1998-2017, Browser Capabilities Project |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types = 1); |
|
12
|
|
|
namespace Browscap\Data\Validator; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class DivisionData |
|
16
|
|
|
* |
|
17
|
|
|
* @category Browscap |
|
18
|
|
|
* |
|
19
|
|
|
* @author Thomas Müller <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class DivisionData |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param array $divisionData |
|
25
|
|
|
* @param string $fileName |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \LogicException |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
12 |
|
public static function validate(array $divisionData, string $fileName) : void |
|
32
|
|
|
{ |
|
33
|
12 |
|
if (!array_key_exists('division', $divisionData)) { |
|
34
|
1 |
|
throw new \LogicException('required attibute "division" is missing in File ' . $fileName); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
11 |
|
if (!is_string($divisionData['division'])) { |
|
38
|
1 |
|
throw new \LogicException('required attibute "division" has to be a string in File ' . $fileName); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
10 |
|
if (!array_key_exists('sortIndex', $divisionData)) { |
|
42
|
1 |
|
throw new \LogicException('required attibute "sortIndex" is missing in File ' . $fileName); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
9 |
|
if (!is_int($divisionData['sortIndex']) || 0 > $divisionData['sortIndex']) { |
|
46
|
2 |
|
throw new \LogicException('required attibute "sortIndex" has to be a positive integer in File ' . $fileName); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
7 |
|
if (!array_key_exists('lite', $divisionData)) { |
|
50
|
1 |
|
throw new \LogicException('required attibute "lite" is missing in File ' . $fileName); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
if (!is_bool($divisionData['lite'])) { |
|
54
|
1 |
|
throw new \LogicException('required attibute "lite" has to be an boolean in File ' . $fileName); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
5 |
|
if (!array_key_exists('standard', $divisionData)) { |
|
58
|
1 |
|
throw new \LogicException('required attibute "standard" is missing in File ' . $fileName); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
4 |
|
if (!is_bool($divisionData['standard'])) { |
|
62
|
1 |
|
throw new \LogicException('required attibute "standard" has to be an boolean in File ' . $fileName); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
3 |
|
if (!isset($divisionData['userAgents'])) { |
|
66
|
1 |
|
throw new \LogicException('required attibute "userAgents" is missing in File ' . $fileName); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
if (!is_array($divisionData['userAgents']) || empty($divisionData['userAgents'])) { |
|
70
|
1 |
|
throw new \LogicException('required attibute "userAgents" should be an non-empty array in File ' . $fileName); |
|
71
|
|
|
} |
|
72
|
1 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|