PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / web-auth / metadata-service / src / DisplayPNGCharacteristicsDescriptor.php

DisplayPNGCharacteristicsDescriptor.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at vendor/web-auth/metadata-service/src/DisplayPNGCharacteristicsDescriptor.php

173 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * The MIT License (MIT)
7 *
8 * Copyright (c) 2014-2021 Spomky-Labs
9 *
10 * This software may be modified and distributed under the terms
11 * of the MIT license. See the LICENSE file for details.
12 */
13
14 namespace Webauthn\MetadataService;
15
16 use Assert\Assertion;
17 use JsonSerializable;
18 use function Safe\sprintf;
19
20 class DisplayPNGCharacteristicsDescriptor implements JsonSerializable
21 {
22 /**
23 * @var int
24 */
25 private $width;
26
27 /**
28 * @var int
29 */
30 private $height;
31
32 /**
33 * @var int
34 */
35 private $bitDepth;
36
37 /**
38 * @var int
39 */
40 private $colorType;
41
42 /**
43 * @var int
44 */
45 private $compression;
46
47 /**
48 * @var int
49 */
50 private $filter;
51
52 /**
53 * @var int
54 */
55 private $interlace;
56
57 /**
58 * @var RgbPaletteEntry[]
59 */
60 private $plte = [];
61
62 public function __construct(int $width, int $height, int $bitDepth, int $colorType, int $compression, int $filter, int $interlace)
63 {
64 Assertion::greaterOrEqualThan($width, 0, Utils::logicException('Invalid width'));
65 Assertion::greaterOrEqualThan($height, 0, Utils::logicException('Invalid height'));
66 Assertion::range($bitDepth, 0, 254, Utils::logicException('Invalid bit depth'));
67 Assertion::range($colorType, 0, 254, Utils::logicException('Invalid color type'));
68 Assertion::range($compression, 0, 254, Utils::logicException('Invalid compression'));
69 Assertion::range($filter, 0, 254, Utils::logicException('Invalid filter'));
70 Assertion::range($interlace, 0, 254, Utils::logicException('Invalid interlace'));
71
72 $this->width = $width;
73 $this->height = $height;
74 $this->bitDepth = $bitDepth;
75 $this->colorType = $colorType;
76 $this->compression = $compression;
77 $this->filter = $filter;
78 $this->interlace = $interlace;
79 }
80
81 public function addPalette(RgbPaletteEntry $rgbPaletteEntry): self
82 {
83 $this->plte[] = $rgbPaletteEntry;
84
85 return $this;
86 }
87
88 public function getWidth(): int
89 {
90 return $this->width;
91 }
92
93 public function getHeight(): int
94 {
95 return $this->height;
96 }
97
98 public function getBitDepth(): int
99 {
100 return $this->bitDepth;
101 }
102
103 public function getColorType(): int
104 {
105 return $this->colorType;
106 }
107
108 public function getCompression(): int
109 {
110 return $this->compression;
111 }
112
113 public function getFilter(): int
114 {
115 return $this->filter;
116 }
117
118 public function getInterlace(): int
119 {
120 return $this->interlace;
121 }
122
123 /**
124 * @return RgbPaletteEntry[]
125 */
126 public function getPlte(): array
127 {
128 return $this->plte;
129 }
130
131 public static function createFromArray(array $data): self
132 {
133 $data = Utils::filterNullValues($data);
134 foreach (['width', 'compression', 'height', 'bitDepth', 'colorType', 'compression', 'filter', 'interlace'] as $key) {
135 Assertion::keyExists($data, $key, sprintf('Invalid data. The key "%s" is missing', $key));
136 }
137 $object = new self(
138 $data['width'],
139 $data['height'],
140 $data['bitDepth'],
141 $data['colorType'],
142 $data['compression'],
143 $data['filter'],
144 $data['interlace']
145 );
146 if (isset($data['plte'])) {
147 $plte = $data['plte'];
148 Assertion::isArray($plte, Utils::logicException('Invalid "plte" parameter'));
149 foreach ($plte as $item) {
150 $object->addPalette(RgbPaletteEntry::createFromArray($item));
151 }
152 }
153
154 return $object;
155 }
156
157 public function jsonSerialize(): array
158 {
159 $data = [
160 'width' => $this->width,
161 'height' => $this->height,
162 'bitDepth' => $this->bitDepth,
163 'colorType' => $this->colorType,
164 'compression' => $this->compression,
165 'filter' => $this->filter,
166 'interlace' => $this->interlace,
167 'plte' => $this->plte,
168 ];
169
170 return Utils::filterNullValues($data);
171 }
172 }
173