Skip to content

Commit d9fa880

Browse files
authored
Allow full population via constructor (#11)
1 parent b4856f5 commit d9fa880

File tree

3 files changed

+162
-190
lines changed

3 files changed

+162
-190
lines changed

src/InternetMediaType.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ class InternetMediaType implements InternetMediaTypeInterface
3333
*/
3434
private $parameters = [];
3535

36+
public function __construct(?string $type = null, ?string $subtype = null, array $parameters = [])
37+
{
38+
if (!empty($type)) {
39+
$this->setType($type);
40+
}
41+
42+
if (!empty($subtype)) {
43+
$this->setSubtype($subtype);
44+
}
45+
46+
foreach ($parameters as $parameter) {
47+
if ($parameter instanceof ParameterInterface) {
48+
$this->addParameter($parameter);
49+
}
50+
}
51+
}
52+
3653
public function setType(string $type)
3754
{
3855
$this->type = strtolower($type);

tests/BaseTest.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)