1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Contains class YapealAutoMagic. |
4
|
|
|
* |
5
|
|
|
* PHP version 5.5 |
6
|
|
|
* |
7
|
|
|
* LICENSE: |
8
|
|
|
* This file is part of Yet Another Php Eve Api Library also know as Yapeal |
9
|
|
|
* which can be used to access the Eve Online API data and place it into a |
10
|
|
|
* database. |
11
|
|
|
* Copyright (C) 2016 Michael Cummings |
12
|
|
|
* |
13
|
|
|
* This program is free software: you can redistribute it and/or modify it |
14
|
|
|
* under the terms of the GNU Lesser General Public License as published by the |
15
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
16
|
|
|
* option) any later version. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
19
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
21
|
|
|
* for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
24
|
|
|
* along with this program. If not, see |
25
|
|
|
* <http://www.gnu.org/licenses/>. |
26
|
|
|
* |
27
|
|
|
* You should be able to find a copy of this license in the LICENSE.md file. A |
28
|
|
|
* copy of the GNU GPL should also be available in the GNU-GPL.md file. |
29
|
|
|
* |
30
|
|
|
* @copyright 2016 Michael Cummings |
31
|
|
|
* @license LGPL-3.0+ |
32
|
|
|
* @author Michael Cummings <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
namespace Yapeal\Console\Command; |
35
|
|
|
|
36
|
|
|
use Symfony\Component\Console\Command\Command; |
37
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
38
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
39
|
|
|
use Yapeal\CommonToolsTrait; |
40
|
|
|
use Yapeal\Container\ContainerInterface; |
41
|
|
|
use Yapeal\Event\EveApiEventEmitterTrait; |
42
|
|
|
use Yapeal\Yapeal; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class YapealAutoMagic. |
46
|
|
|
*/ |
47
|
|
|
class YapealAutoMagic extends Command |
48
|
|
|
{ |
49
|
|
|
use CommonToolsTrait, ConfigFileTrait, EveApiEventEmitterTrait; |
50
|
|
|
/** |
51
|
|
|
* @param string|null $name |
52
|
|
|
* @param ContainerInterface $dic |
53
|
|
|
* |
54
|
|
|
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException |
55
|
|
|
* @throws \Symfony\Component\Console\Exception\LogicException |
56
|
|
|
*/ |
57
|
|
|
public function __construct($name, ContainerInterface $dic) |
58
|
|
|
{ |
59
|
|
|
$this->setDescription('Auto-magically process all Eve APIs'); |
60
|
|
|
$this->setName($name); |
61
|
|
|
$this->setDic($dic); |
62
|
|
|
parent::__construct($name); |
63
|
|
|
} |
64
|
|
|
/** |
65
|
|
|
* Configures the current command. |
66
|
|
|
*/ |
67
|
|
|
protected function configure() |
68
|
|
|
{ |
69
|
|
|
$help = <<<'EOF' |
70
|
|
|
The <info>%command.full_name%</info> command executes the main autoMagic method |
71
|
|
|
of the Yapeal class. This is meant as a replace for the now deprecated |
72
|
|
|
bin/yapeal.php script used to start Yapeal from earlier versions. |
73
|
|
|
|
74
|
|
|
<info>php %command.full_name%</info> |
75
|
|
|
|
76
|
|
|
EXAMPLES: |
77
|
|
|
Using with optional --configFile option to override matching existing settings |
78
|
|
|
from other normally processed configuration files. |
79
|
|
|
<info>%command.name% -c "path/to/my/special/config.yaml"</info> |
80
|
|
|
|
81
|
|
|
EOF; |
82
|
|
|
$this->addConfigFileOption(); |
83
|
|
|
$this->setHelp($help); |
84
|
|
|
} |
85
|
|
|
/** @noinspection PhpMissingParentCallCommonInspection */ |
86
|
|
|
/** |
87
|
|
|
* Executes the current command. |
88
|
|
|
* |
89
|
|
|
* This method is not abstract because you can use this class |
90
|
|
|
* as a concrete class. In this case, instead of defining the |
91
|
|
|
* execute() method, you set the code to execute by passing |
92
|
|
|
* a Closure to the setCode() method. |
93
|
|
|
* |
94
|
|
|
* @param InputInterface $input An InputInterface instance |
95
|
|
|
* @param OutputInterface $output An OutputInterface instance |
96
|
|
|
* |
97
|
|
|
* @return int|null null or 0 if everything went fine, or an error code |
98
|
|
|
* @throws \DomainException |
99
|
|
|
* @throws \InvalidArgumentException |
100
|
|
|
* @throws \LogicException |
101
|
|
|
* @throws \Yapeal\Exception\YapealDatabaseException |
102
|
|
|
* @throws \Yapeal\Exception\YapealException |
103
|
|
|
* |
104
|
|
|
* @see setCode() |
105
|
|
|
*/ |
106
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
107
|
|
|
{ |
108
|
|
|
/** |
109
|
|
|
* @var \Symfony\Component\Console\Output\Output $output |
110
|
|
|
*/ |
111
|
|
|
$dic = $this->getDic(); |
112
|
|
|
if ($output::VERBOSITY_QUIET !== $output->getVerbosity()) { |
113
|
|
|
$mess = sprintf('<info>Starting %1$s</info>', $this->getName()); |
114
|
|
|
$output->writeln($mess); |
115
|
|
|
} |
116
|
|
|
$options = $input->getOptions(); |
117
|
|
|
if (!empty($options['configFile'])) { |
118
|
|
|
$this->processConfigFile($options['configFile'], $dic); |
119
|
|
|
} |
120
|
|
|
return (new Yapeal($dic))->autoMagic(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|