lots of improvements
This commit is contained in:
122
shared/lib/Mail/Object/MessagePartBaseAbstract.php
Normal file
122
shared/lib/Mail/Object/MessagePartBaseAbstract.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXF\Mail\Object;
|
||||
|
||||
/**
|
||||
* Abstract Message Part Base Class
|
||||
*
|
||||
* Provides common implementation for message parts (read-only)
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*/
|
||||
abstract class MessagePartBaseAbstract implements MessagePartInterface {
|
||||
|
||||
/**
|
||||
* Internal data storage
|
||||
*/
|
||||
protected array $data = [];
|
||||
|
||||
/**
|
||||
* Sub-parts storage
|
||||
* @var array<int,MessagePartInterface>
|
||||
*/
|
||||
protected array $parts = [];
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array &$data Reference to data array
|
||||
*/
|
||||
public function __construct(array &$data = null) {
|
||||
if ($data === null) {
|
||||
$data = [];
|
||||
}
|
||||
$this->data = &$data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getBlobId(): ?string {
|
||||
return $this->data['blobId'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getId(): ?string {
|
||||
return $this->data['partId'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType(): ?string {
|
||||
return $this->data['type'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDisposition(): ?string {
|
||||
return $this->data['disposition'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName(): ?string {
|
||||
return $this->data['name'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCharset(): ?string {
|
||||
return $this->data['charset'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLanguage(): ?string {
|
||||
return $this->data['language'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLocation(): ?string {
|
||||
return $this->data['location'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getParts(): array {
|
||||
return $this->parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function jsonSerialize(): array {
|
||||
$result = $this->data;
|
||||
|
||||
if (!empty($this->parts)) {
|
||||
$result['subParts'] = [];
|
||||
foreach ($this->parts as $part) {
|
||||
$result['subParts'][] = $part->jsonSerialize();
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user