|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* ReportingCloud PHP SDK |
|
6
|
|
|
* |
|
7
|
|
|
* PHP SDK 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 TxTextControl\ReportingCloud\Exception\InvalidArgumentException; |
|
18
|
|
|
use TxTextControl\ReportingCloud\ReportingCloud; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Trait AssertDocumentThumbnailExtensionTrait |
|
22
|
|
|
* |
|
23
|
|
|
* @package TxTextControl\ReportingCloud |
|
24
|
|
|
* @author Jonathan Maron (@JonathanMaron) |
|
25
|
|
|
*/ |
|
26
|
|
|
trait AssertDocumentThumbnailExtensionTrait |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @param mixed $value |
|
30
|
|
|
* @param array $values |
|
31
|
|
|
* @param string $message |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract public static function oneOf($value, array $values, $message = ''); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Check value is a valid document thumbnail format extension |
|
37
|
|
|
* |
|
38
|
|
|
* This is a special case assert method that is used only by |
|
39
|
|
|
* TxTextControl\ReportingCloud\ReportingCloud::getDocumentThumbnails() |
|
40
|
|
|
* as this method additionally accepts files in XLSX format. No other methods do. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $value |
|
43
|
|
|
* @param string $message |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
* @throws InvalidArgumentException |
|
47
|
|
|
*/ |
|
48
|
12 |
|
public static function assertDocumentThumbnailExtension(string $value, string $message = ''): void |
|
49
|
|
|
{ |
|
50
|
12 |
|
$extension = pathinfo($value, PATHINFO_EXTENSION); |
|
51
|
12 |
|
$extension = strtoupper($extension); |
|
52
|
|
|
|
|
53
|
12 |
|
$format = $message ?: '"%s" contains an unsupported document thumbnail format file extension'; |
|
54
|
12 |
|
$message = sprintf($format, $value); |
|
55
|
|
|
|
|
56
|
12 |
|
$fileFormats = array_merge( |
|
57
|
12 |
|
ReportingCloud::FILE_FORMATS_DOCUMENT, |
|
58
|
|
|
[ |
|
59
|
12 |
|
ReportingCloud::FILE_FORMAT_XLSX |
|
60
|
|
|
] |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
12 |
|
self::oneOf($extension, $fileFormats, $message); |
|
64
|
6 |
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|