Files
firefly-iii/app/Transformers/AttachmentTransformer.php

75 lines
2.6 KiB
PHP
Raw Normal View History

2018-02-04 15:57:35 +01:00
<?php
2018-02-04 15:57:35 +01:00
/**
2018-02-06 07:49:56 +01:00
* AttachmentTransformer.php
2020-02-16 13:57:18 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-02-04 15:57:35 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-02-04 15:57:35 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-02-04 15:57:35 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-02-04 15:57:35 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-02-04 15:57:35 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-04 15:57:35 +01:00
*/
declare(strict_types=1);
namespace FireflyIII\Transformers;
2018-02-06 07:49:56 +01:00
use FireflyIII\Models\Attachment;
2018-09-27 07:43:30 +02:00
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
2018-02-04 15:57:35 +01:00
/**
2018-02-06 07:49:56 +01:00
* Class AttachmentTransformer
2018-02-04 15:57:35 +01:00
*/
2018-12-16 13:55:19 +01:00
class AttachmentTransformer extends AbstractTransformer
2018-02-04 15:57:35 +01:00
{
2025-05-04 13:04:33 +02:00
private readonly AttachmentRepositoryInterface $repository;
2018-09-27 07:43:30 +02:00
/**
* AttachmentTransformer constructor.
*/
2018-12-16 13:55:19 +01:00
public function __construct()
{
2018-09-27 07:43:30 +02:00
$this->repository = app(AttachmentRepositoryInterface::class);
}
2018-02-04 15:57:35 +01:00
/**
* Transform attachment.
2018-02-04 15:57:35 +01:00
*/
2018-02-06 07:49:56 +01:00
public function transform(Attachment $attachment): array
2018-02-04 15:57:35 +01:00
{
2018-09-27 07:43:30 +02:00
$this->repository->setUser($attachment->user);
2018-02-04 15:57:35 +01:00
return [
2025-05-04 17:41:26 +02:00
'id' => (string) $attachment->id,
'created_at' => $attachment->created_at->toAtomString(),
'updated_at' => $attachment->updated_at->toAtomString(),
'attachable_id' => (string) $attachment->attachable_id,
'attachable_type' => str_replace('FireflyIII\Models\\', '', $attachment->attachable_type),
'hash' => $attachment->md5,
'filename' => $attachment->filename,
'download_url' => route('api.v1.attachments.download', [$attachment->id]),
'upload_url' => route('api.v1.attachments.upload', [$attachment->id]),
'title' => $attachment->title,
'notes' => $this->repository->getNoteText($attachment),
'mime' => $attachment->mime,
'size' => (int) $attachment->size,
'links' => [
[
'rel' => 'self',
2023-12-20 19:35:52 +01:00
'uri' => '/attachment/'.$attachment->id,
],
2018-02-09 19:11:55 +01:00
],
2018-02-04 15:57:35 +01:00
];
}
2018-03-05 19:35:58 +01:00
}