本文整理汇总了PHP中PhingFile::canWrite方法的典型用法代码示例。如果您正苦于以下问题:PHP PhingFile::canWrite方法的具体用法?PHP PhingFile::canWrite怎么用?PHP PhingFile::canWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhingFile
的用法示例。
在下文中一共展示了PhingFile::canWrite方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkPreconditions
/**
* @throws BuildException
*/
private function checkPreconditions()
{
if (is_null($this->destinationFile)) {
throw new BuildException("destfile attribute must be set!", $this->getLocation());
}
if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
throw new BuildException("destfile is a directory!", $this->getLocation());
}
if (!$this->destinationFile->canWrite()) {
throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
}
if (!is_null($this->baseDirectory)) {
if (!$this->baseDirectory->exists()) {
throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation());
}
}
if ($this->signatureAlgorithm == Phar::OPENSSL) {
if (!extension_loaded('openssl')) {
throw new BuildException("PHP OpenSSL extension is required for OpenSSL signing of Phars!", $this->getLocation());
}
if (is_null($this->key)) {
throw new BuildException("key attribute must be set for OpenSSL signing!", $this->getLocation());
}
if (!$this->key->exists()) {
throw new BuildException("key '" . (string) $this->key . "' does not exist!", $this->getLocation());
}
if (!$this->key->canRead()) {
throw new BuildException("key '" . (string) $this->key . "' cannot be read!", $this->getLocation());
}
}
}
示例2: 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;
}
示例3: main
/**
* Run the task.
*
* @throws BuildException trouble, probably file IO
*/
public function main()
{
if ($this->prefix != null && $this->regex != null) {
throw new BuildException("Please specify either prefix or regex, but not both", $this->getLocation());
}
//copy the properties file
$allProps = array();
/* load properties from file if specified, otherwise use Phing's properties */
if ($this->inFile == null) {
// add phing properties
$allProps = $this->getProject()->getProperties();
} elseif ($this->inFile != null) {
if ($this->inFile->exists() && $this->inFile->isDirectory()) {
$message = "srcfile is a directory!";
$this->failOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
if ($this->inFile->exists() && !$this->inFile->canRead()) {
$message = "Can not read from the specified srcfile!";
$this->failOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
try {
$props = new Properties();
$props->load(new PhingFile($this->inFile));
$allProps = $props->getProperties();
} catch (IOException $ioe) {
$message = "Could not read file " . $this->inFile->getAbsolutePath();
$this->failOnErrorAction($ioe, $message, Project::MSG_WARN);
return;
}
}
$os = null;
try {
if ($this->destfile == null) {
$os = Phing::getOutputStream();
$this->saveProperties($allProps, $os);
$this->log($os, Project::MSG_INFO);
} else {
if ($this->destfile->exists() && $this->destfile->isDirectory()) {
$message = "destfile is a directory!";
$this->failOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
if ($this->destfile->exists() && !$this->destfile->canWrite()) {
$message = "Can not write to the specified destfile!";
$this->failOnErrorAction(null, $message, Project::MSG_ERR);
return;
}
$os = new FileOutputStream($this->destfile);
$this->saveProperties($allProps, $os);
}
} catch (IOException $ioe) {
$this->failOnErrorAction($ioe);
}
}
示例4: 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;
}
示例5: 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());
}
}
示例6: checkPreconditions
/**
* @throws BuildException
*/
private function checkPreconditions()
{
if (is_null($this->destinationFile)) {
throw new BuildException("destfile attribute must be set!", $this->getLocation());
}
if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
throw new BuildException("destfile is a directory!", $this->getLocation());
}
if (!$this->destinationFile->canWrite()) {
throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
}
if (!is_null($this->baseDirectory)) {
if (!$this->baseDirectory->exists()) {
throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation());
}
}
}
示例7: 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;
}
示例8: checkPreconditions
/**
* @throws BuildException
*/
private function checkPreconditions()
{
if (!extension_loaded('phar')) {
throw new BuildException("PharDataTask require either PHP 5.3 or better or the PECL's Phar extension");
}
if (is_null($this->destinationFile)) {
throw new BuildException("destfile attribute must be set!", $this->getLocation());
}
if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
throw new BuildException("destfile is a directory!", $this->getLocation());
}
if (!$this->destinationFile->canWrite()) {
throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
}
if (is_null($this->baseDirectory)) {
throw new BuildException("basedir cattribute must be set", $this->getLocation());
}
if (!$this->baseDirectory->exists()) {
throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation());
}
}
示例9: 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());
}
// 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;
}
示例10: 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 ($this->baseDir !== null) {
if (!$this->baseDir->exists()) {
throw new BuildException("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 Archive_Zip($this->zipFile->getAbsolutePath());
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[] = $f->getAbsolutePath();
$this->log("Adding " . $f->getPath() . " to archive.", Project::MSG_VERBOSE);
}
$zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath()));
}
} catch (IOException $ioe) {
$msg = "Problem creating ZIP: " . $ioe->getMessage();
$this->filesets = $savedFileSets;
throw new BuildException($msg, $ioe, $this->getLocation());
}
$this->filesets = $savedFileSets;
}
示例11: isSelected
/**
* {@inheritdoc}
*
* @param PhingFile $basedir
* @param string $filename
* @param PhingFile $file
*
* @return bool
*/
public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
{
return $file !== null && $file->canWrite();
}