1<?php
2/**
3 * Copyright since 2007 PrestaShop SA and Contributors
4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5 *
6 * NOTICE OF LICENSE
7 *
8 * This source file is subject to the Open Software License (OSL 3.0)
9 * that is bundled with this package in the file LICENSE.md.
10 * It is also available through the world-wide-web at this URL:
11 * https://opensource.org/licenses/OSL-3.0
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to https://devdocs.prestashop.com/ for more information.
21 *
22 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
23 * @copyright Since 2007 PrestaShop SA and Contributors
24 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25 */
26
27declare(strict_types=1);
28
29namespace PrestaShop\PrestaShop\Adapter\Attachment;
30
31use Attachment;
32use PrestaShop\PrestaShop\Adapter\AbstractObjectModelRepository;
33use PrestaShop\PrestaShop\Core\Domain\Attachment\Exception\AttachmentNotFoundException;
34use PrestaShop\PrestaShop\Core\Domain\Attachment\ValueObject\AttachmentId;
35use PrestaShop\PrestaShop\Core\Exception\CoreException;
36
37/**
38 * Methods to access Attachment data source
39 */
40class AttachmentRepository extends AbstractObjectModelRepository
41{
42    /**
43     * @param AttachmentId $attachmentId
44     *
45     * @return Attachment
46     *
47     * @throws CoreException
48     * @throws AttachmentNotFoundException
49     */
50    public function get(AttachmentId $attachmentId): Attachment
51    {
52        /** @var Attachment $attachment */
53        $attachment = $this->getObjectModel(
54            $attachmentId->getValue(),
55            Attachment::class,
56            AttachmentNotFoundException::class
57        );
58
59        return $attachment;
60    }
61
62    /**
63     * @param AttachmentId $attachmentId
64     *
65     * @throws CoreException
66     */
67    public function assertAttachmentExists(AttachmentId $attachmentId): void
68    {
69        $this->assertObjectModelExists($attachmentId->getValue(), 'attachment', AttachmentNotFoundException::class);
70    }
71}
72