当前位置: 首页>>代码示例>>PHP>>正文


PHP SplFileInfo::getRealpath方法代码示例

本文整理汇总了PHP中SplFileInfo::getRealpath方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getRealpath方法的具体用法?PHP SplFileInfo::getRealpath怎么用?PHP SplFileInfo::getRealpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplFileInfo的用法示例。


在下文中一共展示了SplFileInfo::getRealpath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fixFile

 private function fixFile(\SplFileInfo $file, $dryRun)
 {
     $new = $old = file_get_contents($file->getRealpath());
     $appliedFixers = [];
     Tokens::clearCache();
     try {
         foreach ($this->fixers as $fixer) {
             if (!$fixer->supports($file)) {
                 continue;
             }
             $newest = $fixer->fix($file, $new);
             if ($newest !== $new) {
                 $appliedFixers[] = $fixer->getName();
             }
             $new = $newest;
         }
     } catch (\Exception $e) {
         if ($this->errorsManager) {
             $this->errorsManager->report(ErrorsManager::ERROR_TYPE_EXCEPTION, $this->getFileRelativePathname($file), $e->__toString());
         }
         return;
     }
     if ($new !== $old) {
         if (!$dryRun) {
             file_put_contents($file->getRealpath(), $new);
         }
     }
     return $appliedFixers;
 }
开发者ID:akovalyov,项目名称:Symfony-Upgrade-Fixer,代码行数:29,代码来源:Fixer.php

示例2: processFile

 public function processFile(\SplFileInfo $file)
 {
     try {
         $parseResult = $this->parser->parse(new SourceFile($file->getRealpath()));
         if ($parseResult->hasRedeclarations() && !$this->tolerantMode) {
             throw new CollectorException(sprintf("Duplicate (potentially conditional) definitions of the following unit(s) found:\n\n\tUnit(s): %s\n\tFile: %s", join(', ', $parseResult->getRedeclarations()), $file->getRealPath()), CollectorException::InFileRedeclarationFound);
         }
         $this->collectorResult->addParseResult($file, $parseResult);
     } catch (ParserException $e) {
         throw new CollectorException(sprintf("Could not process file '%s' due to parse errors", $file->getRealPath()), CollectorException::ParseErrror, $e);
     } catch (CollectorResultException $e) {
         throw new CollectorException($e->getMessage(), CollectorException::RedeclarationFound);
     }
 }
开发者ID:rocketpastsix,项目名称:Autoload,代码行数:14,代码来源:Collector.php

示例3: get_size

/**
 * Get the size of a directory or a file
 *
 * @param SplFileInfo $file SplFileInfo instance
 *
 * @return int The calculated size
 */
function get_size(\SplFileInfo $file)
{
    $size = 0;
    try {
        if ($file->isFile()) {
            $size += $file->getSize();
        } else {
            foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($file->getRealpath())) as $f) {
                $size += $f->getSize();
            }
        }
    } catch (\RuntimeException $e) {
    }
    return $size;
}
开发者ID:Arkhana,项目名称:Cakebox,代码行数:22,代码来源:utils.php

示例4: fixFile

 public function fixFile(\SplFileInfo $file, array $fixers, $dryRun)
 {
     $new = $old = file_get_contents($file->getRealpath());
     $appliedFixers = array();
     foreach ($fixers as $fixer) {
         if (!$fixer->supports($file)) {
             continue;
         }
         $new1 = $fixer->fix($file, $new);
         if ($new1 != $new) {
             $appliedFixers[] = $fixer->getName();
         }
         $new = $new1;
     }
     if ($new != $old) {
         if (!$dryRun) {
             file_put_contents($file->getRealpath(), $new);
         }
         return $appliedFixers;
     }
 }
开发者ID:raphinesse,项目名称:PHP-CS-Fixer,代码行数:21,代码来源:Fixer.php

示例5: find

 /**
  * This method will create reflection class instances for all interfaces
  * and classes that can be found in the given source code files.
  *
  * @param string $pathnames The source directory that is the target of the
  *        class search.
  *
  * @return Iterator
  */
 public function find(array $paths)
 {
     $classes = array();
     foreach ($paths as $path) {
         if (file_exists($path) === false || !is_file($path)) {
             throw new \LogicException('Invalid or nonexistent file ' . $path);
         }
         $fileInfo = new \SplFileInfo($path);
         $fileClasses = $this->parseFile($fileInfo->getRealpath());
         $classes = array_merge($classes, $fileClasses);
     }
     return new \ArrayIterator($classes);
 }
