本文整理汇总了PHP中PhingFile::__toString方法的典型用法代码示例。如果您正苦于以下问题:PHP PhingFile::__toString方法的具体用法?PHP PhingFile::__toString怎么用?PHP PhingFile::__toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhingFile
的用法示例。
在下文中一共展示了PhingFile::__toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Construct a new FileInputStream.
*
* @param PhingFile|string $file Path to the file
* @param boolean $append Whether to append (ignored)
* @throws Exception - if invalid argument specified.
* @throws IOException - if unable to open file.
*/
public function __construct($file, $append = false)
{
if ($file instanceof PhingFile) {
$this->file = $file;
} elseif (is_string($file)) {
$this->file = new PhingFile($file);
} else {
throw new Exception("Invalid argument type for \$file.");
}
$stream = @fopen($this->file->getAbsolutePath(), "rb");
if ($stream === false) {
throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . $php_errormsg);
}
parent::__construct($stream);
}
示例2: main
/**
* @throws BuildException
*/
public function main()
{
$this->checkPreconditions();
try {
$this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
/*
* Delete old package, if exists.
*/
if ($this->destinationFile->exists()) {
/*
* TODO Check operation for errors...
*/
$this->destinationFile->delete();
}
$phar = $this->buildPhar();
$phar->startBuffering();
$baseDirectory = realpath($this->baseDirectory->getPath());
foreach ($this->filesets as $fileset) {
$this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
$phar->buildFromIterator($fileset, $baseDirectory);
}
$phar->stopBuffering();
/*
* File compression, if needed.
*/
if (Phar::NONE != $this->compression) {
$phar->compressFiles($this->compression);
}
} catch (Exception $e) {
throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
}
}
示例3: main
/**
* @throws BuildException
*/
public function main()
{
$this->checkPreconditions();
try {
$this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
/*
* Delete old package, if exists.
*/
if ($this->destinationFile->exists()) {
/*
* TODO Check operation for errors...
*/
$this->destinationFile->delete();
}
$phar = $this->buildPhar();
$phar->startBuffering();
$baseDirectory = realpath($this->baseDirectory->getPath());
foreach ($this->filesets as $fileset) {
foreach ($fileset as $realFileName) {
/*
* Calculate local file name.
*/
$localFileName = $realFileName;
if (0 === strpos($realFileName, $baseDirectory)) {
$localFileName = substr($realFileName, strlen($baseDirectory));
}
$this->log('Adding ' . $realFileName . ' as ' . $localFileName . ' to package', Project::MSG_VERBOSE);
$phar->addFile($realFileName, $localFileName);
}
}
$phar->stopBuffering();
} catch (Exception $e) {
throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
}
}
示例4: main
/**
* @throws BuildException
*/
public function main()
{
$this->checkPreconditions();
try {
$this->log('Building archive: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
/**
* Delete old archive, if exists.
*/
if ($this->destinationFile->exists()) {
$isDeleted = $this->destinationFile->delete();
if (!$isDeleted) {
$this->log("Could not delete destination file {$this->destinationFile}", Project::MSG_WARN);
}
}
$pharData = new PharData($this->baseDirectory->getPath() . '/' . $this->destinationFile->getName());
foreach ($this->filesets as $fileset) {
$this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to archive', Project::MSG_VERBOSE);
$pharData->buildFromIterator($fileset->getIterator(), $fileset->getDir($this->project));
}
if ($this->compression !== PHAR::NONE && $pharData->canCompress($this->compression)) {
try {
$pharData->compress($this->compression);
} catch (UnexpectedValueException $uve) {
$pharData->compressFiles($this->compression);
}
unset($pharData);
}
} catch (Exception $e) {
throw new BuildException('Problem creating archive: ' . $e->getMessage(), $e, $this->getLocation());
}
}
示例5: extractArchive
/**
* Extract archive content into $this->todir directory
* @param PhingFile Zip file to extract
* @return boolean
*/
protected function extractArchive(PhingFile $zipfile)
{
$this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
$zip = new ZipArchive();
$result = $zip->open($zipfile->getAbsolutePath());
if (!$result) {
$this->log("Unable to open zipfile " . $zipfile->__toString(), Project::MSG_ERR);
return false;
}
$result = $zip->extractTo($this->todir->getAbsolutePath());
if (!$result) {
$this->log("Unable to extract zipfile " . $zipfile->__toString(), Project::MSG_ERR);
return false;
}
return true;
}
示例6: main
/**
* do the work
* @throws BuildException
*/
public function main()
{
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 (empty($this->filesets)) {
throw new BuildException("You must supply some nested filesets.", $this->getLocation());
}
$this->log("Building ZIP: " . $this->zipFile->__toString(), Project::MSG_INFO);
$zip = new PclZip($this->zipFile->getAbsolutePath());
if ($zip->errorCode() != 1) {
throw new Exception("PclZip::open() failed: " . $zip->errorInfo());
}
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]);
//$filesToZip[] = realpath($f->getPath());
$fileAbsolutePath = $f->getPath();
$fileDir = rtrim(dirname($fileAbsolutePath), '/\\');
$fileBase = basename($fileAbsolutePath);
if (substr($fileDir, -4) == '.svn') {
continue;
}
if ($fileBase == '.svn') {
continue;
}
if (substr(rtrim($fileAbsolutePath, '/\\'), -4) == '.svn') {
continue;
}
//echo "\t\t$fileAbsolutePath\n";
$filesToZip[] = $f->getPath();
}
/*
$zip->add($filesToZip,
PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix ,
PCLZIP_OPT_REMOVE_PATH, realpath($fsBasedir->getPath()) );
*/
$zip->add($filesToZip, PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix, PCLZIP_OPT_REMOVE_PATH, $fsBasedir->getPath());
}
} catch (IOException $ioe) {
$msg = "Problem creating ZIP: " . $ioe->getMessage();
$this->filesets = $savedFileSets;
throw new BuildException($msg, $ioe, $this->getLocation());
}
$this->filesets = $savedFileSets;
}
示例7: main
/**
* Do the work
*
* @throws BuildException
*/
public function main()
{
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 (empty($this->filesets)) {
throw new BuildException("You must supply some nested filesets.", $this->getLocation());
}
$this->log("Building ZIP: " . $this->zipFile->__toString(), Project::MSG_INFO);
$zip = new PclZip($this->zipFile->getAbsolutePath());
if ($zip->errorCode() != 1) {
throw new Exception("PclZip::open() failed: " . $zip->errorInfo());
}
foreach ($this->filesets as $fs) {
$files = $fs->getFiles($this->project, $this->includeEmpty);
$fsBasedir = $this->baseDir != null ? $this->baseDir : $fs->getDir($this->project);
$filesToZip = array();
foreach ($files as $file) {
$f = new PhingFile($fsBasedir, $file);
$fileAbsolutePath = $f->getPath();
$fileDir = rtrim(dirname($fileAbsolutePath), '/\\');
$fileBase = basename($fileAbsolutePath);
// Only use lowercase for $disallowedBases because we'll convert $fileBase to lowercase
$disallowedBases = array('.ds_store', '.svn', '.gitignore', 'thumbs.db');
$fileBaseLower = strtolower($fileBase);
if (in_array($fileBaseLower, $disallowedBases)) {
continue;
}
if (substr($fileDir, -4) == '.svn') {
continue;
}
if (substr(rtrim($fileAbsolutePath, '/\\'), -4) == '.svn') {
continue;
}
$filesToZip[] = $fileAbsolutePath;
}
$zip->add($filesToZip, PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix, PCLZIP_OPT_REMOVE_PATH, $fsBasedir->getPath());
}
} catch (IOException $ioe) {
$msg = "Problem creating ZIP: " . $ioe->getMessage();
$this->filesets = $savedFileSets;
throw new BuildException($msg, $ioe, $this->getLocation());
}
$this->filesets = $savedFileSets;
}
示例8: main
/**
* 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());
}
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
if ($this->areFilesetsUpToDate()) {
$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);
}
if ($this->comment !== '') {
$isCommented = $zip->setArchiveComment($this->comment);
if ($isCommented === false) {
$this->log("Could not add a comment for the Archive.", Project::MSG_INFO);
}
}
$this->addFilesetsToArchive($zip);
$zip->close();
} catch (IOException $ioe) {
$msg = "Problem creating ZIP: " . $ioe->getMessage();
throw new BuildException($msg, $ioe, $this->getLocation());
}
}
示例9: main
/**
* @throws BuildException
*/
public function main()
{
$this->checkPreconditions();
try {
$this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
/**
* Delete old package, if exists.
*/
if ($this->destinationFile->exists()) {
/**
* TODO Check operation for errors...
*/
$this->destinationFile->delete();
}
$phar = $this->buildPhar();
$phar->startBuffering();
$baseDirectory = realpath($this->baseDirectory->getPath());
foreach ($this->filesets as $fileset) {
$this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
$phar->buildFromIterator($fileset, $baseDirectory);
}
$phar->stopBuffering();
/**
* File compression, if needed.
*/
if (Phar::NONE != $this->compression) {
$phar->compressFiles($this->compression);
}
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);
}
openssl_pkey_export($private, $pkey);
$phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
// 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);
}
} catch (Exception $e) {
throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
}
}
示例10: extractArchive
protected function extractArchive(PhingFile $tarfile)
{
$this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
try {
$tar = $this->initTar($tarfile);
if (!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) {
throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath());
}
} catch (IOException $ioe) {
$msg = "Could not extract tar file: " . $ioe->getMessage();
throw new BuildException($msg, $ioe, $this->getLocation());
}
}
示例11: main
/**
* @throws BuildException
*/
public function main()
{
$this->checkPreconditions();
try {
$this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
$baseDirectory = realpath($this->baseDirectory->getPath());
try {
$this->compressAllFiles($this->initPhar(), $baseDirectory);
} catch (\RuntimeException $e) {
$this->log('Most likely compression failed (known bug): ' . $e->getMessage());
$this->compressEachFile($this->initPhar(), $baseDirectory);
}
} catch (Exception $e) {
throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
}
}
示例12: validateAttributes
/**
* Validates attributes coming in from XML
*
* @return void
* @throws BuildException
*/
protected function validateAttributes()
{
if ($this->file === null && count($this->filesets) === 0) {
throw new BuildException("Specify at least one source compressed archive - a file or a fileset.");
}
if ($this->todir === null) {
throw new BuildException("todir must be set.");
}
if ($this->todir !== null && $this->todir->exists() && !$this->todir->isDirectory()) {
throw new BuildException("todir must be a directory.");
}
if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) {
throw new BuildException("Compressed archive file cannot be a directory.");
}
if ($this->file !== null && !$this->file->exists()) {
throw new BuildException("Could not find compressed archive file " . $this->file->__toString() . " to extract.");
}
}
示例13: main
/**
* 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;
}
示例14: _touch
/**
* Does the actual work.
*/
public function _touch()
{
if ($this->file !== null) {
if (!$this->file->exists()) {
$this->log("Creating " . $this->file->__toString(), $this->verbose ? Project::MSG_INFO : Project::MSG_VERBOSE);
try {
// try to create file
$this->file->createNewFile($this->mkdirs);
} catch (IOException $ioe) {
throw new BuildException("Error creating new file " . $this->file->__toString(), $ioe, $this->location);
}
}
}
$resetMillis = false;
if ($this->millis < 0) {
$resetMillis = true;
$this->millis = Phing::currentTimeMillis();
}
if ($this->file !== null) {
$this->touchFile($this->file);
}
// deal with the filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->getProject());
$fromDir = $fs->getDir($this->getProject());
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
for ($j = 0, $_j = count($srcFiles); $j < $_j; $j++) {
$this->touchFile(new PhingFile($fromDir, (string) $srcFiles[$j]));
}
for ($j = 0, $_j = count($srcDirs); $j < $_j; $j++) {
$this->touchFile(new PhingFile($fromDir, (string) $srcDirs[$j]));
}
}
if ($resetMillis) {
$this->millis = -1;
}
}
示例15: extractArchive
protected function extractArchive(PhingFile $zipfile)
{
$extractParams = array('add_path' => $this->todir->getAbsolutePath());
if (!empty($this->removepath)) {
$extractParams['remove_path'] = $this->removepath;
}
$this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
try {
$zip = new Archive_Zip($zipfile->getAbsolutePath());
$extractResponse = $zip->extract($extractParams);
if (is_array($extractResponse)) {
foreach ($extractResponse as $extractedPath) {
$this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), Project::MSG_VERBOSE);
}
} else {
if ($extractResponse === 0) {
throw new BuildException('Failed to extract zipfile: ' . $zip->errorInfo(true));
}
}
} catch (IOException $ioe) {
$msg = "Could not extract ZIP: " . $ioe->getMessage();
throw new BuildException($msg, $ioe, $this->getLocation());
}
}