|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Partnermarketing\FileSystemBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Partnermarketing\FileSystemBundle\FileSystem\FileSystem; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This command checks if a specific file exists in a file system, depending on the adapter passed. |
|
13
|
|
|
* |
|
14
|
|
|
* Usage: `php app/console partnermarketing:file_system:exists amazon_s3 dir/filename.png` |
|
15
|
|
|
*/ |
|
16
|
|
|
class FindCommand extends ContainerAwareCommand |
|
17
|
|
|
{ |
|
18
|
|
|
protected $availableAdapters = [ |
|
19
|
|
|
'amazon_s3', |
|
20
|
|
|
'local_storage' |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
protected function configure() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->setName('partnermarketing:file_system:exists') |
|
26
|
|
|
->setDescription('Check if a file exists') |
|
27
|
|
|
->addArgument('adapter', InputArgument::REQUIRED, 'amazon_s3 | local_storage - adapter to use') |
|
28
|
|
|
->addArgument('filename', InputArgument::REQUIRED, 'Image filename to search'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$adapterName = $input->getArgument('adapter'); |
|
34
|
|
|
if (!in_array($adapterName, $this->availableAdapters)) { |
|
35
|
|
|
$output->writeln( |
|
36
|
|
|
'Invalid adapter name supplied! Adapters available: ' . implode(', ', $this->availableAdapters) |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$adapter = $this->getContainer()->get('partnermarketing_file_system.factory')->build($adapterName); |
|
43
|
|
|
$fileSystem = new FileSystem($adapter); |
|
44
|
|
|
|
|
45
|
|
|
$filename = $input->getArgument('filename'); |
|
46
|
|
|
|
|
47
|
|
|
if ($fileSystem->exists($filename)) { |
|
48
|
|
|
$output->writeln('File was found using adapter (' . $adapterName . ')'); |
|
49
|
|
|
} else { |
|
50
|
|
|
$output->writeln('File not found using adapter (' . $adapterName . ')'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|