php Symfony-Component-Finder-SplFileInfo类(方法)实例源码

下面列出了php Symfony-Component-Finder-SplFileInfo 类(方法)源码代码实例,从而了解它的用法。

作者:hscal    项目:fizl-page   
/**
  * @param      $string
  * @param null $path
  * @return string
  */
 public function parse($string, $path = null)
 {
     $headers = [];
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3);
     if (count($parts) == 3) {
         $string = $parts[0] . "\n" . $parts[2];
         $headers = $this->yaml->parse($parts[1]);
     }
     $file = new SplFileInfo($path, '', '');
     $date = Carbon::createFromTimestamp($file->getMTime());
     $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia');
     $headers['date_modified'] = $date->toDateTimeString();
     if (isset($headers['date'])) {
         try {
             $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString();
         } catch (\InvalidArgumentException $e) {
             $headers['date'] = $headers['date_modified'];
             //dd($e->getMessage());
         }
     } else {
         $headers['date'] = $headers['date_modified'];
     }
     $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers));
     $viewPath = PageHelper::filePathToViewPath($path);
     $cacheKey = "{$viewPath}.headers";
     $this->cache->put($cacheKey, $headers);
     return $string;
 }

作者:webcreat    项目:conveyo   
/**
  * @param \Phar $phar
  * @param SplFileInfo $file
  */
 private function addFile(\Phar $phar, SplFileInfo $file)
 {
     $path = $file->getRelativePathname();
     $content = file_get_contents($file);
     $content = preg_replace('{^#!/usr/bin/env php\\s*}', '', $content);
     $phar->addFromString($path, $content);
 }

