Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version is mandatory at vCard 4.0 #128

Merged
22 changes: 19 additions & 3 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
use JeroenDesloovere\VCard\Property\Parameter\Version;
use JeroenDesloovere\VCard\Property\Photo;
use JeroenDesloovere\VCard\Property\PropertyInterface;
use JeroenDesloovere\VCard\Property\Role;
use JeroenDesloovere\VCard\Property\Telephone;
use JeroenDesloovere\VCard\Property\Title;
use JeroenDesloovere\VCard\Property\Role;

final class VCard
{
Expand Down Expand Up @@ -66,10 +66,12 @@ final class VCard

/**
* @param Kind|null $kind
* @param Version|null $version
* @throws VCardException
*/
public function __construct(Kind $kind = null)
public function __construct(Kind $kind = null, Version $version = null)
{
$this->add($version ?? Version::version4());
$this->add($kind ?? Kind::individual());
}

Expand Down Expand Up @@ -130,12 +132,26 @@ private function addPropertyParameter(PropertyParameterInterface $propertyParame

public function getKind(): Kind
{
return $this->getParameters(Kind::class)[0];
$kind = $this->getParameters(Kind::class);

return reset($kind);
}

public function getParameters(string $filterByPropertyParameterClass = null): array
{
if ($filterByPropertyParameterClass === null) {
$array = $this->parameters;
$found = $others = [];
foreach ($array as $value) {
if ($value instanceof Version) {
$found[] = $value;
} else {
$others[] = $value;
}
}
$array = array_merge($found, $others);
$this->parameters = $array;

return $this->parameters;
}

Expand Down