X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FTask%2FPharBuild.php;h=181b8eff3a4a345cd0bed0e8d96809f5a60237d8;hb=686017f7a73f9dc9eba2c446db772824e843333b;hp=bc79f79e61e018e1b194f2d0bf7d81652b6e37a7;hpb=1865a2712e004efb244cdbb241a8b7694bcdbfd7;p=pharext%2Fpharext diff --git a/src/pharext/Task/PharBuild.php b/src/pharext/Task/PharBuild.php index bc79f79..181b8ef 100644 --- a/src/pharext/Task/PharBuild.php +++ b/src/pharext/Task/PharBuild.php @@ -19,6 +19,11 @@ class PharBuild implements Task */ private $source; + /** + * @var string + */ + private $stub; + /** * @var array */ @@ -31,11 +36,13 @@ class PharBuild implements Task /** * @param SourceDir $source extension source directory + * @param string $stub path to phar stub * @param array $meta phar meta data * @param bool $readonly whether the stub has -dphar.readonly=1 set */ - public function __construct(SourceDir $source = null, array $meta = null, $readonly = true) { + public function __construct(SourceDir $source = null, $stub, array $meta = null, $readonly = true) { $this->source = $source; + $this->stub = $stub; $this->meta = $meta; $this->readonly = $readonly; } @@ -57,39 +64,38 @@ class PharBuild implements Task if ($this->meta) { $phar->setMetadata($this->meta); - if (isset($this->meta["stub"])) { - $phar->setDefaultStub($this->meta["stub"]); - $phar->setStub("#!/usr/bin/php -dphar.readonly=" . - intval($this->readonly) ."\n". - $phar->getStub()); - } + } + if ($this->stub) { + (new PharStub($phar, $this->stub))->run($verbose); } - $phar->buildFromIterator((new Task\BundleGenerator)->run()); + $phar->buildFromIterator((new Task\BundleGenerator)->run($verbose)); if ($this->source) { - if ($verbose) { - $bdir = $this->source->getBaseDir(); - $blen = strlen($bdir); - foreach ($this->source as $index => $file) { - if (is_resource($file)) { - printf("Packaging %s ...\n", $index); - } else { - printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/")); - } + $bdir = $this->source->getBaseDir(); + $blen = strlen($bdir); + foreach ($this->source as $index => $file) { + if (is_resource($file)) { + $mode = fstat($file)["mode"] & 07777; $phar[$index] = $file; + } else { + $mode = stat($file)["mode"] & 07777; + $index = trim(substr($file, $blen), "/"); + $phar->addFile($file, $index); + } + if ($verbose) { + printf("Packaging %04o %s ...\n", $mode, $index); } - } else { - $phar->buildFromIterator($this->source, $this->source->getBaseDir()); + $phar[$index]->chmod($mode); } } $phar->stopBuffering(); - + if (!chmod($temp, fileperms($temp) | 0111)) { throw new Exception; } - + return $temp; } -} \ No newline at end of file +}