|
5 | 5 | * For the full copyright and license information, please view the LICENSE |
6 | 6 | * file that was distributed with this source code. |
7 | 7 | */ |
8 | | -if (ini_get('phar.readonly') === '1') { |
9 | | - throw new \Exception('Writing to phar files is disabled. Change your `php.ini` or append `-d phar.readonly=false` to the shebang, if supported by your `env` executable.'); |
10 | | -} |
11 | 8 |
|
12 | | -define('__ROOT__', realpath(__DIR__ . '/..')); |
13 | | -chdir(__ROOT__); |
14 | | - |
15 | | -$opt = getopt('v:', ['nozip']); |
16 | | - |
17 | | -$version = $opt['v'] ?? null; |
18 | | -if (empty($version)) { |
19 | | - echo "Please, specify version as \"-v8.0.0\".\n"; |
20 | | - exit(1); |
21 | | -} |
22 | | -if (!preg_match('/^\d+\.\d+\.\d+(\-\w+(\.\d+)?)?$/', $version)) { |
23 | | - echo "Version must be \"7.0.0-beta.42\". Got \"$version\".\n"; |
24 | | - exit(1); |
25 | | -} |
26 | | - |
27 | | -$pharName = "deployer.phar"; |
28 | | -$pharFile = __ROOT__ . '/' . $pharName; |
29 | | -if (file_exists($pharFile)) { |
30 | | - unlink($pharFile); |
31 | | -} |
32 | | - |
33 | | -$ignore = [ |
34 | | - '.anton', |
35 | | - '.git', |
36 | | - 'Tests', |
37 | | - 'tests', |
38 | | - 'deploy.php', |
39 | | - '.php-cs-fixer.dist.php', |
40 | | -]; |
41 | | - |
42 | | -$phar = new \Phar($pharFile, 0, $pharName); |
43 | | -$phar->setSignatureAlgorithm(\Phar::SHA1); |
44 | | -$phar->startBuffering(); |
45 | | -$iterator = new RecursiveDirectoryIterator(__ROOT__, FilesystemIterator::SKIP_DOTS); |
46 | | -$iterator = new RecursiveCallbackFilterIterator($iterator, function (SplFileInfo $fileInfo) use ($ignore) { |
47 | | - return !in_array($fileInfo->getBasename(), $ignore, true); |
48 | | -}); |
49 | | -$iterator = new RecursiveIteratorIterator($iterator); |
50 | | -$iterator = new CallbackFilterIterator($iterator, function (SplFileInfo $fileInfo) { |
51 | | - //'bash', 'fish', 'zsh' is a completion templates |
52 | | - return in_array($fileInfo->getExtension(), ['php', 'exe', 'bash', 'fish', 'zsh'], true); |
53 | | -}); |
54 | | - |
55 | | -foreach ($iterator as $fileInfo) { |
56 | | - $file = str_replace(__ROOT__, '', $fileInfo->getRealPath()); |
57 | | - echo "+ " . $file . "\n"; |
58 | | - $phar->addFile($fileInfo->getRealPath(), $file); |
59 | | - |
60 | | - if (!array_key_exists('nozip', $opt)) { |
61 | | - $phar[$file]->compress(Phar::GZ); |
62 | | - |
63 | | - if (!$phar[$file]->isCompressed()) { |
64 | | - echo "Could not compress File: $file\n"; |
65 | | - } |
66 | | - } |
67 | | -} |
68 | | - |
69 | | -// Add schema.json |
70 | | -echo "+ /src/schema.json\n"; |
71 | | -$phar->addFile(realpath(__DIR__ . '/../src/schema.json'), '/src/schema.json'); |
72 | | - |
73 | | -// Add Caddyfile |
74 | | -echo "+ /recipe/provision/Caddyfile\n"; |
75 | | -$phar->addFile(realpath(__DIR__ . '/../recipe/provision/Caddyfile'), '/recipe/provision/Caddyfile'); |
76 | | - |
77 | | -// Add 404.html |
78 | | -echo "+ /recipe/provision/404.html\n"; |
79 | | -$phar->addFile(realpath(__DIR__ . '/../recipe/provision/404.html'), '/recipe/provision/404.html'); |
80 | | - |
81 | | -// Add bin/dep file |
82 | | -echo "+ /bin/dep\n"; |
83 | | -$depContent = file_get_contents(__ROOT__ . '/bin/dep'); |
84 | | -$depContent = str_replace("#!/usr/bin/env php\n", '', $depContent); |
85 | | -$depContent = str_replace('__FILE__', 'str_replace("phar://", "", Phar::running())', $depContent); |
86 | | -$depContent = preg_replace("/run\('.+?'/", "run('$version'", $depContent); |
87 | | -$phar->addFromString('bin/dep', $depContent); |
88 | | - |
89 | | -$phar->setStub( |
90 | | - <<<STUB |
91 | | -#!/usr/bin/env php |
92 | | -<?php |
93 | | -Phar::mapPhar('{$pharName}'); |
94 | | -require 'phar://{$pharName}/bin/dep'; |
95 | | -__HALT_COMPILER(); |
96 | | -STUB |
97 | | -); |
98 | | -$phar->stopBuffering(); |
99 | | -unset($phar); |
100 | | - |
101 | | -echo "$pharName was created successfully.\n"; |
| 9 | +echo "Do nothing.\n"; |
0 commit comments