03ac42c1019b5d6505eebd0f80b7ef07f9d92206
3 namespace pharext\Task
;
15 class PharBuild
implements Task
18 * @var \pharext\SourceDir
33 * @param SourceDir $source extension source directory
34 * @param array $meta phar meta data
35 * @param bool $readonly whether the stub has -dphar.readonly=1 set
37 public function __construct(SourceDir
$source = null, array $meta = null, $readonly = true) {
38 $this->source
= $source;
40 $this->readonly
= $readonly;
44 * @param bool $verbose
45 * @return \pharext\Tempname
46 * @throws \pharext\Exception
48 public function run($verbose = false) {
49 /* Phar::compress() and ::convert*() use strtok("."), ugh!
50 * so, be sure to not use any other dots in the filename
53 $temp = new Tempname("", "-pharext.phar");
55 $phar = new Phar($temp);
56 $phar->startBuffering();
59 $phar->setMetadata($this->meta
);
60 if (isset($this->meta
["stub"])) {
61 $phar->setDefaultStub($this->meta
["stub"]);
62 $phar->setStub("#!/usr/bin/php -dphar.readonly=" .
63 intval($this->readonly
) ."\n".
68 $phar->buildFromIterator((new Task\BundleGenerator
)->run());
72 $bdir = $this->source
->getBaseDir();
73 $blen = strlen($bdir);
74 foreach ($this->source
as $index => $file) {
75 if (is_resource($file)) {
76 printf("Packaging %s ...\n", $index);
77 $phar[$index] = $file;
79 printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/"));
80 $phar->addFile($file, $index);
84 $phar->buildFromIterator($this->source
, $this->source
->getBaseDir());
88 $phar->stopBuffering();
90 if (!chmod($temp, fileperms($temp) |
0111)) {