1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace whm\Smoke\Cli\Command; |
4
|
|
|
|
5
|
|
|
use phmLabs\Components\Annovent\Dispatcher; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use whm\Html\Uri; |
11
|
|
|
use whm\Smoke\Config\Configuration; |
12
|
|
|
|
13
|
|
|
class WarmUpCommand extends SmokeCommand |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
protected function configure() |
19
|
|
|
{ |
20
|
|
|
$this |
21
|
|
|
->setDefinition([ |
22
|
|
|
new InputArgument('url', InputArgument::REQUIRED, 'the url to start with'), |
23
|
|
|
new InputOption('duration', 'd', InputOption::VALUE_OPTIONAL, 'duration in seconds', 60), |
24
|
|
|
new InputOption('parallel_requests', 'p', InputOption::VALUE_OPTIONAL, 'number of parallel requests.', 10), |
25
|
|
|
]) |
26
|
|
|
->setDescription('analyses a website') |
27
|
|
|
->setHelp('The <info>warmup</info> command warms a website up.') |
28
|
|
|
->setName('warmup'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
protected function execute(InputInterface $input, OutputInterface $output) |
35
|
|
|
{ |
36
|
|
|
$this->init($input, $output, $input->getArgument('url')); |
37
|
|
|
|
38
|
|
|
$this->initConfiguration( |
39
|
|
|
new Uri($input->getArgument('url')), |
|
|
|
|
40
|
|
|
$this->eventDispatcher); |
41
|
|
|
|
42
|
|
|
$timeStrategy = $this->config->getExtension('_SmokeStop')->getStrategy('_TimeStop'); |
43
|
|
|
$timeStrategy->init($input->getOption('duration')); |
44
|
|
|
|
45
|
|
|
return $this->scan(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Initializes the configuration. |
50
|
|
|
* |
51
|
|
|
* @param $configFile |
52
|
|
|
* @param $loadForeign |
53
|
|
|
* @param Uri $uri |
54
|
|
|
* |
55
|
|
|
* @return Configuration |
56
|
|
|
*/ |
57
|
|
|
private function initConfiguration(Uri $uri, Dispatcher $dispatcher) |
58
|
|
|
{ |
59
|
|
|
$configArray = $this->getConfigArray(__DIR__ . '/../../settings/warmup.yml'); |
60
|
|
|
|
61
|
|
|
$config = new Configuration($uri, $dispatcher, $configArray); |
62
|
|
|
|
63
|
|
|
$crawler = $config->getExtension('_ResponseRetriever')->getRetriever(); |
64
|
|
|
$crawler->setStartPage($uri); |
65
|
|
|
|
66
|
|
|
$this->config = $config; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.