本文整理汇总了PHP中PhingFile::length方法的典型用法代码示例。如果您正苦于以下问题:PHP PhingFile::length方法的具体用法?PHP PhingFile::length怎么用?PHP PhingFile::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhingFile
的用法示例。
在下文中一共展示了PhingFile::length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectionTest
/**
* This test is our selection test that compared the file with the destfile.
*
* @param PhingFile $srcfile the source file
* @param PhingFile $destfile the destination file
* @return bool true if the files are different
*
* @throws BuildException
*/
protected function selectionTest(PhingFile $srcfile, PhingFile $destfile)
{
try {
// if either of them is missing, they are different
if ($srcfile->exists() !== $destfile->exists()) {
return true;
}
if ($srcfile->length() !== $destfile->length()) {
// different size => different files
return true;
}
if (!$this->ignoreFileTimes) {
// different dates => different files
if ($destfile->lastModified() !== $srcfile->lastModified()) {
return true;
}
}
if (!$this->ignoreContents) {
//here do a bulk comparison
$fu = new FileUtils();
return !$fu->contentEquals($srcfile, $destfile);
}
} catch (IOException $e) {
throw new BuildException("while comparing {$srcfile} and {$destfile}", $e);
}
return false;
}
示例2: main
//.........这里部分代码省略.........
} else {
$this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
}
if ($this->passive) {
$this->log('Setting passive mode', $this->logLevel);
$ret = $ftp->setPassive();
if (@PEAR::isError($ret)) {
$ftp->disconnect();
throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
}
}
// append '/' to the end if necessary
$dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
if ($this->clearFirst) {
// TODO change to a loop through all files and directories within current directory
$this->log('Clearing directory ' . $dir, $this->logLevel);
$ftp->rm($dir, true);
}
// Create directory just in case
$ret = $ftp->mkdir($dir, true);
if (@PEAR::isError($ret)) {
$ftp->disconnect();
throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
}
$ret = $ftp->cd($dir);
if (@PEAR::isError($ret)) {
$ftp->disconnect();
throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
} else {
$this->log('Changed directory ' . $dir, $this->logLevel);
}
$fs = FileSystem::getFileSystem();
$convert = $fs->getSeparator() == '\\';
foreach ($this->filesets as $fs) {
// Array for holding directory content informations
$remoteFileInformations = array();
$ds = $fs->getDirectoryScanner($project);
$fromDir = $fs->getDir($project);
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
foreach ($srcDirs as $dirname) {
if ($convert) {
$dirname = str_replace('\\', '/', $dirname);
}
// Read directory informations, if file exists, else create the directory
if (!$this->_directoryInformations($ftp, $remoteFileInformations, $dirname)) {
$this->log('Will create directory ' . $dirname, $this->logLevel);
$ret = $ftp->mkdir($dirname, true);
if (@PEAR::isError($ret)) {
$ftp->disconnect();
throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
}
}
if ($this->dirmode) {
if ($this->dirmode == 'inherit') {
$mode = fileperms($dirname);
} else {
$mode = $this->dirmode;
}
// Because Net_FTP does not support a chmod call we call ftp_chmod directly
ftp_chmod($ftp->_handle, $mode, $dirname);
}
}
foreach ($srcFiles as $filename) {
$file = new PhingFile($fromDir->getAbsolutePath(), $filename);
if ($convert) {
$filename = str_replace('\\', '/', $filename);
}
$local_filemtime = filemtime($file->getCanonicalPath());
if (isset($remoteFileInformations[$filename]['stamp'])) {
$remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'];
} else {
$remoteFileModificationTime = 0;
}
if (!$this->depends || $local_filemtime > $remoteFileModificationTime) {
if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) {
$this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel);
continue;
}
$this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
$ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
if (@PEAR::isError($ret)) {
$ftp->disconnect();
throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
}
}
if ($this->filemode) {
if ($this->filemode == 'inherit') {
$mode = fileperms($filename);
} else {
$mode = $this->filemode;
}
// Because Net_FTP does not support a chmod call we call ftp_chmod directly
ftp_chmod($ftp->_handle, $mode, $filename);
}
}
}
$ftp->disconnect();
$this->log('Disconnected from FTP server', $this->logLevel);
}
示例3: isSelected
/**
* The heart of the matter. This is where the selector gets to decide
* on the inclusion of a file in a particular fileset.
*
* {@inheritdoc}
*
* @param PhingFile $basedir A PhingFile object for the base directory
* @param string $filename The name of the file to check
* @param PhingFile $file A PhingFile object for this filename
*
* @return bool whether the file should be selected or not
*/
public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
{
$this->validate();
// Directory size never selected for
if ($file->isDirectory()) {
return true;
}
if ($this->cmp === 0) {
return $file->length() < $this->sizelimit;
} elseif ($this->cmp === 1) {
return $file->length() > $this->sizelimit;
} else {
return $file->length() === $this->sizelimit;
}
}
示例4: _validateAttributes
/**
* Validates attributes coming in from XML.
*
* @param void
* @return void
* @throws BuildException
* @access protected
*/
protected function _validateAttributes()
{
if (null === $this->_resource) {
throw new BuildException('You must specify a file to load.');
}
if (null === $this->_destFile && empty($this->_filesets)) {
throw new BuildException('Specify at least one source - a file or a fileset.');
}
if (null !== $this->_destFile && !empty($this->_filesets)) {
throw new BuildException('Only one of destination file and fileset may be set.');
}
if ($this->_resource->exists()) {
if ($this->_resource->isDirectory()) {
throw new BuildException('Cannot load a directory as a file.');
}
try {
if (0 === $this->_resource->length()) {
$this->log('The file ' . $this->_resource . ' is empty!', $this->getVerbose());
}
} catch (IOException $e) {
throw new BuildException($e->getMessage(), $e->getLocation());
}
} else {
throw new BuildException($this->_resource . ' does not exist!');
}
}