Skip to content

Commit

Permalink
Merge pull request #128 from helveticadomes/feature-fix-version-property
Browse files Browse the repository at this point in the history
version is mandatory at vCard 4.0
  • Loading branch information
jeroendesloovere authored Mar 2, 2019
2 parents 054f604 + 76f766c commit 6346d51
Showing 1 changed file with 19 additions and 3 deletions.
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

0 comments on commit 6346d51

Please sign in to comment.