*/
private $source;
+ /**
+ * @var string
+ */
+ private $stub;
+
/**
* @var array
*/
/**
* @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;
}
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 (is_file($this->stub)) {
+ $stub = preg_replace_callback('/^#include <([^>]+)>/m', function($includes) {
+ return file_get_contents($includes[1], true, null, 5);
+ }, file_get_contents($this->stub));
+ $phar->setStub($stub);
}
$phar->buildFromIterator((new Task\BundleGenerator)->run());
if ($this->source) {
- $phar->buildFromIterator($this->source, $this->source->getBaseDir());
+ if ($verbose) {
+ $bdir = $this->source->getBaseDir();
+ $blen = strlen($bdir);
+ foreach ($this->source as $index => $file) {
+ if (is_resource($file)) {
+ printf("Packaging %s ...\n", $index);
+ $phar[$index] = $file;
+ } else {
+ printf("Packaging %s ...\n", $index = trim(substr($file, $blen), "/"));
+ $phar->addFile($file, $index);
+ }
+ }
+ } else {
+ $phar->buildFromIterator($this->source, $this->source->getBaseDir());
+ }
}
$phar->stopBuffering();
-
+
if (!chmod($temp, fileperms($temp) | 0111)) {
throw new Exception;
}