1 | <?php |
||
10 | final class Compiler |
||
11 | { |
||
12 | /** |
||
13 | * @var string $pharFile |
||
14 | */ |
||
15 | private $pharFile; |
||
16 | |||
17 | /** |
||
18 | * @var string $baseDir |
||
19 | */ |
||
20 | private $baseDir; |
||
21 | |||
22 | /** |
||
23 | * @var \Phar $phar |
||
24 | */ |
||
25 | private $phar; |
||
26 | |||
27 | /** |
||
28 | * @var \Assimtech\Tempo\Node\Local $local |
||
29 | */ |
||
30 | private $local; |
||
31 | |||
32 | /** |
||
33 | * @param \Assimtech\Tempo\Node\Local $local |
||
34 | */ |
||
35 | public function __construct(Phar $phar, Local $local) |
||
36 | { |
||
37 | $this->phar = $phar; |
||
38 | $this->local = $local; |
||
39 | $this->baseDir = realpath(__DIR__.'/../../'); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @throws \RuntimeException |
||
44 | */ |
||
45 | public function compile() |
||
46 | { |
||
47 | $this->checkWorkingDirectory(); |
||
48 | $this->checkVersion(); |
||
49 | |||
50 | if (file_exists($this->pharFile)) { |
||
51 | unlink($this->pharFile); |
||
52 | } |
||
53 | |||
54 | $this->phar->setSignatureAlgorithm(Phar::SHA1); |
||
55 | |||
56 | $this->phar->startBuffering(); |
||
57 | |||
58 | $finder = new Finder(); |
||
59 | $finder->files() |
||
60 | ->ignoreVCS(true) |
||
61 | ->name('*.php') |
||
62 | ->notName('Compiler.php') |
||
63 | ->exclude('Test') |
||
64 | ->in('vendor/composer') |
||
65 | ->in('vendor/assimtech/sysexits') |
||
66 | ->in('vendor/symfony/console') |
||
67 | ->in('vendor/symfony/polyfill-mbstring') |
||
68 | ->in('vendor/symfony/process') |
||
69 | ->in('vendor/symfony/yaml') |
||
70 | ->in('src') |
||
71 | ; |
||
72 | foreach ($finder as $file) { |
||
73 | $this->phar->addFile($file); |
||
74 | } |
||
75 | $this->phar->addFile('vendor/autoload.php'); |
||
76 | |||
77 | // Add bin/tempo but without shebang |
||
78 | $tempoBinContents = file_get_contents($this->baseDir.'/bin/tempo'); |
||
79 | $tempoBinPhar = preg_replace('{^#!/usr/bin/env php\s*}', '', $tempoBinContents); |
||
80 | $this->phar->addFromString('bin/tempo', $tempoBinPhar); |
||
81 | |||
82 | // Stubs |
||
83 | $stub = file_get_contents(__DIR__.'/tempo.phar.stub'); |
||
84 | $this->phar->setStub($stub); |
||
85 | |||
86 | $this->phar->stopBuffering(); |
||
87 | } |
||
88 | |||
89 | private function checkWorkingDirectory() |
||
102 | |||
103 | private function checkVersion() |
||
125 | } |
||
126 |