PHP code example of dflydev / symfony-finder-factory

1. Go to this page and download the library: Download dflydev/symfony-finder-factory library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dflydev / symfony-finder-factory example snippets



namespace My;

use Dflydev\Symfony\FinderFactory;
use Dflydev\Symfony\FinderFactoryInterface;

class Service
{
    public function __construct(FinderFactoryInterface $finderFactory = null)
    {
        $this->finderFactory = $finderFactory ?: new FinderFactory;
    }

    public function doThingsWithTempFiles()
    {
        $finder = $this->finderFactory->create();

        $finder->in(sys_get_temp_dir());
        
        // do stuff with temp files
    }
}


namespace My;

use Dflydev\Symfony\FinderFactory;
use Dflydev\Symfony\FinderFactoryInterface;
use Symfony\Component\Finder\Finder;

class Service
{
    public function __construct(FinderFactoryInterface $finderFactory = null)
    {
        $this->finderFactory = $finderFactory ?: new FinderFactory;
    }

    public function findTmpFilesNew()
    {
        // Potential for mocked injected Finder Factory to return
        // a mocked Finder instance.
        $finder = $this->finderFactory->create();

        return $finder->in(sys_get_temp_dir());
    }

    public function findTmpFilesOld()
    {
        // Difficult to Mock
        $finder = new Finder;

        return $finder->in(sys_get_temp_dir());
    }
}