-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDocumentBuilder.php
121 lines (93 loc) · 2.66 KB
/
DocumentBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Copyright © OpenGento, All rights reserved.
* See LICENSE bundled with this library for license details.
*/
declare(strict_types=1);
namespace Opengento\Document\Model;
use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\Api\ExtensionAttributesInterface;
use Magento\Framework\Api\SimpleBuilderInterface;
use Magento\Framework\Model\AbstractModel;
use Opengento\Document\Api\Data\DocumentInterface;
use Opengento\Document\Api\Data\DocumentInterfaceFactory;
final class DocumentBuilder implements SimpleBuilderInterface
{
/**
* @var array
*/
private $data;
/**
* @var DocumentInterfaceFactory
*/
private $documentFactory;
public function __construct(
DocumentInterfaceFactory $documentFactory
) {
$this->documentFactory = $documentFactory;
$this->data = [];
}
public function setId(int $entityId): self
{
$this->data['entity_id'] = $entityId;
return $this;
}
public function setTypeId(int $typeId): self
{
$this->data['type_id'] = $typeId;
return $this;
}
public function setCode(string $code): self
{
$this->data['code'] = $code;
return $this;
}
public function setName(string $name): self
{
$this->data['name'] = $name;
return $this;
}
public function setDescription(string $description): self
{
$this->data['description'] = $description;
return $this;
}
public function setLocale(string $locale): self
{
$this->data['file_locale'] = $locale;
return $this;
}
public function setFileName(string $fileName): self
{
$this->data['file_name'] = $fileName;
return $this;
}
public function setFilePath(string $filePath): self
{
$this->data['file_path'] = $filePath;
return $this;
}
public function setImageFileName(string $imageFileName): self
{
$this->data['image_file_name'] = $imageFileName;
return $this;
}
public function setExtensionAttributes(ExtensionAttributesInterface $extensionAttributes): self
{
$this->data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY] = $extensionAttributes;
return $this;
}
public function getData(): array
{
return $this->data;
}
public function create(): DocumentInterface
{
/** @var DocumentInterface $document */
$document = $this->documentFactory->create(['data' => $this->getData()]);
if ($document instanceof AbstractModel) {
$document->setHasDataChanges(true);
}
return $document;
}
}