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