3 namespace pharext\Task
;
15 class PharBuild
implements Task
18 * @var \pharext\SourceDir
38 * @param SourceDir $source extension source directory
39 * @param string $stub path to phar stub
40 * @param array $meta phar meta data
41 * @param bool $readonly whether the stub has -dphar.readonly=1 set
43 public function __construct(SourceDir
$source = null, $stub, array $meta = null, $readonly = true) {
44 $this->source
= $source;
47 $this->readonly
= $readonly;
51 * @param bool $verbose
52 * @return \pharext\Tempname
53 * @throws \pharext\Exception
55 public function run($verbose = false) {
56 /* Phar::compress() and ::convert*() use strtok("."), ugh!
57 * so, be sure to not use any other dots in the filename
60 $temp = new Tempname("", "-pharext.phar");
62 $phar = new Phar($temp);
63 $phar->startBuffering();
66 $phar->setMetadata($this->meta
);
69 (new PharStub($phar, $this->stub
))->run($verbose);
72 $phar->buildFromIterator((new Task\BundleGenerator
)->run());
76 $bdir = $this->source
->getBaseDir();
77 $blen = strlen($bdir);
78 foreach ($this->source
as $index => $file) {
79 if (is_resource($file)) {
80 printf("Packaging %s ...\n", $index);
81 $phar[$index] = $file;
83 printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/"));
84 $phar->addFile($file, $index);
88 $phar->buildFromIterator($this->source
, $this->source
->getBaseDir());
92 $phar->stopBuffering();
94 if (!chmod($temp, fileperms($temp) |
0111)) {