contacts as $element) { if ($element->type === $type) { return $element; } } return new NullContact(); } /** * Create object from array * * @param array{id:int, name:array{0:string, 1:string, 2:string}, email:string, login:string, type:int, status:int, groups:array, permissions:array, tries:?int, addresses?:array, contacts?:array, parents?:array, l11n:array} $account Account data * * @return self * * @since 1.0.0 */ public static function fromJson(array $account) : self { $new = new self(); $new->from($account); $new->tries = $account['tries'] ?? 0; foreach (($account['addresses'] ?? []) as $address) { $new->addresses[] = \phpOMS\Stdlib\Base\Address::fromJson($address); } foreach (($account['contacts'] ?? []) as $contact) { $new->contacts[] = Contact::fromJson($contact); } foreach (($account['parents'] ?? []) as $parent) { $new->parents[] = self::fromJson($parent); } return $new; } /** * {@inheritdoc} */ public function toArray() : array { return \array_merge( parent::toArray(), [ 'tries' => $this->tries, 'addresses' => $this->addresses, 'contacts' => $this->contacts, 'parents' => $this->parents, ] ); } /** * {@inheritdoc} */ public function jsonSerialize() : mixed { return $this->toArray(); } }