开发者ID:naderman,项目名称:pflow,代码行数:22,代码来源:ReflectionFileSetQuery.php

示例6: filesize

 /**
  * Get the total filesize for a given file or directory
  *
  * If $file is a file then just return the result of `filesize()`.
  * If $file is a directory then schedule a recursive filesize scan.
  *
  * @param \SplFileInfo $file The file or directory you want to know the size of
  * @param bool $skip_excluded_files Skip excluded files when calculating a directories total size
  *
  * @return int                        The total of the file or directory
  */
 public function filesize(\SplFileInfo $file, $skip_excluded_files = false)
 {
     // Skip missing or unreadable files
     if (!file_exists($file->getPathname()) || !$file->getRealpath() || !$file->isReadable()) {
         return false;
     }
     // If it's a file then just pass back the filesize
     if ($file->isFile() && $file->isReadable()) {
         return $file->getSize();
     }
     // If it's a directory then pull it from the cached filesize array
     if ($file->isDir()) {
         // If we haven't calculated the site size yet then kick it off in a thread
         $directory_sizes = get_transient('hmbkp_directory_filesizes');
         if (!is_array($directory_sizes)) {
             if (!$this->is_site_size_being_calculated()) {
                 // Mark the filesize as being calculated
                 set_transient('hmbkp_directory_filesizes_running', true, HOUR_IN_SECONDS);
                 // Schedule a Backdrop task to trigger a recalculation
                 $task = new \HM\Backdrop\Task(array($this, 'recursive_filesize_scanner'));
                 $task->schedule();
             }
             return;
         }
         if ($this->backup->get_root() === $file->getPathname()) {
             return $directory_sizes[$file->getPathname()];
         }
         $current_pathname = trailingslashit($file->getPathname());
         $root = trailingslashit($this->backup->get_root());
         foreach ($directory_sizes as $path => $size) {
             // Remove any files that aren't part of the current tree
             if (false === strpos($path, $current_pathname)) {
                 unset($directory_sizes[$path]);
             }
         }
         if ($skip_excluded_files) {
             $excludes = $this->backup->exclude_string('regex');
             foreach ($directory_sizes as $path => $size) {
                 // Skip excluded files if we have excludes
                 if ($excludes && preg_match('(' . $excludes . ')', str_ireplace($root, '', Backup::conform_dir($path)))) {
                     unset($directory_sizes[$path]);
                 }
             }
         }
         // Directory size is now just a sum of all files across all sub directories
         return array_sum($directory_sizes);
     }
 }
开发者ID:alexanderpetrob89,项目名称:fei.edu,代码行数:59,代码来源:class-schedule.php

示例7: fixFile

 public function fixFile(\SplFileInfo $file, array $fixers, $dryRun, $diff, FileCacheManager $fileCacheManager)
 {
     $new = $old = file_get_contents($file->getRealpath());
     if (!$fileCacheManager->needFixing($this->getFileRelativePathname($file), $old)) {
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_SKIPPED));
         }
         return;
     }
     if ($this->lintManager && !$this->lintManager->createProcessForFile($file->getRealpath())->isSuccessful()) {
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_INVALID));
         }
         return;
     }
     $appliedFixers = array();
     // we do not need Tokens to still caching previously fixed file - so clear the cache
     Tokens::clearCache();
     try {
         foreach ($fixers as $fixer) {
             if (!$fixer->supports($file)) {
                 continue;
             }
             $newest = $fixer->fix($file, $new);
             if ($newest !== $new) {
                 $appliedFixers[] = $fixer->getName();
             }
             $new = $newest;
         }
     } catch (\Exception $e) {
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_EXCEPTION));
         }
         if ($this->errorsManager) {
             $this->errorsManager->report(ErrorsManager::ERROR_TYPE_EXCEPTION, $this->getFileRelativePathname($file), $e->__toString());
         }
         return;
     }
     $fixInfo = null;
     if ($new !== $old) {
         if ($this->lintManager) {
             $lintProcess = $this->lintManager->createProcessForSource($new);
             if (!$lintProcess->isSuccessful()) {
                 if ($this->eventDispatcher) {
                     $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_LINT));
                 }
                 if ($this->errorsManager) {
                     $this->errorsManager->report(ErrorsManager::ERROR_TYPE_LINT, $this->getFileRelativePathname($file), $lintProcess->getOutput());
                 }
                 return;
             }
         }
         if (!$dryRun) {
             file_put_contents($file->getRealpath(), $new);
         }
         $fixInfo = array('appliedFixers' => $appliedFixers);
         if ($diff) {
             $fixInfo['diff'] = $this->stringDiff($old, $new);
         }
     }
     $fileCacheManager->setFile($this->getFileRelativePathname($file), $new);
     if ($this->eventDispatcher) {
         $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus($fixInfo ? FixerFileProcessedEvent::STATUS_FIXED : FixerFileProcessedEvent::STATUS_NO_CHANGES));
     }
     return $fixInfo;
 }
