lots of improvements
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;
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?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 DateTimeImmutable;
|
||||
use JsonSerializable;
|
||||
|
||||
/**
|
||||
* Mail Collection Base Interface
|
||||
*
|
||||
* Represents a mailbox/folder in a mail service.
|
||||
* For future use with full mail providers (IMAP, JMAP, etc.)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
interface ICollectionBase extends JsonSerializable {
|
||||
|
||||
public const JSON_TYPE = 'mail.collection';
|
||||
public const JSON_PROPERTY_TYPE = '@type';
|
||||
public const JSON_PROPERTY_PROVIDER = 'provider';
|
||||
public const JSON_PROPERTY_SERVICE = 'service';
|
||||
public const JSON_PROPERTY_IN = 'in';
|
||||
public const JSON_PROPERTY_ID = 'id';
|
||||
public const JSON_PROPERTY_LABEL = 'label';
|
||||
public const JSON_PROPERTY_ROLE = 'role';
|
||||
public const JSON_PROPERTY_TOTAL = 'total';
|
||||
public const JSON_PROPERTY_UNREAD = 'unread';
|
||||
|
||||
/**
|
||||
* Gets the parent collection identifier (null for root)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return string|int|null
|
||||
*/
|
||||
public function in(): string|int|null;
|
||||
|
||||
/**
|
||||
* Gets the collection identifier
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return string|int
|
||||
*/
|
||||
public function id(): string|int;
|
||||
|
||||
/**
|
||||
* Gets the collection label/name
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel(): string;
|
||||
|
||||
/**
|
||||
* Gets the collection role
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return CollectionRoles
|
||||
*/
|
||||
public function getRole(): CollectionRoles;
|
||||
|
||||
/**
|
||||
* Gets the total message count
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTotal(): ?int;
|
||||
|
||||
/**
|
||||
* Gets the unread message count
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getUnread(): ?int;
|
||||
|
||||
/**
|
||||
* Gets the collection signature/sync token
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSignature(): ?string;
|
||||
|
||||
/**
|
||||
* Gets the creation date
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return DateTimeImmutable|null
|
||||
*/
|
||||
public function created(): ?DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* Gets the modification date
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @return DateTimeImmutable|null
|
||||
*/
|
||||
public function modified(): ?DateTimeImmutable;
|
||||
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Collection;
|
||||
|
||||
/**
|
||||
* Mail Collection Mutable Interface
|
||||
*
|
||||
* Interface for creating and modifying mail collections with fluent setters.
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
interface ICollectionMutable extends ICollectionBase {
|
||||
|
||||
/**
|
||||
* Sets the parent collection identifier
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param string|int|null $in Parent collection ID or null for root
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setIn(string|int|null $in): self;
|
||||
|
||||
/**
|
||||
* Sets the collection identifier
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param string|int $id
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setId(string|int $id): self;
|
||||
|
||||
/**
|
||||
* Sets the collection label/name
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param string $label
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setLabel(string $label): self;
|
||||
|
||||
/**
|
||||
* Sets the collection role
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param CollectionRoles $role
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setRole(CollectionRoles $role): self;
|
||||
|
||||
/**
|
||||
* Sets the total message count
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param int|null $total
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setTotal(?int $total): self;
|
||||
|
||||
/**
|
||||
* Sets the unread message count
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param int|null $unread
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setUnread(?int $unread): self;
|
||||
|
||||
/**
|
||||
* Sets the collection signature/sync token
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
* @param string|null $signature
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setSignature(?string $signature): self;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user