Skip to content

Commit 15c7b1f

Browse files
committed
Ignores non-project files when building PHAR.
1 parent 7a95a0e commit 15c7b1f

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

tools/build.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
#!/usr/bin/env php
22
<?php
33

4+
class NonProjectFilesFilter extends RecursiveFilterIterator {
5+
public function accept() {
6+
if ($this->hasChildren()) {
7+
return true;
8+
} else {
9+
/** @var SplFileInfo $current */
10+
$current = $this->current();
11+
$realpath = substr($current->getRealPath(), strlen(dirname(__FILE__) . DIRECTORY_SEPARATOR));
12+
$extension = $current->getExtension();
13+
$valid_prefixes = ["src/", "vendor/composer/", "vendor/league/", "vendor/phpseclib/", "vendor/seld/"];
14+
15+
if ($realpath == "vendor/autoload.php") {
16+
return true;
17+
}
18+
19+
foreach ($valid_prefixes as $prefix) {
20+
if (substr($realpath, 0, strlen($prefix)) == $prefix && $extension == "php") {
21+
return true;
22+
}
23+
}
24+
25+
return false;
26+
}
27+
}
28+
}
29+
430
if (ini_get("phar.readonly")) {
5-
echo "You need to set the 'phar.readonly' option to 'Off' in your php.ini file (" . php_ini_loaded_file() . ")".PHP_EOL;
31+
echo "You need to set the 'phar.readonly' option to 'Off' in your php.ini file (" . php_ini_loaded_file() . ")" . PHP_EOL;
632
} else {
733
$phar = new Phar('git-deploy.phar', 0, 'git-deploy');
8-
$phar->buildFromDirectory(dirname(__FILE__));
34+
$iterator = new NonProjectFilesFilter(new RecursiveDirectoryIterator(dirname(__FILE__), FilesystemIterator::SKIP_DOTS));
35+
$d = $phar->buildFromIterator(new RecursiveIteratorIterator($iterator), dirname(__FILE__));
936
$phar->setStub(file_get_contents(dirname(__FILE__) . "/index.php"));
1037
unset($phar);
1138
@unlink('../git-deploy');
1239
rename('git-deploy.phar', '../git-deploy');
13-
echo "Built git-deploy successfully!".PHP_EOL;
40+
chmod('../git-deploy', 0755);
41+
echo "Built git-deploy successfully!" . PHP_EOL;
1442
}

0 commit comments

Comments
 (0)