Example #1
0
 /**
  * @param bool $verbose
  * @return \pharext\Tempname
  * @throws \pharext\Exception
  */
 public function run($verbose = false)
 {
     /* Phar::compress() and ::convert*() use strtok("."), ugh!
      * so, be sure to not use any other dots in the filename
      * except for .phar
      */
     $temp = new Tempname("", "-pharext.phar");
     $phar = new Phar($temp);
     $phar->startBuffering();
     if ($this->meta) {
         $phar->setMetadata($this->meta);
     }
     if ($this->stub) {
         (new PharStub($phar, $this->stub))->run($verbose);
     }
     $phar->buildFromIterator((new Task\BundleGenerator())->run());
     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);
                     $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();
     }
     return $temp;
 }