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


PHP SplFileInfo::isFile方法代码示例

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


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

示例1: readFile

 public static function readFile($path)
 {
     $file = new SplFileInfo($path, '', '');
     if (!$file->isFile()) {
         throw new Exception('Invalid file. Fail to get file ' . $path);
     }
     return $file;
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:8,代码来源:FileSystemUtil.php

示例2: parse

 /**
  * Parse the contents of the file.
  *
  * Example:
  *
  *     ---
  *     title: Title
  *     date: 2016-07-29
  *     ---
  *     Lorem Ipsum.
  *
  * @throws \RuntimeException
  *
  * @return $this
  */
 public function parse()
 {
     if ($this->file->isFile()) {
         if (!$this->file->isReadable()) {
             throw new \RuntimeException('Cannot read file');
         }
         // parse front matter
         preg_match('/' . self::PATTERN . '/s', $this->file->getContents(), $matches);
         // if not front matter, set body only
         if (!$matches) {
             $this->body = $this->file->getContents();
             return $this;
         }
         $this->frontmatter = trim($matches[1]);
         $this->body = trim($matches[2]);
     }
     return $this;
 }
开发者ID:narno,项目名称:phpoole-library,代码行数:33,代码来源:Parser.php

示例3: getVersionFromComposerJson

 private function getVersionFromComposerJson($dir)
 {
     $version = '_._._';
     /** @var SplFileInfo $composerFile */
     $composerFile = new SplFileInfo($dir . '/composer.json', '', '');
     if ($composerFile->isFile()) {
         $composerJson = json_decode($composerFile->getContents());
         return $composerJson->version;
     }
     return $version;
 }
开发者ID:sulu,项目名称:sulu,代码行数:11,代码来源:SuluVersionPass.php

示例4: clean

 /**
  * @param SplFileInfo $file
  *
  * @return string
  */
 public function clean(SplFileInfo $file)
 {
     $name = $file->getFilename();
     if ($file->isFile()) {
         $name = pathinfo($name, PATHINFO_FILENAME);
     }
     $name = str_replace("\t\n\r\v", ' ', $name);
     // remove control characters
     $name = str_replace('_', ' ', $name);
     $name = preg_replace('/\\[[^\\[\\]]*\\]/', ' ', $name);
     // remove [...]
     $name = preg_replace('/\\([^\\(\\)]*\\)/', ' ', $name);
     // remove (...)
     // remove all file meta data
     $reg = sprintf('/[ .,](?:%s)[ .,]/i', implode('|', $this->meta));
     while (preg_match($reg, $name . ' ')) {
         $name = preg_replace($reg, ' ', $name . ' ');
     }
     $name = str_replace('  ', ' ', $name);
     // remove double spaces
     $name = trim($name, ' .,-');
     return $name;
 }
开发者ID:anime-db,项目名称:catalog-bundle,代码行数:28,代码来源:FilenameCleaner.php

示例5: determineCode

 /**
  * @param string|null $code
  * @param SplFileInfo $file
  * @param string      $suffix
  *
  * @return string|null
  */
 private function determineCode($code, SplFileInfo $file, $suffix)
 {
     if (null !== $code) {
         return $code;
     }
     $candidateFile = new SplFileInfo($file->getPathname() . $suffix, '', '');
     if ($candidateFile->isFile()) {
         return $candidateFile->getContents();
     }
 }
开发者ID:friendsofphp,项目名称:php-cs-fixer,代码行数:17,代码来源:IntegrationCaseFactory.php

示例6: build

 /**
  * Build the site
  */
 public function build()
 {
     $that = $this;
     $this->root = realpath($this->root);
     // First, clean up non-existent files
     if (file_exists($this->outputDir)) {
         $deleteFinder = new Finder();
         $deleteFinder->in($this->outputDir)->filter(function (SplFileInfo $dstFile) {
             // Filter out entries where the source does not exist, or is not the same type
             $srcFile = new SplFileInfo("{$this->root}/{$dstFile->getRelativePathname()}", $dstFile->getRelativePath(), $dstFile->getRelativePathname());
             $old = $dstFile->isDir() && !$srcFile->isDir() || $dstFile->isFile() && !$srcFile->isFile();
             $event = new OldFileEvent($this, $srcFile, $dstFile, $old);
             $this->dispatcher->dispatch(BrancherEvents::OLDFILE, $event);
             return $event->isOld();
         });
         $this->filesystem->remove($deleteFinder);
     }
     // Find all files in root directory
     $renderFinder = new Finder();
     $renderFinder->files()->in(realpath($this->root))->ignoreDotFiles(false);
     array_map([$renderFinder, 'notPath'], array_filter(array_map(function ($exclude) use($that) {
         return $this->filesystem->makePathRelative(realpath($exclude), $that->root);
     }, array_merge($this->excludes, [$this->outputDir]))));
     $this->dispatcher->dispatch(BrancherEvents::SETUP, new SetupEvent($this, $renderFinder));
     // Render every file and dump to output
     $directoryVisited = [];
     /** @var \Symfony\Component\Finder\SplFileInfo $fileInfo */
     foreach ($renderFinder as $fileInfo) {
         $path = $fileInfo->getRelativePath();
         if (!isset($directoryVisited[$path])) {
             $pathObj = new SplFileInfo($fileInfo->getPath(), basename($fileInfo->getRelativePath()), $fileInfo->getRelativePath());
             $event = new DirectoryEnterEvent($this, $pathObj, $this->getSpecialConfig($fileInfo->getPath()));
             $this->dispatcher->dispatch(BrancherEvents::DIRECTORY_ENTER, $event);
             $directoryVisited[$path] = !$event->isShouldSkip();
         }
         if ($directoryVisited[$fileInfo->getRelativePath()] === false) {
             continue;
         }
         if ($fileInfo->getFilename() === $this->specialFile) {
             continue;
         }
         if (substr($this->finfo->file($fileInfo->getPathname()), 0, 4) === 'text') {
             $this->renderFile($fileInfo->getRelativePathname(), $fileInfo->getRelativePathname(), ['path' => $fileInfo->getRelativePathname()]);
         } else {
             // Dump binary files verbatim into output directory
             $this->filesystem->copy($fileInfo->getPathname(), "{$this->outputDir}/{$fileInfo->getRelativePathname()}");
         }
     }
     // Finally, we need to add all remaining templates as resources to Assetic
     // so it will dump the proper files
     /** @var \Twig_Loader_Filesystem $loader */
     $loader = $this->twig->getLoader();
     if ($loader instanceof \Twig_Loader_Filesystem) {
         $resourceFinder = new Finder();
         foreach ($loader->getNamespaces() as $ns) {
             $resourceFinder->in($loader->getPaths($ns));
         }
         /** @var \Symfony\Component\Finder\SplFileInfo $template */
         foreach ($resourceFinder as $template) {
             $this->manager->addResource(new TwigResource($loader, $template->getRelativePathname()), 'twig');
         }
     }
     $this->writer->writeManagerAssets($this->manager);
     $this->dispatcher->dispatch(BrancherEvents::TEARDOWN, new TeardownEvent($this));
 }
开发者ID:castlepointanime,项目名称:brancher,代码行数:68,代码来源:Brancher.php

示例7:

 function it_should_filter_by_date(SplFileInfo $file1, SplFileInfo $file2)
 {
     $file1->isFile()->willReturn(true);
     $file2->isFile()->willReturn(true);
     $file1->getRealPath()->willReturn($this->tempFile);
     $file2->getRealPath()->willReturn($this->tempFile);
     $file1->getMTime()->willReturn(strtotime('-4 hours'));
     $file2->getMTime()->willReturn(strtotime('-5 days'));
     $result = $this->date('since yesterday');
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection');
     $result->count()->shouldBe(1);
     $files = $result->toArray();
     $files[0]->shouldBe($file1);
 }
开发者ID:kientrunghuynh,项目名称:grumphp,代码行数:14,代码来源:FilesCollectionSpec.php

示例8: moveFile

 /**
  * Move a single file or folder.
  *
  * @param SplFileInfo $file      The file to move.
  *
  * @param string      $targetDir The destination directory.
  *
  * @param bool        $logging   Flag determining if actions shall get logged.
  *
  * @param IOInterface $ioHandler The io handler to log to.
  *
  * @return void
  *
  * @throws \RuntimeException When an unknown file type has been encountered.
  */
 private function moveFile(SplFileInfo $file, $targetDir, $logging, $ioHandler)
 {
     $pathName = $file->getPathname();
     $destinationFile = str_replace($this->tempDir, $targetDir, $pathName);
     // Symlink must(!) be handled first as the isDir() and isFile() checks return true for symlinks.
     if ($file->isLink()) {
         $target = $file->getLinkTarget();
         if ($logging) {
             $ioHandler->write(sprintf('link %s to %s', $target, $destinationFile));
         }
         symlink($target, $destinationFile);
         unlink($pathName);
         return;
     }
     if ($file->isDir()) {
         $permissions = substr(decoct(fileperms($pathName)), 1);
         $this->folders[] = $pathName;
         if (!is_dir($destinationFile)) {
             if ($logging) {
                 $ioHandler->write(sprintf('mkdir %s (permissions: %s)', $pathName, $permissions));
             }
             mkdir($destinationFile, octdec($permissions), true);
         }
         return;
     }
     if ($file->isFile()) {
         $permissions = substr(decoct(fileperms($pathName)), 1);
         if ($logging) {
             $ioHandler->write(sprintf('move %s to %s (permissions: %s)', $pathName, $destinationFile, $permissions));
         }
         copy($pathName, $destinationFile);
         chmod($destinationFile, octdec($permissions));
         unlink($pathName);
         return;
     }
     throw new \RuntimeException(sprintf('Unknown file of type %s encountered for %s', filetype($pathName), $pathName));
 }
开发者ID:tenside,项目名称:core,代码行数:52,代码来源:InstallTask.php

示例9: getAllFiles

 /**
  * Lista carpeta y archivos segun el path ingresado, no recursivo, ordenado por tipo y nombre
  * 
  * @param string $path Ruta de la carpeta o archivo
  * @return array|null Listado de archivos o null si no existe
  */
 public function getAllFiles($path)
 {
     $fullpath = $this->getFullPath() . $path;
     if (file_exists($fullpath)) {
         $file = new \SplFileInfo($fullpath);
         if ($file->isDir()) {
             $r = array();
             // if($path != "/") $r[] = $this->folderParent($path);
             $finder = new Finder();
             $directories = $finder->notName('_thumbs')->notName('web.config')->notName('.htaccess')->depth(0)->sortByType();
             // $directories = $directories->files()->name('*.jpg');
             $directories = $directories->in($fullpath);
             foreach ($directories as $key => $directorie) {
                 $namefile = $directorie->getFilename();
                 if ($directorie->isDir() && $this->validNameFile($namefile, false)) {
                     $t = $this->fileInfo($directorie, $path);
                     if ($t) {
                         $r[] = $t;
                     }
                 } elseif ($directorie->isFile() && $this->validNameFile($namefile)) {
                     $t = $this->fileInfo($directorie, $path);
                     if ($t) {
                         $r[] = $t;
                     }
                 }
             }
             return $r;
         } elseif ($file->isFile()) {
             $t = $this->fileInfo($file, $path);
             if ($t) {
                 return $t;
             } else {
                 $result = array("query" => "BE_GETFILEALL_NOT_LEIBLE", "params" => array());
                 $this->setInfo(array("msg" => $result));
                 if ($this->config['debug']) {
                     $this->_log(__METHOD__ . " - Archivo no leible - {$fullpath}");
                 }
                 return;
             }
         } elseif ($file->isLink()) {
             $result = array("query" => "BE_GETFILEALL_NOT_PERMITIDO", "params" => array());
             $this->setInfo(array("msg" => $result));
             if ($this->config['debug']) {
                 $this->_log(__METHOD__ . " - path desconocido - {$fullpath}");
             }
             return;
         }
     } else {
         $result = array("query" => "BE_GETFILEALL_NOT_EXISTED", "params" => array());
         $this->setInfo(array("msg" => $result));
         if ($this->config['debug']) {
             $this->_log(__METHOD__ . " - No existe el archivo - {$fullpath}");
         }
         return;
     }
 }
开发者ID:guillermomartinez,项目名称:filemanager-php,代码行数:62,代码来源:Filemanager.php

示例10: isFile

 public function isFile()
 {
     return $this->fileInfo->isFile();
 }
开发者ID:phramz,项目名称:doctrine-annotation-scanner,代码行数:4,代码来源:ClassFileInfo.php


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