|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Dumper |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/mtymek/class-dumper |
|
6
|
|
|
* @copyright Copyright (c) 2015 Mateusz Tymek |
|
7
|
|
|
* @license BSD 2-Clause |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace ClassDumper; |
|
11
|
|
|
|
|
12
|
|
|
use ClassDumper\Exception\RuntimeException; |
|
13
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
|
14
|
|
|
use Zend\Console\Console; |
|
15
|
|
|
use ZF\Console\Application; |
|
16
|
|
|
use ZF\Console\Route; |
|
17
|
|
|
|
|
18
|
|
|
class DumperApp extends Application |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
|
|
$routes = [[ |
|
23
|
|
|
'name' => '<config> <output_file> [--strip]', |
|
24
|
|
|
'short_description' => "Generate class cache based on <config> file into <output_file>.", |
|
25
|
|
|
'handler' => [$this, 'generateDump'], |
|
26
|
|
|
]]; |
|
27
|
|
|
parent::__construct('Cache dumper', 1.0, $routes, Console::getInstance()); |
|
28
|
|
|
$this->removeRoute('autocomplete'); |
|
29
|
|
|
$this->removeRoute('help'); |
|
30
|
|
|
$this->removeRoute('version'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function generateDump(Route $route, AdapterInterface $console) |
|
34
|
|
|
{ |
|
35
|
|
|
$configFile = $route->getMatchedParam('config'); |
|
36
|
|
|
$outputFile = $route->getMatchedParam('output_file'); |
|
37
|
|
|
$strip = (bool)$route->getMatchedParam('strip'); |
|
38
|
|
|
|
|
39
|
|
|
$console->writeLine("Generating class cache from $configFile into $outputFile"); |
|
40
|
|
|
|
|
41
|
|
|
if (!file_exists($configFile)) { |
|
42
|
|
|
throw new RuntimeException("Configuration file does not exist: $configFile"); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$classes = include $configFile; |
|
46
|
|
|
|
|
47
|
|
|
if (!is_array($classes)) { |
|
48
|
|
|
throw new RuntimeException("Configuration file does not contain array of class names"); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (!file_exists(dirname($outputFile))) { |
|
52
|
|
|
mkdir(dirname($outputFile), 0777, true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$dumper = new ClassDumper(); |
|
56
|
|
|
$cache = $dumper->dump($classes, $strip); |
|
57
|
|
|
|
|
58
|
|
|
file_put_contents($outputFile, "<?php\n" . $cache); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|