1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the DataImporter package. |
||
7 | * |
||
8 | * (c) Loïc Sapone <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace IQ2i\DataImporter\Archiver; |
||
15 | |||
16 | use Symfony\Component\Filesystem\Filesystem; |
||
17 | |||
18 | class DateTimeArchiver implements ArchiverInterface |
||
19 | { |
||
20 | private readonly string $rootPath; |
||
21 | |||
22 | 5 | public function __construct(string $rootPath) |
|
23 | { |
||
24 | 5 | $this->rootPath = \rtrim($rootPath, '/'); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
25 | } |
||
26 | |||
27 | 5 | public function archive(\SplFileInfo $file): string |
|
28 | { |
||
29 | 5 | $now = $this->now(); |
|
30 | 5 | $archivePath = $this->rootPath.'/'.$now->format('Y/m/d'); |
|
31 | 5 | $archiveFileName = $archivePath.'/'.$now->format('YmdHis').'_'.$file->getFilename(); |
|
32 | |||
33 | 5 | $filesystem = new Filesystem(); |
|
34 | 5 | $filesystem->mkdir($archivePath); |
|
35 | 4 | $filesystem->rename($file->getPathname(), $archiveFileName); |
|
36 | |||
37 | 4 | return $archiveFileName; |
|
38 | } |
||
39 | |||
40 | 4 | public function now(): \DateTimeInterface |
|
41 | { |
||
42 | 4 | return new \DateTime(); |
|
43 | } |
||
44 | } |
||
45 |