clphillips / seedling

A framework agnostic database seeding and fixture library
MIT License
0 stars 0 forks source link

Use GlobIterator in Fixture::fetchFixtures #32

Open clphillips opened 9 years ago

clphillips commented 9 years ago

Look into extending GlobIterator to improve performance in Fixture::fetchFixtures. We could have something like:

    protected function fetchFixtures(array $fixtures = null)
    {
        return new FixtureIterator($this->config['location'] . "/*.php", $fixtures);
    }

FixtureIterator would extend GlobIterator (which indirectly extends DirectoryIterator) and would handle filtering out undesired fixtures.

clphillips commented 8 years ago

Could use PHP 5.5 generator instead of implementing FixtureIterator class. Obviously requires increasing PHP requirement.

    protected function fetchFixtures(array $fixtures = null, \DirectoryIterator $files = null)
    {
        $files = $files ?: new \GlobIterator($this->config['location'] . "/*.php");

        foreach ($files as $filename => $file) {
            if (null === $fixtures || in_array(basename($filename, '.php'), $fixtures)) {
                yield $filename;
            }
        }
    }
clphillips commented 8 years ago

Glob pattern should be provided in the config. Update config to use either location or pattern, where pattern is a globbing pattern.