Skip to content

Commit bfa8a09

Browse files
Andrey ErdikovAndrey Erdikov
authored andcommitted
[C0-3455] Добавил сущности, репозитории, маппинг для файлов и каталогов
1 parent 1d59754 commit bfa8a09

16 files changed

+450
-0
lines changed

src/Domain/Entity/MediaCatalog.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Entity;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\Id;
8+
9+
class MediaCatalog
10+
{
11+
/**
12+
* @var Id
13+
*/
14+
private $id;
15+
16+
/**
17+
* @var string
18+
*/
19+
private $name;
20+
21+
public function __construct(Id $id, string $name)
22+
{
23+
$this->id = $id;
24+
$this->name = $name;
25+
}
26+
27+
public function getId(): Id
28+
{
29+
return $this->id;
30+
}
31+
32+
public function getName(): string
33+
{
34+
return $this->name;
35+
}
36+
}

src/Domain/Entity/MediaFile.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Entity;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\Id;
8+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\MediaFileStorage;
9+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\MediaFileType;
10+
11+
class MediaFile
12+
{
13+
/**
14+
* @var Id
15+
*/
16+
private $id;
17+
18+
/**
19+
* @var MediaCatalog
20+
*/
21+
private $catalog;
22+
23+
/**
24+
* @var string
25+
*/
26+
private $title;
27+
28+
/**
29+
* @var MediaFileType
30+
*/
31+
private $type;
32+
33+
/**
34+
* @var string
35+
*/
36+
private $name;
37+
38+
/**
39+
* @var MediaFileStorage
40+
*/
41+
private $storage;
42+
43+
public function __construct(Id $id, MediaCatalog $catalog, string $title, MediaFileType $type, string $name, MediaFileStorage $storage)
44+
{
45+
$this->id = $id;
46+
$this->catalog = $catalog;
47+
$this->title = $title;
48+
$this->type = $type;
49+
$this->name = $name;
50+
$this->storage = $storage;
51+
}
52+
53+
public function getId(): Id
54+
{
55+
return $this->id;
56+
}
57+
58+
public function getCatalog(): MediaCatalog
59+
{
60+
return $this->catalog;
61+
}
62+
63+
public function getTitle(): string
64+
{
65+
return $this->title;
66+
}
67+
68+
public function getType(): MediaFileType
69+
{
70+
return $this->type;
71+
}
72+
73+
public function getName(): string
74+
{
75+
return $this->name;
76+
}
77+
78+
public function getStorage(): MediaFileStorage
79+
{
80+
return $this->storage;
81+
}
82+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Traits\Exception\IncorrectValueObjectException;
8+
use Skyeng\MarketingCmsBundle\Domain\Traits\ValueObjectTrait;
9+
10+
class MediaFileStorage
11+
{
12+
public const S3_STORAGE = 's3';
13+
public const LOCAL_STORAGE = 'local';
14+
15+
public const AVAILABLE_STORAGES = [
16+
self::S3_STORAGE => self::S3_STORAGE,
17+
self::LOCAL_STORAGE => self::LOCAL_STORAGE,
18+
];
19+
20+
use ValueObjectTrait;
21+
22+
protected function checkValue(string $value): void
23+
{
24+
if (!in_array($value, self::AVAILABLE_STORAGES)) {
25+
throw new IncorrectValueObjectException('This media file storage is not supported');
26+
}
27+
}
28+
29+
public function isS3(): bool
30+
{
31+
return $this->value === self::S3_STORAGE;
32+
}
33+
34+
public function isLocal(): bool
35+
{
36+
return $this->value === self::LOCAL_STORAGE;
37+
}
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Traits\Exception\IncorrectValueObjectException;
8+
use Skyeng\MarketingCmsBundle\Domain\Traits\ValueObjectTrait;
9+
10+
class MediaFileType
11+
{
12+
public const IMAGE_TYPE = 'image';
13+
public const PDF_TYPE = 'pdf';
14+
public const VIDEO_TYPE = 'video';
15+
16+
public const AVAILABLE_TYPES = [
17+
self::IMAGE_TYPE => self::IMAGE_TYPE,
18+
self::PDF_TYPE => self::PDF_TYPE,
19+
self::VIDEO_TYPE => self::VIDEO_TYPE,
20+
];
21+
22+
use ValueObjectTrait;
23+
24+
protected function checkValue(string $value): void
25+
{
26+
if (!in_array($value, self::AVAILABLE_TYPES)) {
27+
throw new IncorrectValueObjectException('This media file type is not supported');
28+
}
29+
}
30+
31+
public function isPdf(): bool
32+
{
33+
return $this->value === self::PDF_TYPE;
34+
}
35+
36+
public function isImage(): bool
37+
{
38+
return $this->value === self::IMAGE_TYPE;
39+
}
40+
41+
public function isVideo(): bool
42+
{
43+
return $this->value === self::VIDEO_TYPE;
44+
}
45+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaCatalogRepository\Exception;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Exception\NotFoundException;
8+
9+
class MediaCatalogNotFoundException extends NotFoundException
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaCatalogRepository\Exception;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Exception\ServiceException;
8+
9+
class MediaCatalogRepositoryException extends ServiceException
10+
{
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaCatalogRepository;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Entity\MediaCatalog;
8+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\Id;
9+
use Skyeng\MarketingCmsBundle\Domain\Repository\MediaCatalogRepository\Exception\MediaFileRepositoryException;
10+
11+
interface MediaCatalogRepositoryInterface
12+
{
13+
public function getNextIdentity(): Id;
14+
15+
/**
16+
* @return MediaCatalog[]
17+
* @throws MediaFileRepositoryException
18+
*/
19+
public function getAll(): array;
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaFileRepository\Exception;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Exception\NotFoundException;
8+
9+
class MediaFileNotFoundException extends NotFoundException
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaFileRepository\Exception;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Exception\ServiceException;
8+
9+
class MediaFileRepositoryException extends ServiceException
10+
{
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Skyeng\MarketingCmsBundle\Domain\Repository\MediaFileRepository;
6+
7+
use Skyeng\MarketingCmsBundle\Domain\Entity\MediaCatalog;
8+
use Skyeng\MarketingCmsBundle\Domain\Entity\MediaFile;
9+
use Skyeng\MarketingCmsBundle\Domain\Entity\ValueObject\Id;
10+
use Skyeng\MarketingCmsBundle\Domain\Repository\MediaFileRepository\Exception\MediaFileRepositoryException;
11+
12+
interface MediaFileRepositoryInterface
13+
{
14+
public function getNextIdentity(): Id;
15+
16+
/**
17+
* @return MediaFile[]
18+
* @throws MediaFileRepositoryException
19+
*/
20+
public function getByCatalog(MediaCatalog $catalog): array;
21+
}

0 commit comments

Comments
 (0)