1 | <?php |
||
25 | final class Backup implements BackupInterface |
||
26 | { |
||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name; |
||
31 | |||
32 | /** |
||
33 | * @var FileInterface[] |
||
34 | */ |
||
35 | private $files; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $size; |
||
41 | |||
42 | /** |
||
43 | * @var \DateTimeInterface |
||
44 | */ |
||
45 | private $createdAt; |
||
46 | |||
47 | /** |
||
48 | * @var \DateTimeInterface |
||
49 | */ |
||
50 | private $modifiedAt; |
||
51 | |||
52 | 34 | public function __construct($name, array $files = array(), $size = 0, $createdAt = null, $modifiedAt = null) |
|
53 | { |
||
54 | 34 | $this->name = Filename::sanitize($name); |
|
55 | 34 | $this->size = $size; |
|
56 | 34 | $this->createdAt = is_null($createdAt) ? new \DateTime('now') : $createdAt; |
|
57 | 34 | $this->modifiedAt = is_null($modifiedAt) ? new \DateTime('now') : $modifiedAt; |
|
58 | |||
59 | 34 | if (count($files)) { |
|
60 | 18 | $this->setFiles($files); |
|
61 | 9 | } |
|
62 | 34 | } |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 32 | public function getName() |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 2 | public function setName($name) |
|
76 | { |
||
77 | 2 | $this->name = Filename::sanitize($name); |
|
78 | |||
79 | 2 | return $this; |
|
80 | } |
||
81 | |||
82 | 4 | public function addFiles(array $files) |
|
83 | { |
||
84 | 4 | foreach ($files as $file) { |
|
85 | 2 | $this->addFile($file); |
|
86 | 2 | } |
|
87 | |||
88 | 4 | return $this; |
|
89 | } |
||
90 | |||
91 | 2 | public function addFile(FileInterface $file) |
|
92 | { |
||
93 | 2 | $this->files[] = $file; |
|
94 | 2 | $this->size += $file->getSize(); |
|
95 | |||
96 | 2 | return $this; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 22 | public function getFiles() |
|
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | 18 | public function setFiles(array $files) |
|
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | 8 | public function getSize() |
|
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function setSize($size) |
||
138 | |||
139 | /** |
||
140 | * {@inheritdoc} |
||
141 | */ |
||
142 | 10 | public function getCreatedAt() |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | public function setCreatedAt($createdAt) |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function getModifiedAt() |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function setModifiedAt($modifiedAt) |
||
174 | } |
||
175 |