Skip to content

Commit 72ff668

Browse files
committed
PHAR generating task added
1 parent 6b31083 commit 72ff668

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
/vendor
2-
/tasks

tasks/generate_phar.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
define('BASEDIR', dirname(dirname(__FILE__)));
4+
define('BUILDDIR', BASEDIR . DIRECTORY_SEPARATOR . 'tasks');
5+
6+
$exclude = [
7+
'build',
8+
'.gitignore',
9+
'composer.json',
10+
'composer.lock',
11+
'composer.phar',
12+
'README.md',
13+
'.git',
14+
'.idea',
15+
'tasks'
16+
];
17+
18+
$filter = function ($file, $key, $iterator) use ($exclude) {
19+
if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) {
20+
return true;
21+
}
22+
return $file->isFile() && !in_array($file->getFilename(), $exclude);
23+
};
24+
25+
$innerIterator = new RecursiveDirectoryIterator(BASEDIR, RecursiveDirectoryIterator::SKIP_DOTS);
26+
27+
$iterator = new RecursiveIteratorIterator(new RecursiveCallbackFilterIterator($innerIterator, $filter));
28+
29+
$phar = new \Phar('phpandroid.phar', 0, 'phpandroid.phar');
30+
$phar->setSignatureAlgorithm(\Phar::SHA1);
31+
$phar->startBuffering();
32+
$phar->buildFromIterator($iterator, BASEDIR);
33+
$phar->setStub(file_get_contents(BUILDDIR . DIRECTORY_SEPARATOR . 'stub.php'));
34+
$phar->stopBuffering();

tasks/stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
Phar::mapPhar();
5+
require_once "phar://phpandroid.phar/index.php";
6+
__HALT_COMPILER();

0 commit comments

Comments
 (0)