Example #1
0
 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     if (!empty($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         if (!empty($this->cliStubFile)) {
             $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $cliStubFile = null;
         }
         if (!empty($this->webStubFile)) {
             $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $webStubFile = null;
         }
         $phar->setDefaultStub($cliStubFile, $webStubFile);
     }
     if ($this->metadata === null) {
         $this->createMetaData();
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     if ($this->signatureAlgorithm == Phar::OPENSSL) {
         // Load up the contents of the key
         $keyContents = file_get_contents($this->key);
         // Attempt to load the given key as a PKCS#12 Cert Store first.
         if (openssl_pkcs12_read($keyContents, $certs, $this->keyPassword)) {
             $private = openssl_pkey_get_private($certs['pkey']);
         } else {
             // Fall back to a regular PEM-encoded private key.
             // Setup an OpenSSL resource using the private key
             // and tell the Phar to sign it using that key.
             $private = openssl_pkey_get_private($keyContents, $this->keyPassword);
         }
         $phar->setSignatureAlgorithm(Phar::OPENSSL, $private);
         // Get the details so we can get the public key and write that out
         // alongside the phar.
         $details = openssl_pkey_get_details($private);
         file_put_contents($this->destinationFile . '.pubkey', $details['key']);
     } else {
         $phar->setSignatureAlgorithm($this->signatureAlgorithm);
     }
     if (!empty($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         if (!empty($this->cliStubFile)) {
             $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $cliStubFile = null;
         }
         if (!empty($this->webStubFile)) {
             $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $webStubFile = null;
         }
         $phar->setDefaultStub($cliStubFile, $webStubFile);
     }
     if ($this->metadata === null) {
         $this->createMetaData();
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     $phar->setSignatureAlgorithm($this->signatureAlgorithm);
     if (isset($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         $phar->setDefaultStub($this->cliStubFile->getPathWithoutBase($this->baseDirectory), $this->webStubFile->getPathWithoutBase($this->baseDirectory));
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
Example #4
0
 /**
  * Build and configure Phar object.
  *
  * @return Phar
  */
 private function buildPhar()
 {
     $phar = new Phar($this->destinationFile);
     if ($this->signatureAlgorithm == Phar::OPENSSL) {
         // Load up the contents of the key
         $keyContents = file_get_contents($this->key);
         // Setup an OpenSSL resource using the private key and tell the Phar
         // to sign it using that key.
         $private = openssl_pkey_get_private($keyContents, $this->keyPassword);
         $phar->setSignatureAlgorithm(Phar::OPENSSL, $private);
         // Get the details so we can get the public key and write that out
         // alongside the phar.
         $details = openssl_pkey_get_details($private);
         file_put_contents($this->destinationFile . '.pubkey', $details['key']);
     } else {
         $phar->setSignatureAlgorithm($this->signatureAlgorithm);
     }
     if (isset($this->stubPath)) {
         $phar->setStub(file_get_contents($this->stubPath));
     } else {
         if (!empty($this->cliStubFile)) {
             $cliStubFile = $this->cliStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $cliStubFile = null;
         }
         if (!empty($this->webStubFile)) {
             $webStubFile = $this->webStubFile->getPathWithoutBase($this->baseDirectory);
         } else {
             $webStubFile = null;
         }
         $phar->setDefaultStub($cliStubFile, $webStubFile);
     }
     if ($metadata = $this->metadata->toArray()) {
         $phar->setMetadata($metadata);
     }
     if (!empty($this->alias)) {
         $phar->setAlias($this->alias);
     }
     return $phar;
 }
Example #5
0
 /**
  * do the work
  *
  * @throws BuildException
  */
 public function main()
 {
     if ($this->jpaFile === null) {
         throw new BuildException("jpafile attribute must be set!", $this->getLocation());
     }
     if ($this->jpaFile->exists() && $this->jpaFile->isDirectory()) {
         throw new BuildException("jpafile is a directory!", $this->getLocation());
     }
     if ($this->jpaFile->exists() && !$this->jpaFile->canWrite()) {
         throw new BuildException("Can not write to the specified jpafile!", $this->getLocation());
     }
     // shouldn't need to clone, since the entries in filesets
     // themselves won't be modified -- only elements will be added
     $savedFileSets = $this->filesets;
     try {
         if (empty($this->filesets)) {
             throw new BuildException("You must supply some nested filesets.", $this->getLocation());
         }
         $this->log("Building JPA: " . $this->jpaFile->__toString(), Project::MSG_INFO);
         $jpa = new JPAMaker();
         $res = $jpa->create($this->jpaFile->getAbsolutePath());
         if ($res !== true) {
             throw new Exception("JPAMaker::open() failed: " . $jpa->error);
         }
         foreach ($this->filesets as $fs) {
             $files = $fs->getFiles($this->project, $this->includeEmpty);
             $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project);
             $filesToZip = array();
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 $f = new PhingFile($fsBasedir, $files[$i]);
                 $pathInJPA = $this->prefix . $f->getPathWithoutBase($fsBasedir);
                 $jpa->addFile($f->getPath(), $pathInJPA);
                 $this->log("Adding " . $f->getPath() . " as " . $pathInJPA . " to archive.", Project::MSG_VERBOSE);
             }
         }
         $jpa->finalize();
     } catch (IOException $ioe) {
         $msg = "Problem creating JPA: " . $ioe->getMessage();
         $this->filesets = $savedFileSets;
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
     $this->filesets = $savedFileSets;
 }
Example #6
0
 /**
  * @param $zip
  */
 private function addFilesetsToArchive($zip)
 {
     foreach ($this->filesets as $fs) {
         $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project);
         $files = $fs->getFiles($this->project, $this->includeEmpty);
         for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
             $f = new PhingFile($fsBasedir, $files[$i]);
             $pathInZip = $this->prefix . $f->getPathWithoutBase($fsBasedir);
             $pathInZip = str_replace('\\', '/', $pathInZip);
             if ($this->ignoreLinks && $f->isLink()) {
                 continue;
             } elseif ($f->isDirectory()) {
                 if ($pathInZip != '.') {
                     $zip->addEmptyDir($pathInZip);
                 }
             } else {
                 $zip->addFile($f->getAbsolutePath(), $pathInZip);
             }
             $this->log("Adding " . $f->getPath() . " as " . $pathInZip . " to archive.", Project::MSG_VERBOSE);
         }
     }
 }
 /**
  * do the work
  * @throws BuildException
  */
 public function main()
 {
     if (!extension_loaded('zip')) {
         throw new BuildException("Zip extension is required");
     }
     if ($this->zipFile === null) {
         throw new BuildException("zipfile attribute must be set!", $this->getLocation());
     }
     if ($this->zipFile->exists() && $this->zipFile->isDirectory()) {
         throw new BuildException("zipfile is a directory!", $this->getLocation());
     }
     if ($this->zipFile->exists() && !$this->zipFile->canWrite()) {
         throw new BuildException("Can not write to the specified zipfile!", $this->getLocation());
     }
     // shouldn't need to clone, since the entries in filesets
     // themselves won't be modified -- only elements will be added
     $savedFileSets = $this->filesets;
     try {
         if ($this->baseDir !== null) {
             if (!$this->baseDir->exists()) {
                 throw new BuildException("basedir '" . (string) $this->baseDir . "' does not exist!", $this->getLocation());
             }
             if (empty($this->filesets)) {
                 // add the main fileset to the list of filesets to process.
                 $mainFileSet = new ZipFileSet($this->fileset);
                 $mainFileSet->setDir($this->baseDir);
                 $this->filesets[] = $mainFileSet;
             }
         }
         if (empty($this->filesets)) {
             throw new BuildException("You must supply either a basedir " . "attribute or some nested filesets.", $this->getLocation());
         }
         // check if zip is out of date with respect to each
         // fileset
         $upToDate = true;
         foreach ($this->filesets as $fs) {
             $files = $fs->getFiles($this->project, $this->includeEmpty);
             if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) {
                 $upToDate = false;
             }
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) {
                     throw new BuildException("A zip file cannot include itself", $this->getLocation());
                 }
             }
         }
         if ($upToDate) {
             $this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", Project::MSG_INFO);
             return;
         }
         $this->log("Building zip: " . $this->zipFile->__toString(), Project::MSG_INFO);
         $zip = new ZipArchive();
         $res = $zip->open($this->zipFile->getAbsolutePath(), ZIPARCHIVE::CREATE);
         if ($res !== true) {
             throw new Exception("ZipArchive::open() failed with code " . $res);
         }
         foreach ($this->filesets as $fs) {
             $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project);
             $files = $fs->getFiles($this->project, $this->includeEmpty);
             $filesToZip = array();
             for ($i = 0, $fcount = count($files); $i < $fcount; $i++) {
                 $f = new PhingFile($fsBasedir, $files[$i]);
                 $pathInZip = $this->prefix . $f->getPathWithoutBase($fsBasedir);
                 $pathInZip = str_replace('\\', '/', $pathInZip);
                 if ($f->isDirectory()) {
                     if ($pathInZip != '.') {
                         $zip->addEmptyDir($pathInZip);
                     }
                 } else {
                     $zip->addFile($f->getPath(), $pathInZip);
                 }
                 $this->log("Adding " . $f->getPath() . " as " . $pathInZip . " to archive.", Project::MSG_VERBOSE);
             }
         }
         $zip->close();
     } catch (IOException $ioe) {
         $msg = "Problem creating ZIP: " . $ioe->getMessage();
         $this->filesets = $savedFileSets;
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
     $this->filesets = $savedFileSets;
 }