|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: wechsler |
|
5
|
|
|
* Date: 11/02/2017 |
|
6
|
|
|
* Time: 20:19 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Phase\TakeATicketBundle\Command; |
|
10
|
|
|
|
|
11
|
|
|
use Phase\TakeATicket\SongLoader; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class LoadSongsCommand extends ContainerAwareCommand |
|
18
|
|
|
{ |
|
19
|
|
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
$this |
|
22
|
|
|
// the name of the command (the part after "bin/console") |
|
23
|
|
|
->setName('ticket:load-songs') |
|
24
|
|
|
// the short description shown while running "php bin/console list" |
|
25
|
|
|
->setDescription('Load songlist') |
|
26
|
|
|
// the full command description shown when running the command with |
|
27
|
|
|
// the "--help" option |
|
28
|
|
|
->setHelp("Load songlist from XLS file") |
|
29
|
|
|
->addArgument('file', InputArgument::REQUIRED, 'Name of the CSV file.') |
|
30
|
|
|
->addArgument('mapper', InputArgument::OPTIONAL, 'ShortName of mapper to use', 'rclrockband'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$rowMapperManager = $this->getContainer()->get('songloader.rowmappermanager'); |
|
36
|
|
|
/** @var SongLoader\RowMapperManager $rowMapperManager */ |
|
37
|
|
|
$mapper = $input->getArgument('mapper'); |
|
38
|
|
|
$mapperClass = $rowMapperManager->getRowMapperClassByShortName($mapper); |
|
39
|
|
|
|
|
40
|
|
|
if (!$mapperClass) { |
|
|
|
|
|
|
41
|
|
|
throw new \InvalidArgumentException("'$mapper' is not a valid mapper name"); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$loader = new SongLoader(); |
|
45
|
|
|
$loader->setRowMapperClass($mapperClass); |
|
46
|
|
|
|
|
47
|
|
|
$file = $input->getArgument('file'); |
|
48
|
|
|
$songsLoaded = $loader->run($file, $this->getContainer()->get('database_connection')); |
|
49
|
|
|
$output->writeln(""); |
|
50
|
|
|
$output->writeln("Loaded $songsLoaded songs from $file"); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: