1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* ReportingCloud PHP Wrapper |
6
|
|
|
* |
7
|
|
|
* PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH. |
8
|
|
|
* |
9
|
|
|
* @link https://www.reporting.cloud to learn more about ReportingCloud |
10
|
|
|
* @link https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository |
11
|
|
|
* @license https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md |
12
|
|
|
* @copyright © 2019 Text Control GmbH |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TxTextControl\ReportingCloud\Assert; |
16
|
|
|
|
17
|
|
|
use ReflectionClass; |
18
|
|
|
use ReflectionException; |
19
|
|
|
use TxTextControl\ReportingCloud\ReportingCloud; |
20
|
|
|
use TxTextControl\ReportingCloud\Stdlib\StringUtils; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Trait DocumentDividerTrait |
24
|
|
|
* |
25
|
|
|
* @package TxTextControl\ReportingCloud |
26
|
|
|
* @author Jonathan Maron (@JonathanMaron) |
27
|
|
|
*/ |
28
|
|
|
trait AssertDocumentDividerTrait |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Validate a document divider |
32
|
|
|
* |
33
|
|
|
* @param int $value |
34
|
|
|
* @param string $message |
35
|
|
|
* |
36
|
|
|
* @return null |
37
|
|
|
* @throws \TxTextControl\ReportingCloud\Exception\InvalidArgumentException |
38
|
|
|
*/ |
39
|
12 |
|
public static function assertDocumentDivider(int $value, string $message = '') |
40
|
|
|
{ |
41
|
12 |
|
$haystack = self::getDocumentDividers(); |
42
|
12 |
|
$format = $message ?: '%s contains an unsupported document divider'; |
43
|
12 |
|
$message = sprintf($format, self::valueToString($value)); |
44
|
|
|
|
45
|
12 |
|
return self::oneOf($value, $haystack, $message); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Return document dividers array |
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
12 |
|
private static function getDocumentDividers(): array |
54
|
|
|
{ |
55
|
12 |
|
$constants = []; |
56
|
|
|
|
57
|
|
|
try { |
58
|
12 |
|
$reportingCloud = new ReportingCloud(); |
59
|
12 |
|
$reflectionClass = new ReflectionClass($reportingCloud); |
60
|
12 |
|
$constants = $reflectionClass->getConstants(); |
61
|
12 |
|
unset($reportingCloud); |
62
|
|
|
} catch (ReflectionException $e) { |
63
|
|
|
// continue |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$ret = array_filter($constants, function ($constantKey) { |
67
|
12 |
|
if (StringUtils::startsWith($constantKey, 'DOCUMENT_DIVIDER_')) { |
68
|
12 |
|
return true; |
69
|
|
|
} |
70
|
12 |
|
}, ARRAY_FILTER_USE_KEY); |
71
|
|
|
|
72
|
12 |
|
$ret = array_values($ret); |
73
|
|
|
|
74
|
12 |
|
return $ret; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|