Symfony\Component\Finder\Finder::filter PHP Method

filter() public method

The anonymous function receives a \SplFileInfo and must return false to remove files.
See also: CustomFilterIterator
public filter ( Closure $closure ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$closure Closure An anonymous function
return Finder | Symfony\Component\Finder\SplFileInfo[] The current Finder instance
    public function filter(\Closure $closure)
    {
        $this->filters[] = $closure;

        return $this;
    }

Usage Example

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Sync our local folder with the S3 Bucket...');
     $sync = $this->getApplication()->make('operations.s3-sync');
     $sync->sync();
     $output->writeln('Getting the list of files to be processed...');
     $finder = new Finder();
     $finder->files('*.json')->in($this->directories['files_dir'])->sort(function ($a, $b) {
         return strnatcmp($a->getRealPath(), $b->getRealPath());
     });
     if (file_exists($this->directories['last_read_file'])) {
         $lastFile = file_get_contents($this->directories['last_read_file']);
         $finder->filter(function ($file) use($lastFile) {
             if (0 >= strnatcmp($file->getFilename(), $lastFile)) {
                 return false;
             }
             return true;
         });
     }
     $importer = $this->getApplication()->make('operations.file-importer');
     foreach ($finder as $file) {
         $output->writeln('Processing the events from ' . $file->getFilename() . '...');
         $importer->from($file);
         file_put_contents($this->directories['last_read_file'], $file->getFilename());
     }
 }
All Usage Examples Of Symfony\Component\Finder\Finder::filter