1 | <?php |
||
24 | final class Backup implements BackupInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $name; |
||
30 | |||
31 | /** |
||
32 | * @var FileInterface[] |
||
33 | */ |
||
34 | private $files; |
||
35 | |||
36 | /** |
||
37 | * @var int |
||
38 | */ |
||
39 | private $size; |
||
40 | |||
41 | /** |
||
42 | * @var \DateTimeInterface |
||
43 | */ |
||
44 | private $createdAt; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTimeInterface |
||
48 | */ |
||
49 | private $modifiedAt; |
||
50 | |||
51 | 14 | public function __construct($name, array $files = array(), $size = 0, $createdAt = null, $modifiedAt = null) |
|
52 | { |
||
53 | 14 | $this->name = $name; |
|
54 | 14 | $this->size = $size; |
|
55 | 14 | $this->createdAt = is_null($createdAt) ? new \DateTime('now') : $createdAt; |
|
56 | 14 | $this->modifiedAt = is_null($modifiedAt) ? new \DateTime('now') : $modifiedAt; |
|
57 | |||
58 | 14 | if (count($files)) { |
|
59 | 4 | $this->setFiles($files); |
|
60 | 4 | } |
|
61 | 14 | } |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 14 | public function getName() |
|
67 | { |
||
68 | 14 | return $this->name; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function setName($name) |
||
75 | { |
||
76 | $this->name = $name; |
||
77 | |||
78 | return $this; |
||
79 | } |
||
80 | |||
81 | public function addFiles(array $files) |
||
89 | |||
90 | 4 | public function addFile(FileInterface $file) |
|
91 | { |
||
92 | 4 | $this->files[] = $file; |
|
93 | 4 | $this->size += $file->getSize(); |
|
94 | |||
95 | 4 | return $this; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 4 | public function getFiles() |
|
102 | { |
||
103 | 4 | return $this->files; |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | 4 | public function setFiles(array $files) |
|
110 | { |
||
111 | 4 | $this->files = $files; |
|
112 | 4 | $this->size = 0; |
|
113 | 4 | foreach ($this->files as $file) { |
|
114 | 4 | $this->size += $file->getSize(); |
|
115 | 4 | } |
|
116 | |||
117 | 4 | return $this; |
|
118 | } |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | 8 | public function getSize() |
|
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function setSize($size) |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | 10 | public function getCreatedAt() |
|
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function setCreatedAt($createdAt) |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | public function getModifiedAt() |
||
163 | |||
164 | /** |
||
165 | * {@inheritdoc} |
||
166 | */ |
||
167 | public function setModifiedAt($modifiedAt) |
||
173 | } |
||
174 |