. */ declare(strict_types=1); namespace FireflyIII\Transformers; use FireflyIII\Models\TransactionJournalLink; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; /** * * Class TransactionLinkTransformer */ class TransactionLinkTransformer extends AbstractTransformer { /** @var JournalRepositoryInterface */ private $repository; /** * Constructor. * */ public function __construct() { $this->repository = app(JournalRepositoryInterface::class); } /** * @param TransactionJournalLink $link * * @return array */ public function transform(TransactionJournalLink $link): array { $notes = $this->repository->getLinkNoteText($link); return [ 'id' => (string)$link->id, 'created_at' => $link->created_at->toAtomString(), 'updated_at' => $link->updated_at->toAtomString(), 'inward_id' => (string)$link->source_id, 'outward_id' => (string)$link->destination_id, 'link_type_id' => (string)$link->link_type_id, 'notes' => '' === $notes ? null : $notes, 'links' => [ [ 'rel' => 'self', 'uri' => '/transaction_links/'.$link->id, ], ], ]; } }