181b8eff3a4a345cd0bed0e8d96809f5a60237d8
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($verbose));
75 $bdir = $this->source
->getBaseDir();
76 $blen = strlen($bdir);
77 foreach ($this->source
as $index => $file) {
78 if (is_resource($file)) {
79 $mode = fstat($file)["mode"] & 07777;
80 $phar[$index] = $file;
82 $mode = stat($file)["mode"] & 07777;
83 $index = trim(substr($file, $blen), "/");
84 $phar->addFile($file, $index);
87 printf("Packaging %04o %s ...\n", $mode, $index);
89 $phar[$index]->chmod($mode);
93 $phar->stopBuffering();
95 if (!chmod($temp, fileperms($temp) |
0111)) {