Skip to content

Commit 1c7fd0a

Browse files
author
Stanislav Idolov
committed
Eliminate AbstractExtensibleModel usage
1 parent 01ac38b commit 1c7fd0a

File tree

27 files changed

+324
-142
lines changed

27 files changed

+324
-142
lines changed

app/code/Magento/MediaGallery/Model/Asset.php

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,123 +10,199 @@
1010

1111
use Magento\MediaGalleryApi\Api\Data\AssetExtensionInterface;
1212
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
13-
use Magento\Framework\Model\AbstractExtensibleModel;
1413

1514
/**
1615
* Media Gallery Asset
1716
*/
18-
class Asset extends AbstractExtensibleModel implements AssetInterface
17+
class Asset implements AssetInterface
1918
{
20-
private const ID = 'id';
21-
private const PATH = 'path';
22-
private const TITLE = 'title';
23-
private const SOURCE = 'source';
24-
private const CONTENT_TYPE = 'content_type';
25-
private const WIDTH = 'width';
26-
private const HEIGHT = 'height';
27-
private const SIZE = 'size';
28-
private const CREATED_AT = 'created_at';
29-
private const UPDATED_AT = 'updated_at';
19+
/**
20+
* @var int|null
21+
*/
22+
private $id;
23+
24+
/**
25+
* @var string
26+
*/
27+
private $path;
28+
29+
/**
30+
* @var string|null
31+
*/
32+
private $title;
33+
34+
/**
35+
* @var string|null
36+
*/
37+
private $source;
38+
39+
/**
40+
* @var string
41+
*/
42+
private $contentType;
43+
44+
/**
45+
* @var int
46+
*/
47+
private $width;
48+
49+
/**
50+
* @var int
51+
*/
52+
private $height;
53+
54+
/**
55+
* @var int
56+
*/
57+
private $size;
58+
59+
/**
60+
* @var string|null
61+
*/
62+
private $createdAt;
63+
64+
/**
65+
* @var string|null
66+
*/
67+
private $updatedAt;
68+
69+
/**
70+
* @var AssetExtensionInterface|null
71+
*/
72+
private $extensionAttributes;
73+
74+
/**
75+
* @param string $path
76+
* @param string $contentType
77+
* @param int $width
78+
* @param int $height
79+
* @param int $size
80+
* @param int|null $id
81+
* @param string|null $title
82+
* @param string|null $source
83+
* @param string|null $createdAt
84+
* @param string|null $updatedAt
85+
* @param AssetExtensionInterface|null $extensionAttributes
86+
*/
87+
public function __construct(
88+
string $path,
89+
string $contentType,
90+
int $width,
91+
int $height,
92+
int $size,
93+
?int $id = null,
94+
?string $title = null,
95+
?string $source = null,
96+
?string $createdAt = null,
97+
?string $updatedAt = null,
98+
?AssetExtensionInterface $extensionAttributes = null
99+
) {
100+
$this->path = $path;
101+
$this->contentType = $contentType;
102+
$this->width = $width;
103+
$this->height = $height;
104+
$this->size = $size;
105+
$this->id = $id;
106+
$this->title = $title;
107+
$this->source = $source;
108+
$this->createdAt = $createdAt;
109+
$this->updatedAt = $updatedAt;
110+
$this->extensionAttributes = $extensionAttributes;
111+
}
30112

31113
/**
32114
* @inheritdoc
33115
*/
34116
public function getId(): ?int
35117
{
36-
$id = $this->getData(self::ID);
37-
38-
if (!$id) {
39-
return null;
40-
}
41-
42-
return (int) $id;
118+
return $this->id;
43119
}
44120

45121
/**
46122
* @inheritdoc
47123
*/
48124
public function getPath(): string
49125
{
50-
return (string) $this->getData(self::PATH);
126+
return $this->path;
51127
}
52128

53129
/**
54130
* @inheritdoc
55131
*/
56132
public function getTitle(): ?string
57133
{
58-
return $this->getData(self::TITLE);
134+
return $this->title;
59135
}
60136

61137
/**
62138
* @inheritdoc
63139
*/
64140
public function getSource(): ?string
65141
{
66-
return $this->getData(self::SOURCE);
142+
return $this->source;
67143
}
68144

69145
/**
70146
* @inheritdoc
71147
*/
72148
public function getContentType(): string
73149
{
74-
return (string) $this->getData(self::CONTENT_TYPE);
150+
return $this->contentType;
75151
}
76152

77153
/**
78154
* @inheritdoc
79155
*/
80156
public function getWidth(): int
81157
{
82-
return (int) $this->getData(self::WIDTH);
158+
return $this->width;
83159
}
84160

85161
/**
86162
* @inheritdoc
87163
*/
88164
public function getHeight(): int
89165
{
90-
return (int) $this->getData(self::HEIGHT);
166+
return $this->height;
91167
}
92168

93169
/**
94170
* @inheritdoc
95171
*/
96172
public function getSize(): int
97173
{
98-
return (int) $this->getData(self::SIZE);
174+
return $this->size;
99175
}
100176

101177
/**
102178
* @inheritdoc
103179
*/
104-
public function getCreatedAt(): string
180+
public function getCreatedAt(): ?string
105181
{
106-
return (string) $this->getData(self::CREATED_AT);
182+
return $this->createdAt;
107183
}
108184

109185
/**
110186
* @inheritdoc
111187
*/
112-
public function getUpdatedAt(): string
188+
public function getUpdatedAt(): ?string
113189
{
114-
return (string) $this->getData(self::UPDATED_AT);
190+
return $this->updatedAt;
115191
}
116192

117193
/**
118194
* @inheritdoc
119195
*/
120-
public function getExtensionAttributes(): AssetExtensionInterface
196+
public function getExtensionAttributes(): ?AssetExtensionInterface
121197
{
122-
return $this->_getExtensionAttributes();
198+
return $this->extensionAttributes;
123199
}
124200

125201
/**
126202
* @inheritdoc
127203
*/
128-
public function setExtensionAttributes(AssetExtensionInterface $extensionAttributes): void
204+
public function setExtensionAttributes(?AssetExtensionInterface $extensionAttributes): void
129205
{
130-
$this->_setExtensionAttributes($extensionAttributes);
206+
$this->extensionAttributes = $extensionAttributes;
131207
}
132208
}

