本文整理汇总了PHP中PhingFile::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP PhingFile::exists方法的具体用法?PHP PhingFile::exists怎么用?PHP PhingFile::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhingFile
的用法示例。
在下文中一共展示了PhingFile::exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Uses a builder class to create the output class.
* This method assumes that the DataModelBuilder class has been initialized with the build properties.
*
* @param OMBuilder $builder
* @param boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).
*
* @todo -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
* @return int
*/
protected function build(OMBuilder $builder, $overwrite = true)
{
$path = $builder->getClassFilePath();
$this->ensureDirExists(dirname($path));
$_f = new PhingFile($this->getOutputDirectory(), $path);
// skip files already created once
if ($_f->exists() && !$overwrite) {
$this->log("\t-> (exists) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
return 0;
}
$script = $builder->build();
foreach ($builder->getWarnings() as $warning) {
$this->log($warning, Project::MSG_WARN);
}
// skip unchanged files
if ($_f->exists() && $script == $_f->contents()) {
$this->log("\t-> (unchanged) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
return 0;
}
// write / overwrite new / changed files
$action = $_f->exists() ? 'Updating' : 'Creating';
$this->log(sprintf("\t-> %s %s (table: %s, builder: %s)", $action, $builder->getClassFilePath(), $builder->getTable()->getName(), get_class($builder)));
file_put_contents($_f->getAbsolutePath(), $script);
return 1;
}
示例2: 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());
}
}
}
示例3: main
public function main()
{
if (empty($this->filesets)) {
throw new BuildException("You must specify a file or fileset(s).");
}
if (empty($this->_compilePath)) {
throw new BuildException("You must specify location for compiled templates.");
}
date_default_timezone_set("America/New_York");
$project = $this->getProject();
$this->_count = $this->_total = 0;
$smartyCompilePath = new PhingFile($this->_compilePath);
if (!$smartyCompilePath->exists()) {
$this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
if (!$smartyCompilePath->mkdirs()) {
throw new BuildException("Error creating compile path for Smarty in " . $this->_compilePath);
}
}
$this->_smarty = new Smarty();
$this->_smarty->use_sub_dirs = true;
$this->_smarty->compile_dir = $smartyCompilePath;
$this->_smarty->plugins_dir[] = $this->_pluginsPath;
$this->_smarty->force_compile = $this->_forceCompile;
// process filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($project);
$fromDir = $fs->getDir($project);
$srcFiles = $ds->getIncludedFiles();
$this->_compile($fromDir, $srcFiles);
}
$this->log("Compiled " . $this->_count . " out of " . $this->_total . " Smarty templates");
}
示例4: checkFileExists
public function checkFileExists()
{
//Get the correct path to asset
switch ($this->type) {
case Asset::ASSET_TYPE_CSS:
$this->assetFolder = $this->paths['css'];
break;
case Asset::ASSET_TYPE_JS:
$this->assetFolder = $this->paths['js'];
break;
case Asset::ASSET_TYPE_IMAGE:
$this->assetFolder = $this->paths['images'];
break;
default:
$folder = '';
}
//Path to file
$file = new PhingFile($this->assetsDir . '/' . $this->assetFolder . $this->file);
//Check file exists
if (!$file->exists()) {
throw new BuildException("Unable to find asset file: " . $file->getAbsolutePath());
}
//Check we can read it
if (!$file->canRead()) {
throw IOException("Unable to read asset file: " . $file->getPath());
}
return $file;
}
示例5: 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;
}
示例6: setOutputDirectory
/**
* Set the sqldbmap.
* @param PhingFile $sqldbmap The db map.
*/
public function setOutputDirectory(PhingFile $out)
{
if (!$out->exists()) {
$out->mkdirs();
}
$this->outDir = $out;
}
示例7: createDirectories
private function createDirectories($path)
{
$f = new PhingFile($path);
if (!$f->exists()) {
$f->mkdirs();
}
}
示例8: setDir
public function setDir(PhingFile $dir)
{
if (!$dir->exists()) {
throw new BuildException("Can not find asset directory: " . $dir->getAbsolutePath(), $this->location);
}
$this->assetDir = $dir->getAbsolutePath();
}
示例9: 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;
}
示例10: 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);
}
}
示例11: doWork
/**
* Copied from 'CopyTask.php'
*/
protected function doWork()
{
// These "slots" allow filters to retrieve information about the currently-being-process files
$fromSlot = $this->getRegisterSlot("currentFromFile");
$fromBasenameSlot = $this->getRegisterSlot("currentFromFile.basename");
$toSlot = $this->getRegisterSlot("currentToFile");
$toBasenameSlot = $this->getRegisterSlot("currentToFile.basename");
$mapSize = count($this->fileCopyMap);
$total = $mapSize;
if ($mapSize > 0) {
$this->log("Minifying " . $mapSize . " file" . ($mapSize === 1 ? '' : 's') . " to " . $this->destDir->getAbsolutePath());
// walks the map and actually copies the files
$count = 0;
foreach ($this->fileCopyMap as $from => $to) {
if ($from === $to) {
$this->log("Skipping self-copy of " . $from, $this->verbosity);
$total--;
continue;
}
$this->log("From " . $from . " to " . $to, $this->verbosity);
try {
// try to copy file
$fromFile = new PhingFile($from);
$toFile = new PhingFile($to);
$fromSlot->setValue($fromFile->getPath());
$fromBasenameSlot->setValue($fromFile->getName());
$toSlot->setValue($toFile->getPath());
$toBasenameSlot->setValue($toFile->getName());
$this->fileUtils->copyFile($fromFile, $toFile, $this->overwrite, $this->preserveLMT, $this->filterChains, $this->getProject());
// perform ''minification'' once all other things are done on it.
$this->minify($toFile);
$count++;
} catch (IOException $ioe) {
$this->log("Failed to minify " . $from . " to " . $to . ": " . $ioe->getMessage(), Project::MSG_ERR);
}
}
}
// handle empty dirs if appropriate
if ($this->includeEmpty) {
$destdirs = array_values($this->dirCopyMap);
$count = 0;
foreach ($destdirs as $destdir) {
$d = new PhingFile((string) $destdir);
if (!$d->exists()) {
if (!$d->mkdirs()) {
$this->log("Unable to create directory " . $d->__toString(), Project::MSG_ERR);
} else {
$count++;
}
}
}
if ($count > 0) {
$this->log("Copied " . $count . " empty director" . ($count == 1 ? "y" : "ies") . " to " . $this->destDir->getAbsolutePath());
}
}
}
示例12: 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;
}
示例13: 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());
}
}
示例14: initPhar
/**
* @return Phar
*/
private function initPhar()
{
/**
* Delete old package, if exists.
*/
if ($this->destinationFile->exists()) {
$this->destinationFile->delete();
}
$phar = $this->buildPhar();
return $phar;
}
示例15: output
private function output($is_css, $data, $js)
{
if (!$is_css) {
$folder = '/js/';
} else {
$folder = '/css/';
}
//Build path to output file
$out = new PhingFile($this->assetDir . $folder . $js->file);
//Check whether to overwrite files
if ($out->exists() && !$js->overwrite) {
throw new BuildException("Trying to write to " . $js->file . " but the overwrite flag has not been set to TRUE", $this->location);
} else {
if ($out->exists()) {
$out->delete();
}
}
//Write compressed JS to file
file_put_contents($out->getAbsolutePath(), $data);
}