Initial commit
This commit is contained in:
77
lib/Providers/Mail/CollectionResource.php
Normal file
77
lib/Providers/Mail/CollectionResource.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers\Mail;
|
||||
|
||||
use KTXF\Mail\Collection\CollectionMutableAbstract;
|
||||
|
||||
/**
|
||||
* Mail Collection Resource Implementation
|
||||
*/
|
||||
class CollectionResource extends CollectionMutableAbstract {
|
||||
|
||||
public function __construct(
|
||||
string $provider = 'jmapc',
|
||||
string|int|null $service = null,
|
||||
) {
|
||||
parent::__construct($provider, $service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts JMAP parameters array to mail collection object
|
||||
*
|
||||
* @param array $parameters JMAP parameters array
|
||||
*/
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
if (isset($parameters['parentId'])) {
|
||||
$this->data['collection'] = $parameters['parentId'];
|
||||
}
|
||||
if (isset($parameters['id'])) {
|
||||
$this->data['identifier'] = $parameters['id'];
|
||||
}
|
||||
if (isset($parameters['signature'])) {
|
||||
$this->data['signature'] = $parameters['signature'];
|
||||
}
|
||||
|
||||
$this->getProperties()->fromJmap($parameters);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mail collection object to JMAP parameters array
|
||||
*/
|
||||
public function toJmap(): array {
|
||||
|
||||
$parameters = [];
|
||||
|
||||
if (isset($this->data['collection'])) {
|
||||
$parameters['parentId'] = $this->data['collection'];
|
||||
}
|
||||
if (isset($this->data['identifier'])) {
|
||||
$parameters['id'] = $this->data['identifier'];
|
||||
}
|
||||
|
||||
$parameters = array_merge($parameters, $this->getProperties()->toJmap());
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): CollectionProperties {
|
||||
if (!isset($this->properties)) {
|
||||
$this->properties = new CollectionProperties([]);
|
||||
}
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user