开发者ID:brighten01,项目名称:opencloud-zendframework,代码行数:66,代码来源:Fixer.php

示例8: fixFile

 public function fixFile(\SplFileInfo $file, array $fixers, $dryRun, $diff)
 {
     $new = $old = file_get_contents($file->getRealpath());
     $appliedFixers = array();
     foreach ($fixers as $fixer) {
         if (!$fixer->supports($file)) {
             continue;
         }
         $new1 = $fixer->fix($file, $new);
         if ($new1 != $new) {
             $appliedFixers[] = $fixer->getName();
         }
         $new = $new1;
     }
     if ($new != $old) {
         if (!$dryRun) {
             file_put_contents($file->getRealpath(), $new);
         }
         $fixInfo = array('appliedFixers' => $appliedFixers);
         if ($diff) {
             $fixInfo['diff'] = $this->stringDiff($old, $new);
         }
         return $fixInfo;
     }
 }
开发者ID:JasonWayne,项目名称:markdown-resume,代码行数:25,代码来源:Fixer.php

示例9: upload

 /**
  * Uploads a file or directory to an FTP connection.
  *
  * @param \Ftp         $ftp  An active FTP connection.
  * @param \SplFileInfo $file A local file to upload.
  */
 protected function upload(\Ftp $ftp, \SplFileInfo $file)
 {
     // enter into passive mode
     $ftp->pasv(true);
     // move to the file's parent directory
     $ftp->chdir($this->targetDirectory . '/' . $file->getRelativePath());
     // check if the file exists
     $fileExists = in_array($file->getBasename(), $ftp->nlist('.'));
     // check if the file is a directory
     if ($file->isDir()) {
         // create the directory if it does not exist
         if (!$fileExists) {
             $this->printTaskInfo('Creating directory: ' . $file->getRelativePathname());
             // create directory
             $ftp->mkdir($file->getBasename());
         }
     } else {
         // if the file already exists, check our skip options
         if ($fileExists) {
             // skip the file if the file sizes are equal
             if ($this->skipSizeEqual && $ftp->size($file->getBasename()) === $file->getSize()) {
                 return;
             }
             // skip the file if modified time is same or newer than source
             if ($this->skipUnmodified && $ftp->mdtm($file->getBasename()) >= $file->getMTime()) {
                 return;
             }
         }
         // try to upload the file
         $this->printTaskInfo('Uploading: ' . $file->getRelativePathname());
         if (!$ftp->put($file->getBasename(), $file->getRealpath(), FTP_BINARY)) {
             // something went wrong
             return Result::error($this, 'Failed while uploading file ' . $file->getRelativePathname());
         }
     }
 }
开发者ID:coderstephen,项目名称:robo-ftp,代码行数:42,代码来源:FtpDeployTask.php

示例10: conVertFile

 public function conVertFile(\SplFileInfo $file, array $converter, $dryRun, $diff, $outputExt)
 {
     $new = $old = file_get_contents($file->getRealpath());
     $appliedConverters = array();
     foreach ($converter as $convert) {
         if (!$convert->supports($file)) {
             continue;
         }
         $new1 = $convert->convert($file, $new);
         if ($new1 != $new) {
             $appliedConverters[] = $convert->getName();
         }
         $new = $new1;
     }
     if ($new != $old) {
         if (!$dryRun) {
             $filename = $file->getRealpath();
             $ext = strrchr($filename, '.');
             if ($outputExt) {
                 $filename = rtrim($filename, $ext) . '.' . trim($outputExt, '.');
             }
             file_put_contents($filename, $new);
         }
         $fixInfo = array('appliedConverters' => $appliedConverters);
         if ($diff) {
             $fixInfo['diff'] = $this->stringDiff($old, $new);
         }
         return $fixInfo;
     }
 }
开发者ID:Gamesh,项目名称:to-twig,代码行数:30,代码来源:Converter.php

示例11: convertResource

 /**
  * @param  \Yosmanyga\Resource\Resource $resource
  * @param  \SplFileInfo                 $file
  * @return \Yosmanyga\Resource\Resource
  */
 private function convertResource(Resource $resource, \SplFileInfo $file)
 {
     return new Resource(array_merge($resource->getMetadata(), array('file' => $file->getRealpath())), $resource->getMetadata('type'));
 }
开发者ID:yosmanyga,项目名称:resource,代码行数:9,代码来源:DirectoryReader.php

示例12: _tryToBuildAddonFromFile

 private function _tryToBuildAddonFromFile(SplFileInfo $infoFile)
 {
     $manifestFilePath = realpath("{$infoFile}");
     $infoFileContents = @json_decode(file_get_contents($manifestFilePath), true);
     $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG);
     if ($infoFileContents === null || $infoFileContents === false || empty($infoFileContents)) {
         if ($shouldLog) {
             $this->_logger->debug('Could not parse add-on manifest file at ' . $manifestFilePath);
         }
         return null;
     }
     try {
         return $this->_constructAddonFromArray($infoFileContents, $manifestFilePath);
     } catch (Exception $e) {
         if ($shouldLog) {
             $this->_logger->warn('Caught exception when parsing info file at ' . $infoFile->getRealpath() . ': ' . $e->getMessage());
         }
         return null;
     }
 }
开发者ID:jenia-buianov,项目名称:all_my_sites,代码行数:20,代码来源:DefaultAddonDiscoverer.php

示例13: fixFile

 public function fixFile(\SplFileInfo $file, array $fixers, $dryRun, $diff, FileCacheManager $fileCacheManager)
 {
     $new = $old = file_get_contents($file->getRealpath());
     if ('' === $old || !$fileCacheManager->needFixing($this->getFileRelativePathname($file), $old) || PHP_VERSION_ID >= 50306 && PHP_VERSION_ID < 50400 && false !== stripos($old, '__halt_compiler()')) {
         $this->dispatchEvent(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_SKIPPED));
         return;
     }
     try {
         $this->linter->lintFile($file->getRealpath());
     } catch (LintingException $e) {
         $this->dispatchEvent(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_INVALID));
         $this->errorsManager->report(new Error(Error::TYPE_INVALID, $this->getFileRelativePathname($file)));
         return;
     }
     $old = file_get_contents($file->getRealpath());
     $appliedFixers = array();
     // we do not need Tokens to still caching previously fixed file - so clear the cache
     Tokens::clearCache();
     $tokens = Tokens::fromCode($old);
     $newHash = $oldHash = $tokens->getCodeHash();
     try {
         foreach ($fixers as $fixer) {
             if (!$fixer->supports($file) || !$fixer->isCandidate($tokens)) {
                 continue;
             }
             $fixer->fix($file, $tokens);
             if ($tokens->isChanged()) {
                 $tokens->clearEmptyTokens();
                 $tokens->clearChanged();
                 $appliedFixers[] = $fixer->getName();
             }
         }
     } catch (\Exception $e) {
         $this->dispatchEvent(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_EXCEPTION));
         $this->errorsManager->report(new Error(Error::TYPE_EXCEPTION, $this->getFileRelativePathname($file)));
         return;
     }
     $fixInfo = null;
     if (!empty($appliedFixers)) {
         $new = $tokens->generateCode();
         $newHash = $tokens->getCodeHash();
     }
     // We need to check if content was changed and then applied changes.
     // But we can't simple check $appliedFixers, because one fixer may revert
     // work of other and both of them will mark collection as changed.
     // Therefore we need to check if code hashes changed.
     if ($oldHash !== $newHash) {
         try {
             $this->linter->lintSource($new);
         } catch (LintingException $e) {
             $this->dispatchEvent(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_LINT));
             $this->errorsManager->report(new Error(Error::TYPE_LINT, $this->getFileRelativePathname($file)));
             return;
         }
         if (!$dryRun && false === @file_put_contents($file->getRealpath(), $new)) {
             $error = error_get_last();
             if ($error) {
                 throw new IOException(sprintf('Failed to write file "%s", "%s".', $file->getRealpath(), $error['message']), 0, null, $file->getRealpath());
             }
             throw new IOException(sprintf('Failed to write file "%s".', $file->getRealpath()), 0, null, $file->getRealpath());
         }
         $fixInfo = array('appliedFixers' => $appliedFixers);
         if ($diff) {
             $fixInfo['diff'] = $this->stringDiff($old, $new);
         }
     }
     $fileCacheManager->setFile($this->getFileRelativePathname($file), $new);
     $this->dispatchEvent(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus($fixInfo ? FixerFileProcessedEvent::STATUS_FIXED : FixerFileProcessedEvent::STATUS_NO_CHANGES));
     return $fixInfo;
 }
开发者ID:nazimodi,项目名称:PHP-CS-Fixer,代码行数:70,代码来源:Fixer.php

示例14: fixFile

 public function fixFile(\SplFileInfo $file, array $fixers, $dryRun, $diff, FileCacheManager $fileCacheManager)
 {
     $new = $old = file_get_contents($file->getRealpath());
     if (!$fileCacheManager->needFixing($this->getFileRelativePathname($file), $old)) {
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus(FixerFileProcessedEvent::STATUS_SKIPPED));
         }
         return;
     }
     $appliedFixers = array();
     // we do not need Tokens to still caching previously fixed file - so clear the cache
     Tokens::clearCache();
     foreach ($fixers as $fixer) {
         if (!$fixer->supports($file)) {
             continue;
         }
         $newest = $fixer->fix($file, $new);
         if ($newest !== $new) {
             $appliedFixers[] = $fixer->getName();
         }
         $new = $newest;
     }
     $fixInfo = null;
     if ($new !== $old) {
         if (!$dryRun) {
             file_put_contents($file->getRealpath(), $new);
         }
         $fixInfo = array('appliedFixers' => $appliedFixers);
         if ($diff) {
             $fixInfo['diff'] = $this->stringDiff($old, $new);
         }
     }
     $fileCacheManager->setFile($this->getFileRelativePathname($file), $new);
     if ($this->eventDispatcher) {
         $this->eventDispatcher->dispatch(FixerFileProcessedEvent::NAME, FixerFileProcessedEvent::create()->setStatus($fixInfo ? FixerFileProcessedEvent::STATUS_FIXED : FixerFileProcessedEvent::STATUS_NO_CHANGES));
     }
     return $fixInfo;
 }
开发者ID:bgotink,项目名称:PHP-CS-Fixer,代码行数:38,代码来源:Fixer.php

示例15: updateContentDir

 public function updateContentDir(DOMElement $parent, SplFileInfo $directory, $role)
 {
     $dir = $parent->ownerDocument->createElement('dir');
     $dir->setAttribute('name', $directory->getFilename());
     if ($this->basedir) {
         $dir->setAttribute('baseinstalldir', $this->basedir);
     }
     $parent->appendChild($dir);
     foreach (new DirectoryIterator($directory->getRealpath()) as $file) {
         if ($file->isDot()) {
             continue;
         } else {
             if ($file->isDir()) {
                 $this->updateContentDir($dir, $file, $role);
             } else {
                 $this->updateContentFile($dir, $file, $role);
             }
         }
     }
     return $parent;
 }
开发者ID:Qafoo,项目名称:build-commons,代码行数:21,代码来源:update.php


注:本文中的SplFileInfo::getRealpath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。