1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the hogosha-monitor package |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Guillaume Cavana |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* Feel free to edit as you please, and have fun. |
12
|
|
|
* |
13
|
|
|
* @author Guillaume Cavana <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Hogosha\Monitor\Console; |
17
|
|
|
|
18
|
|
|
use Hogosha\Monitor\Configuration\ConfigurationDumper; |
19
|
|
|
use Hogosha\Monitor\Configuration\ConfigurationLoader; |
20
|
|
|
use Hogosha\Monitor\Console\Handler\InitHandler; |
21
|
|
|
use Hogosha\Monitor\Console\Handler\RunHandler; |
22
|
|
|
use Hogosha\Monitor\Monitor; |
23
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
24
|
|
|
use Webmozart\Console\Api\Args\Format\Option; |
25
|
|
|
use Webmozart\Console\Config\DefaultApplicationConfig; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @author Guillaume Cavana <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class MonitorApplicationConfig extends DefaultApplicationConfig |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected function configure() |
36
|
|
|
{ |
37
|
|
|
parent::configure(); |
38
|
|
|
|
39
|
|
|
$configurationLoader = new ConfigurationLoader(); |
40
|
|
|
$configurationDumper = new ConfigurationDumper(); |
41
|
|
|
|
42
|
|
|
$filesystem = new Filesystem(); |
43
|
|
|
|
44
|
|
|
$signature = <<<SIGNATURE |
45
|
|
|
_ _ ___ ____ ___ ____ _ _ _ |
46
|
|
|
| | | | / _ \ / ___| / _ \ / ___| | | | | / \ |
47
|
|
|
| |_| || | | || | _ | | | |\___ \ | |_| | / _ \ |
48
|
|
|
| _ || |_| || |_| || |_| | ___) || _ | / ___ \ |
49
|
|
|
|_| |_| \___/ \____| \___/ |____/ |_| |_|/_/ \_\ |
50
|
|
|
|
51
|
|
|
SIGNATURE; |
52
|
|
|
|
53
|
|
|
$this |
|
|
|
|
54
|
|
|
->setDisplayName($signature."\n".'Hogosha Monitoring Tool') |
55
|
|
|
->setName('monitor') |
56
|
|
|
->setVersion(Monitor::VERSION) |
57
|
|
|
->addOption('config', 'c', Option::OPTIONAL_VALUE, 'Config file path', rtrim(getcwd(), DIRECTORY_SEPARATOR)) |
58
|
|
|
->beginCommand('init') |
59
|
|
|
->setDescription('Create a default configuration file if you do not have one') |
60
|
|
|
->setHandler(function () use ($configurationLoader, $configurationDumper, $filesystem) { |
61
|
|
|
return new InitHandler($configurationLoader, $configurationDumper, $filesystem); |
62
|
|
|
}) |
63
|
|
|
->setHelp('php <info>bin/monitor</info> init') |
64
|
|
|
->addOption('force', 'f', Option::OPTIONAL_VALUE, 'Overwrite the config file') |
65
|
|
|
->end() |
66
|
|
|
->beginCommand('run') |
67
|
|
|
->setDescription('Launch the monitor process') |
68
|
|
|
->setHandler(function () use ($configurationLoader) { |
69
|
|
|
return new RunHandler($configurationLoader); |
70
|
|
|
}) |
71
|
|
|
->setHelp('php <info>bin/monitor</info> run') |
72
|
|
|
->addOption('format', 'f', Option::OPTIONAL_VALUE, 'The formatter', 'list') |
73
|
|
|
->end() |
74
|
|
|
; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: