LazyRecord\Schema\SchemaFinder::findByPaths PHP Method

findByPaths() public method

public findByPaths ( array $paths )
$paths array
    public function findByPaths(array $paths)
    {
        $this->logger->debug('Finding schemas in (' . implode(', ', $paths) . ')');
        $files = array();
        foreach ($paths as $path) {
            $this->logger->debug('Finding schemas in ' . $path);
            if (is_file($path)) {
                $this->logger->debug('Loading schema: ' . $path);
                require_once $path;
                $files[] = $path;
            } elseif (is_dir($path)) {
                $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::FOLLOW_SYMLINKS), RecursiveIteratorIterator::SELF_FIRST);
                foreach ($rii as $fi) {
                    if (substr($fi->getFilename(), -10) == 'Schema.php') {
                        $this->logger->debug('Loading schema: ' . $fi->getPathname());
                        require_once $fi->getPathname();
                        $files[] = $path;
                    }
                }
            }
        }
        return $files;
    }

Usage Example

 public function testSchemaFinder()
 {
     $finder = new SchemaFinder();
     $finder->findByPaths(['src', 'tests']);
     $schemas = SchemaLoader::loadDeclaredSchemas();
     $this->assertNotEmpty($schemas);
     foreach ($schemas as $schema) {
         $this->assertInstanceOf('LazyRecord\\Schema\\DeclareSchema', $schema);
     }
 }