1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of CacheTool. |
5
|
|
|
* |
6
|
|
|
* (c) Samuel Gordalina <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace CacheTool\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Helper\Table; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
class OpcacheCompileScriptCommand extends AbstractCommand |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
|
|
->setName('opcache:compile:script') |
28
|
|
|
->setDescription('Compile a given script to the opcode cache') |
29
|
|
|
->addArgument('path', InputArgument::REQUIRED) |
30
|
|
|
->setHelp(''); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$this->ensureExtensionLoaded('Zend OPcache'); |
39
|
|
|
$path = $input->getArgument('path'); |
40
|
|
|
|
41
|
|
|
$info = $this->getCacheTool()->opcache_get_status(true); |
42
|
|
|
|
43
|
|
|
if ($info === false) { |
44
|
|
|
throw new \RuntimeException('opcache_get_status(): No Opcache status info available. Perhaps Opcache is disabled via opcache.enable or opcache.enable_cli?'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$splFiles = array($path); |
48
|
|
|
|
49
|
|
|
$table = new Table($output); |
50
|
|
|
$table |
51
|
|
|
->setHeaders(array( |
52
|
|
|
'Compiled', |
53
|
|
|
'Filename' |
54
|
|
|
)) |
55
|
|
|
->setRows($this->processFilelist($splFiles)) |
56
|
|
|
; |
57
|
|
|
|
58
|
|
|
$table->render(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function processFileList($splFiles) |
62
|
|
|
{ |
63
|
|
|
$list = array(); |
64
|
|
|
|
65
|
|
|
foreach ($splFiles as $file) { |
66
|
|
|
$list[] = array( |
67
|
|
|
$this->getCacheTool()->opcache_compile_file(realpath($file)), |
68
|
|
|
realpath($file) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $list; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|