refactor: message object properties
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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\Object;
|
||||
|
||||
/**
|
||||
* Shared Message Part implementation matching the frontend JSON shape.
|
||||
*/
|
||||
class MessagePart extends MessagePartMutableAbstract {
|
||||
|
||||
public static function fromArray(array $data): self {
|
||||
$part = new self();
|
||||
$part->data = $data;
|
||||
|
||||
if (isset($part->data[MessagePartInterface::PROPERTY_SUB_PARTS]) && is_array($part->data[MessagePartInterface::PROPERTY_SUB_PARTS])) {
|
||||
foreach ($part->data[MessagePartInterface::PROPERTY_SUB_PARTS] as $entry) {
|
||||
if (is_object($entry)) {
|
||||
$entry = get_object_vars($entry);
|
||||
}
|
||||
|
||||
if (is_array($entry)) {
|
||||
$part->parts[] = self::fromArray($entry);
|
||||
}
|
||||
}
|
||||
|
||||
unset($part->data[MessagePartInterface::PROPERTY_SUB_PARTS]);
|
||||
}
|
||||
|
||||
return $part;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user