app/code/Magento/MediaGallery/Model/Asset/Command/DeleteByPath.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
use Psr\Log\LoggerInterface;
1515

1616
/**
17-
* Class DeleteByPath
17+
* Delete media asset by path
18+
*
1819
* @deprecated use \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface instead
1920
* @see \Magento\MediaGalleryApi\Api\DeleteAssetsByPathInterface
2021
*/

app/code/Magento/MediaGallery/Model/Asset/Command/GetById.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,20 @@ public function execute(int $mediaAssetId): AssetInterface
8989
}
9090

9191
try {
92-
return $this->assetFactory->create(['data' => $mediaAssetData]);
92+
return $this->assetFactory->create(
93+
[
94+
'id' => $mediaAssetData['id'],
95+
'path' => $mediaAssetData['path'],
96+
'title' => $mediaAssetData['title'],
97+
'source' => $mediaAssetData['source'],
98+
'contentType' => $mediaAssetData['content_type'],
99+
'width' => $mediaAssetData['width'],
100+
'height' => $mediaAssetData['height'],
101+
'size' => $mediaAssetData['size'],
102+
'createdAt' => $mediaAssetData['created_at'],
103+
'updatedAt' => $mediaAssetData['updated_at'],
104+
]
105+
);
93106
} catch (\Exception $exception) {
94107
$this->logger->critical($exception);
95108
$message = __(

app/code/Magento/MediaGallery/Model/Asset/Command/GetByPath.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Psr\Log\LoggerInterface;
1717

1818
/**
19-
* Class GetByPath
19+
* Provide media asset by path
20+
*
2021
* @deprecated use \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface instead
2122
* @see \Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface
2223
*/
@@ -59,7 +60,7 @@ public function __construct(
5960
}
6061

6162
/**
62-
* Return media asset asset list
63+
* Return media asset
6364
*
6465
* @param string $path
6566
*
@@ -80,7 +81,20 @@ public function execute(string $path): AssetInterface
8081
throw new NoSuchEntityException($message);
8182
}
8283

83-
return $this->mediaAssetFactory->create(['data' => $data]);
84+
return $this->mediaAssetFactory->create(
85+
[
86+
'id' => $data['id'],
87+
'path' => $data['path'],
88+
'title' => $data['title'],
89+
'source' => $data['source'],
90+
'contentType' => $data['content_type'],
91+
'width' => $data['width'],
92+
'height' => $data['height'],
93+
'size' => $data['size'],
94+
'createdAt' => $data['created_at'],
95+
'updatedAt' => $data['updated_at'],
96+
]
97+
);
8498
} catch (\Exception $exception) {
8599
$this->logger->critical($exception);
86100
$message = __('An error occurred during get media asset list: %1', $exception->getMessage());

app/code/Magento/MediaGallery/Model/Asset/Command/Save.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Framework\Exception\CouldNotSaveException;
12-
use Magento\Framework\Reflection\DataObjectProcessor;
1312
use Magento\MediaGalleryApi\Api\Data\AssetInterface;
1413
use Magento\MediaGalleryApi\Model\Asset\Command\SaveInterface;
1514
use Psr\Log\LoggerInterface;
1615

1716
/**
18-
* Class Save
17+
* Save media asset
18+
*
1919
* @deprecated use \Magento\MediaGalleryApi\Api\SaveAssetsInterface instead
2020
* @see \Magento\MediaGalleryApi\Api\SaveAssetsInterface
2121
*/
@@ -48,7 +48,7 @@ public function __construct(
4848
}
4949

5050
/**
51-
* Save media assets
51+
* Save media asset
5252
*
5353
* @param AssetInterface $mediaAsset
5454
*

0 commit comments

Comments
 (0)