1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegryd\OpcacheResetBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
9
|
|
|
use GuzzleHttp\Client as HttpClient; |
10
|
|
|
use Timegryd\OpcacheResetBundle\Helper\OpcacheResetCommandHelper; |
11
|
|
|
|
12
|
|
|
class OpcacheResetCommand extends ContainerAwareCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $defaultHost; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $defaultDir; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var OpcacheResetCommandHelper |
26
|
|
|
*/ |
27
|
|
|
protected $helper; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var HttpClient |
31
|
|
|
*/ |
32
|
|
|
protected $httpClient; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $defaultHost |
36
|
|
|
* @param string $defaultDir |
37
|
|
|
*/ |
38
|
|
|
public function __construct($defaultHost, $defaultDir, OpcacheResetCommandHelper $opcacheResetCommandHelper, HttpClient $httpClient) |
39
|
|
|
{ |
40
|
|
|
$this->defaultHost = $defaultHost; |
41
|
|
|
$this->defaultDir = $defaultDir; |
42
|
|
|
$this->helper = $opcacheResetCommandHelper; |
43
|
|
|
$this->httpClient = $httpClient; |
44
|
|
|
|
45
|
|
|
parent::__construct(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function configure() |
49
|
|
|
{ |
50
|
|
|
$this |
51
|
|
|
->setName('opcache:reset') |
52
|
|
|
->setDescription('Reset opcache') |
53
|
|
|
->addArgument('host', InputArgument::OPTIONAL, 'Base url to call', $this->defaultHost) |
54
|
|
|
->addArgument('dir', InputArgument::OPTIONAL, 'Web dir where to create file to call', $this->defaultDir) |
55
|
|
|
; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
59
|
|
|
{ |
60
|
|
|
$output->writeln(['Opcache reset begin', '==================='], OutputInterface::VERBOSITY_VERBOSE); |
61
|
|
|
|
62
|
|
|
$token = sha1(uniqid()); |
63
|
|
|
|
64
|
|
|
$this->helper->createFile($input->getArgument('dir'), $token); |
65
|
|
|
$output->writeln('File created', OutputInterface::VERBOSITY_VERBOSE); |
66
|
|
|
|
67
|
|
|
$url = $this->helper->generateUrl($input->getArgument('host'), $token); |
68
|
|
|
|
69
|
|
|
$response = $this->httpClient->request('GET', $url); |
70
|
|
|
|
71
|
|
|
$this->helper->clean($input->getArgument('dir')); |
72
|
|
|
$output->writeln('File deleted', OutputInterface::VERBOSITY_VERBOSE); |
73
|
|
|
|
74
|
|
|
$output->writeln($this->helper->handleResponse($response), OutputInterface::VERBOSITY_VERBOSE); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.