作者:jolicod    项目:jan   
/**
  * @dataProvider schemaProvider
  */
 public function testRessources(SplFileInfo $testDirectory)
 {
     // 1. Cleanup generated
     $filesystem = new Filesystem();
     if ($filesystem->exists($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated')) {
         $filesystem->remove($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     }
     $filesystem->mkdir($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     // 2. Generate
     $command = new GenerateCommand();
     $inputArray = new ArrayInput(['--config-file' => $testDirectory->getRealPath() . DIRECTORY_SEPARATOR . '.jane'], $command->getDefinition());
     $command->execute($inputArray, new NullOutput());
     // 3. Compare
     $expectedFinder = new Finder();
     $expectedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'expected');
     $generatedFinder = new Finder();
     $generatedFinder->in($testDirectory->getRealPath() . DIRECTORY_SEPARATOR . 'generated');
     $generatedData = [];
     $this->assertEquals(count($expectedFinder), count($generatedFinder), sprintf('No same number of files for %s', $testDirectory->getRelativePathname()));
     foreach ($generatedFinder as $generatedFile) {
         $generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
     }
     foreach ($expectedFinder as $expectedFile) {
         $this->assertArrayHasKey($expectedFile->getRelativePathname(), $generatedData, sprintf('File %s does not exist for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname()));
         if ($expectedFile->isFile()) {
             $this->assertEquals(file_get_contents($expectedFile->getRealPath()), file_get_contents($generatedData[$expectedFile->getRelativePathname()]), sprintf('File %s does not have the same content for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname()));
         }
     }
 }

作者:survo    项目:remot   
private function processFile(SplFileInfo $path)
 {
     $relativeDirName = dirname(str_replace($this->inPath, '', $path->getPathname()));
     $filenameParts = explode('/', $relativeDirName);
     $pdfDir = array_pop($filenameParts);
     $restaurant = array_pop($filenameParts);
     $outDir = $this->outPath . '/' . $relativeDirName;
     if (!is_dir($outDir)) {
         mkdir($outDir, 0777, true);
     }
     $outFilename = $outDir . '/' . str_replace('.pdf', '-%03d.png', $path->getFilename());
     $convertCommand = "gm convert -density 300 \"{$path->getPathname()}\" -resize '1280x1280>' +profile '*' +adjoin \"{$outFilename}\"";
     $this->output->writeln("Processing {$path->getPathname()}");
     // convert directory
     exec($convertCommand);
     // create csv file
     $finder = new Finder();
     $finder->files()->name('*.png')->in($outDir);
     /** @type SplFileInfo $file */
     $index = 1;
     $this->output->writeln("-- " . $finder->count() . " images");
     foreach ($finder as $file) {
         if (!isset($this->outCsv[$restaurant])) {
             $this->outCsv[$restaurant] = [];
         }
         $this->outCsv[$restaurant][] = ['restaurant' => $restaurant, 'pdf' => $path->getRelativePathname(), 'page' => $index, 'image' => $relativeDirName . '/' . $file->getFilename(), 'folder' => $relativeDirName];
         $index++;
     }
 }

作者:ls    项目:jwap   
/**
  * Create our second level request for posting items
  *
  * @param Api         $api
  * @param SplFileInfo $file
  * @param bool        $method
  */
 public function __construct(Api $api, SplFileInfo $file, $method)
 {
     $data = $api->getResponse()->json();
     parent::__construct($api->getApiKey(), $api->getApiSecret(), $api->getHttps());
     $this->path = sprintf('%s://%s%s', $data['link']['protocol'], $data['link']['address'], $data['link']['path']);
     $this->setGet('key', $data['link']['query']['key'])->setGet('token', $data['link']['query']['token'])->setPost('file', '@' . $file->getPath() . '/' . $file->getFilename());
 }

作者:ta    项目:orc   
/**
  * Convert a blade view into a site page.
  *
  * @param SplFileInfo $file
  *
  * @return void
  */
 public function handle(SplFileInfo $file, $viewsData)
 {
     $this->viewsData = $viewsData;
     $this->file = $file;
     $this->viewPath = $this->getViewPath();
     $this->directory = $this->getDirectoryPrettyName();
     $this->appendViewInformationToData();
     $content = $this->getFileContent();
     $this->filesystem->put(sprintf('%s/%s', $this->prepareAndGetDirectory(), ends_with($file->getFilename(), ['.blade.php', 'md']) ? 'index.html' : $file->getFilename()), $content);
     // copy images to public folder
     foreach ($file->images as $media) {
         $copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}";
         $copyTo = "{$this->directory}/{$media}";
         if (!$this->filesystem->copy($copyFrom, $copyTo)) {
             echo "failed to copy {$media}...\n";
         }
     }
     // copy documents
     foreach ($file->documents as $media) {
         $copyFrom = ORCA_CONTENT_DIR . "/{$file->getRelativePath()}/{$media}";
         $copyTo = "{$this->directory}/{$media}";
         if (!$this->filesystem->copy($copyFrom, $copyTo)) {
             echo "failed to copy {$media}...\n";
         }
     }
 }

作者:henre    项目:MajoraGeneratorBundl   
/**
  * @see ContentModifierInterface::modify()
  */
 public function modify(SplFileInfo $generatedFile, array $data, Inflector $inflector, SplFileInfo $templateFile)
 {
     $options = $this->resolver->resolve($data);
     // retrieve target location
     $targetConfigFilepath = $this->resolveTargetFilePath($options['target'], $generatedFile->getPath());
     $emBundleDefinition = sprintf('
                 %s:
                     type: yml
                     dir: %s
                     prefix: %s
                     alias: %s
                     ', $options['bundle'], $options['relative_schema_directory'], $options['prefix'], $options['alias']);
     $configsFile = new SplFileInfo($targetConfigFilepath, '', '');
     $configsContent = $configsFile->getContents();
     // are configs not already registered ?
     if (strpos($configsContent, trim($emBundleDefinition)) !== false) {
         $this->logger->debug(sprintf('Config file "%s" is already registered into "%s". Abording.', $generatedFile->getFilename(), $targetConfigFilepath));
         return $generatedFile->getContents();
     }
     $this->filesystem->dumpFile($configsFile->getPathname(), str_replace(sprintf('
     entity_managers:
         %s:
             mappings:', $options['em']), sprintf('
     entity_managers:
         %s:
             mappings:%s', $options['em'], $emBundleDefinition), $configsContent));
     $this->logger->info(sprintf('file updated : %s', $configsFile->getPathname()));
     return $generatedFile->getContents();
 }

作者:webcreat    项目:conveyo   
public function put($src, $dest)
 {
     if (false === file_exists($src)) {
         throw new \InvalidArgumentException(sprintf('Resource \'%s\' does not exist', $src));
     }
     if (is_file($src) && is_dir($dest)) {
         $dest = $dest . DIRECTORY_SEPARATOR . basename($src);
     }
     if (is_file($src)) {
         $file = new \SplFileInfo($src);
         $this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_PUT, new TransporterEvent($this, array('dest' => $dest, 'src' => $file->getPathname())));
         $pwd = dirname($dest);
         if (!is_dir($pwd)) {
             $this->mkdir($pwd);
         }
         copy($file->getPathname(), $dest);
     } else {
         if (!$this->exists($dest)) {
             $this->mkdir($dest);
         }
         $finder = new Finder();
         $test = $finder->in($src)->depth('== 0');
         foreach ($test as $file) {
             $this->put(rtrim($src, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file->getFilename(), rtrim($dest, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file->getFilename());
         }
     }
 }

作者:learnosit    项目:learnosity-qt   
public static function readFile($path)
 {
     $file = new SplFileInfo($path, '', '');
     if (!$file->isFile()) {
         throw new Exception('Invalid file. Fail to get file ' . $path);
     }
     return $file;
 }

作者:procoder    项目:admi   
/**
  * @param SplFileInfo $file
  * @return StdClass
  */
 protected function createImageObject(SplFileInfo $file)
 {
     $obj = new StdClass();
     $path = $file->getRelativePathname();
     $obj->url = route('imagecache', ['original', $path]);
     $obj->thumbnail = route('imagecache', ['small', $path]);
     return $obj;
 }

作者:avverti    项目:pronto-framewor   
/**
  * __construct 
  */
 protected function __construct(SplFileInfo $file, $relativePath = null)
 {
     $this->title = Content::filename_to_title($file->getFilename());
     $this->slug = Content::str_to_slug($file->getFilename());
     $relativePath = !is_null($relativePath) && !empty($relativePath) ? $relativePath : $file->getRelativePath();
     $this->path = $relativePath . (ends_with($relativePath, '/') ? '' : '/') . $this->slug;
     $this->file = $file;
 }

作者:consoll    项目:framewor   
/**
  * Get the configuration file nesting path.
  *
  * @param  \Symfony\Component\Finder\SplFileInfo  $file
  * @return string
  */
 private function getConfigurationNesting(SplFileInfo $file)
 {
     $directory = dirname($file->getPathname());
     if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) {
         $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
     }
     return $tree;
 }

作者:jtallan    项目:skimpy-engin   
/**
  * @param SplFileInfo $file
  *
  * @return void
  *
  * @throws InvalidContentFile
  */
 protected function verifyFrontMatterSeparatorExists(SplFileInfo $file)
 {
     $content = $file->getContents();
     $fileName = $file->getFilename();
     if (false === strpos($content, FrontMatter::SEPARATOR)) {
         throw new InvalidContentFile("Missing '---' deliminator in " . $fileName);
     }
 }

作者:bldr-i    项目:frontend-bloc   
/**
  * @param SplFileInfo $file
  *
  * @return string
  */
 private function getFileContents(SplFileInfo $file)
 {
     $content = $file->getContents();
     if ($file->getExtension() === 'js' && substr($content, -1) !== ';') {
         $content .= ';';
     }
     return $content;
 }

作者:notad    项目:framewor   
/**
  * @param \Symfony\Component\Finder\SplFileInfo $file
  * @param string                                $configPath
  *
  * @return string
  */
 protected function getConfigurationNesting(SplFileInfo $file, $configPath)
 {
     $directory = dirname($file->getRealPath());
     if ($tree = trim(str_replace($configPath, '', $directory), DIRECTORY_SEPARATOR)) {
         $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
     }
     return $tree;
 }

作者:spryke    项目:Developmen   
/**
  * @param SplFileInfo $composerJsonFile
  * @param array $bundles
  *
  * @return bool
  */
 protected function shouldSkip(SplFileInfo $composerJsonFile, array $bundles)
 {
     if (!$bundles) {
         return false;
     }
     $folder = $composerJsonFile->getRelativePath();
     return !in_array($folder, $bundles);
 }

作者:opiu    项目:opiu   
/**
  * treatFile
  *
  * @param File $file
  * @param bool $recursive
  * @access private
  * @return File
  */
 private function treatFile(SplFileInfo $file)
 {
     if ($file->isDir()) {
         return $this->fileTransformer->transformToDirectory($file);
     } elseif ($file->isFile()) {
         return $this->fileTransformer->transformToFile($file);
     }
 }

作者:newu    项目:cor   
/**
  * Get the configuration file nesting path.
  *
  * @param  \Symfony\Component\Finder\SplFileInfo  $file
  * @return string
  */
 private function getConfigurationNesting(SplFileInfo $file)
 {
     $directory = $this->normalizePath(dirname($file->getRealPath()));
     $directory = ltrim($directory, $this->userConfigurationPath);
     if ($tree = trim(str_replace(config_path(), '', $directory), DIRECTORY_SEPARATOR)) {
         $tree = str_replace(DIRECTORY_SEPARATOR, '.', $tree) . '.';
     }
     return $tree;
 }

作者:VertexDezig    项目:VertexDezig   
public static function checkIfImage($path)
 {
     $file = new \SplFileInfo($path);
     $ex = $file->getExtension();
     if ($ex === "png" || $ex === "gif" || $ex === 'bmp' || $ex === "jpeg" || $ex === "jpg") {
         return true;
     }
     return false;
 }

作者:spryke    项目:Prope   
/**
  * @param \Symfony\Component\Finder\SplFileInfo $schemaFile
  * @param array $schemaFiles
  *
  * @return array
  */
 private function addSchemaToList(SplFileInfo $schemaFile, array $schemaFiles)
 {
     $fileIdentifier = $schemaFile->getFilename();
     if (!isset($schemaFiles[$fileIdentifier])) {
         $schemaFiles[$fileIdentifier] = [];
     }
     $schemaFiles[$fileIdentifier][] = $schemaFile;
     return $schemaFiles;
 }


问题


面经


文章

微信
公众号

扫码关注公众号