Initial Version
This commit is contained in:
31
shared/lib/Mail/Collection/CollectionBaseAbstract.php
Normal file
31
shared/lib/Mail/Collection/CollectionBaseAbstract.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseAbstract;
|
||||
|
||||
/**
|
||||
* Abstract Mail Collection Base Class
|
||||
*
|
||||
* Provides common implementation for mail collections
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class CollectionBase extends NodeBaseAbstract implements CollectionBaseInterface {
|
||||
|
||||
protected CollectionPropertiesBaseAbstract $properties;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): CollectionPropertiesBaseInterface {
|
||||
return $this->properties;
|
||||
}
|
||||
}
|
||||
30
shared/lib/Mail/Collection/CollectionBaseInterface.php
Normal file
30
shared/lib/Mail/Collection/CollectionBaseInterface.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeBaseInterface;
|
||||
|
||||
/**
|
||||
* Mail Collection Base Interface
|
||||
*
|
||||
* Interface represents a mailbox/folder in a mail service
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
interface CollectionBaseInterface extends NodeBaseInterface {
|
||||
|
||||
/**
|
||||
* Gets the collection properties
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getProperties(): CollectionPropertiesBaseInterface|CollectionPropertiesMutableInterface;
|
||||
|
||||
}
|
||||
49
shared/lib/Mail/Collection/CollectionMutableAbstract.php
Normal file
49
shared/lib/Mail/Collection/CollectionMutableAbstract.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeMutableAbstract;
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
/**
|
||||
* Abstract Mail Collection Mutable Class
|
||||
*
|
||||
* Provides common implementation for mutable mail collections
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class CollectionMutableAbstract extends NodeMutableAbstract implements CollectionMutableInterface {
|
||||
|
||||
protected CollectionPropertiesMutableAbstract $properties;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProperties(): CollectionPropertiesMutableInterface {
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setProperties(NodePropertiesMutableInterface $value): static {
|
||||
if (!$value instanceof CollectionPropertiesMutableInterface) {
|
||||
throw new \InvalidArgumentException('Properties must implement CollectionPropertiesMutableInterface');
|
||||
}
|
||||
|
||||
// Copy all property values
|
||||
$this->properties->setLabel($value->getLabel());
|
||||
$this->properties->setRole($value->getRole());
|
||||
$this->properties->setRank($value->getRank());
|
||||
$this->properties->setSubscription($value->getSubscription());
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
32
shared/lib/Mail/Collection/CollectionMutableInterface.php
Normal file
32
shared/lib/Mail/Collection/CollectionMutableInterface.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodeMutableInterface;
|
||||
|
||||
/**
|
||||
* Mail Collection Mutable Interface
|
||||
*
|
||||
* Interface for altering mailbox/folder properties in a mail service
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @method static setProperties(CollectionPropertiesMutableInterface $value)
|
||||
*/
|
||||
interface CollectionMutableInterface extends CollectionBaseInterface, NodeMutableInterface {
|
||||
|
||||
/**
|
||||
* Gets the collection properties (mutable)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
public function getProperties(): CollectionPropertiesMutableInterface;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseAbstract;
|
||||
|
||||
/**
|
||||
* Abstract Mail Collection Properties Base Class
|
||||
*
|
||||
* Provides common implementation for mail collection properties
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class CollectionPropertiesBaseAbstract extends NodePropertiesBaseAbstract implements CollectionPropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function total(): int {
|
||||
return $this->data['total'] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function unread(): int {
|
||||
return $this->data['unread'] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabel(): string {
|
||||
return $this->data['label'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRole(): CollectionRoles {
|
||||
return isset($this->data['role'])
|
||||
? ($this->data['role'] instanceof CollectionRoles ? $this->data['role'] : CollectionRoles::from($this->data['role']))
|
||||
: CollectionRoles::Custom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRank(): int {
|
||||
return $this->data['rank'] ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSubscription(): bool {
|
||||
return $this->data['subscribed'] ?? false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesBaseInterface;
|
||||
|
||||
interface CollectionPropertiesBaseInterface extends NodePropertiesBaseInterface {
|
||||
|
||||
public const JSON_TYPE = 'mail.collection';
|
||||
public const JSON_PROPERTY_TOTAL = 'total';
|
||||
public const JSON_PROPERTY_UNREAD = 'unread';
|
||||
public const JSON_PROPERTY_LABEL = 'label';
|
||||
public const JSON_PROPERTY_ROLE = 'role';
|
||||
public const JSON_PROPERTY_RANK = 'rank';
|
||||
public const JSON_PROPERTY_SUBSCRIPTION = 'subscription';
|
||||
|
||||
public function total(): int;
|
||||
|
||||
public function unread(): int;
|
||||
|
||||
public function getLabel(): string;
|
||||
|
||||
public function getRole(): CollectionRoles;
|
||||
|
||||
public function getRank(): int;
|
||||
|
||||
public function getSubscription(): bool;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableAbstract;
|
||||
|
||||
/**
|
||||
* Abstract Mail Collection Properties Mutable Class
|
||||
*/
|
||||
abstract class CollectionPropertiesMutableAbstract extends CollectionPropertiesBaseAbstract implements CollectionPropertiesMutableInterface {
|
||||
|
||||
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonDeserialize(array|string $data): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setLabel(string $value): static {
|
||||
$this->data['label'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setRole(CollectionRoles $value): static {
|
||||
$this->data['role'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setRank(int $value): static {
|
||||
$this->data['rank'] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSubscription(bool $value): static {
|
||||
$this->data['subscription'] = $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use KTXF\Resource\Provider\Node\NodePropertiesMutableInterface;
|
||||
|
||||
interface CollectionPropertiesMutableInterface extends CollectionPropertiesBaseInterface, NodePropertiesMutableInterface {
|
||||
|
||||
public const JSON_TYPE = CollectionPropertiesBaseInterface::JSON_TYPE;
|
||||
|
||||
public function setLabel(string $value);
|
||||
|
||||
public function setRole(CollectionRoles $value): static;
|
||||
|
||||
public function setRank(int $value): static;
|
||||
|
||||
public function setSubscription(bool $value): static;
|
||||
|
||||
}
|
||||
37
shared/lib/Mail/Collection/CollectionRoles.php
Normal file
37
shared/lib/Mail/Collection/CollectionRoles.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* Mail Collection Roles
|
||||
*
|
||||
* Standard mailbox/folder roles for mail collections.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
enum CollectionRoles: string implements JsonSerializable {
|
||||
|
||||
case Inbox = 'inbox';
|
||||
case Drafts = 'drafts';
|
||||
case Sent = 'sent';
|
||||
case Trash = 'trash';
|
||||
case Junk = 'junk';
|
||||
case Archive = 'archive';
|
||||
case Outbox = 'outbox';
|
||||
case Queue = 'queue';
|
||||
case Custom = 'custom';
|
||||
|
||||
public function jsonSerialize(): string {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user