|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Monsieur Biz <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace MonsieurBiz\SyliusRichEditorPlugin\Fixture; |
|
15
|
|
|
|
|
16
|
|
|
use MonsieurBiz\SyliusRichEditorPlugin\Uploader\FixtureFileUploaderInterface; |
|
17
|
|
|
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; |
|
18
|
|
|
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; |
|
19
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
21
|
|
|
|
|
22
|
|
|
final class FileFixture extends AbstractFixture implements FixtureInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var FixtureFileUploaderInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private FixtureFileUploaderInterface $uploader; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param FixtureFileUploaderInterface $uploader |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(FixtureFileUploaderInterface $uploader) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->uploader = $uploader; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param array $options |
|
39
|
|
|
*/ |
|
40
|
|
|
public function load(array $options): void |
|
41
|
|
|
{ |
|
42
|
|
|
foreach ($options['files'] as $data) { |
|
43
|
|
|
$file = new UploadedFile($data['source_path'], basename($data['source_path'])); |
|
44
|
|
|
$this->uploader->upload($file, $data['target_path']); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getName(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return 'monsieurbiz_rich_editor_file'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param ArrayNodeDefinition $optionsNode |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void |
|
60
|
|
|
{ |
|
61
|
|
|
/** @phpstan-ignore-next-line */ |
|
62
|
|
|
$optionsNode |
|
63
|
|
|
->children() |
|
64
|
|
|
->arrayNode('files') |
|
65
|
|
|
->arrayPrototype() |
|
66
|
|
|
->children() |
|
67
|
|
|
->scalarNode('source_path')->cannotBeEmpty()->end() |
|
68
|
|
|
->scalarNode('target_path')->cannotBeEmpty()->end() |
|
|
|
|
|
|
69
|
|
|
->end() |
|
70
|
|
|
->end() |
|
71
|
|
|
->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|