public static function isDrupal($directory, $depth = '< 2')
    {
        if (!is_dir($directory)) {
            return false;
        }

        $finder = new Finder();

        // Look for at least one Drush make file.
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->exclude(['node_modules', 'vendor'])
               ->name('project.make*')
               ->name('drupal-org.make*');
        foreach ($finder as $file) {
            return true;
        }

        // Check whether there is an index.php file whose first few lines
        // contain the word "Drupal".
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->name('index.php');
        foreach ($finder as $file) {
            $f = fopen($file, 'r');
            $beginning = fread($f, 3178);
            fclose($f);
            if (strpos($beginning, 'Drupal') !== false) {
                return true;
            }
        }

        // Check whether there is a composer.json file requiring Drupal core.
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->name('composer.json');
        foreach ($finder as $file) {
            $composerJson = json_decode(file_get_contents($file), true);
            if (isset($composerJson['require']['drupal/core'])
                || isset($composerJson['require']['drupal/phing-drush-task'])) {
                return true;
            }
        }

        return false;
    }
public static function isDrupal($directory, $depth = '< 2')
    {
        if (!is_dir($directory)) {
            return false;
        }

        $finder = new Finder();

        // Look for at least one Drush make file.
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->exclude(['node_modules', 'vendor'])
               ->name('project.make*')
               ->name('drupal-org.make*');
        foreach ($finder as $file) {
            return true;
        }

        // Check whether there is an index.php file whose first few lines
        // contain the word "Drupal".
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->name('index.php');
        foreach ($finder as $file) {
            $f = fopen($file, 'r');
            $beginning = fread($f, 3178);
            fclose($f);
            if (strpos($beginning, 'Drupal') !== false) {
                return true;
            }
        }

        // Check whether there is a composer.json file requiring Drupal core.
        $finder->in($directory)
               ->files()
               ->depth($depth)
               ->name('composer.json');
        foreach ($finder as $file) {
            $composerJson = json_decode(file_get_contents($file), true);
            if (isset($composerJson['require']['drupal/core'])
                || isset($composerJson['require']['drupal/phing-drush-task'])) {
                return true;
            }
        }

        return false;
    }
public static function isDrupal ( $ directory , $ depth = '< 2' ) { if ( ! is_dir ( $ directory ) ) { return false ; } $ finder = new Finder ( ) ; // Look for at least one Drush make file. $ finder -> in ( $ directory ) -> files ( ) -> depth ( $ depth ) -> exclude ( [ 'node_modules' , 'vendor' ] ) -> name ( 'project.make*' ) -> name ( 'drupal-org.make*' ) ; foreach ( $ finder as $ file ) { return true ; } // Check whether there is an index.php file whose first few lines // contain the word "Drupal". $ finder -> in ( $ directory ) -> files ( ) -> depth ( $ depth ) -> name ( 'index.php' ) ; foreach ( $ finder as $ file ) { $ f = fopen ( $ file , 'r' ) ; $ beginning = fread ( $ f , 3178 ) ; fclose ( $ f ) ; if ( strpos ( $ beginning , 'Drupal' ) !== false ) { return true ; } } // Check whether there is a composer.json file requiring Drupal core. $ finder -> in ( $ directory ) -> files ( ) -> depth ( $ depth ) -> name ( 'composer.json' ) ; foreach ( $ finder as $ file ) { $ composerJson = json_decode ( file_get_contents ( $ file ) , true ) ; if ( isset ( $ composerJson [ 'require' ] [ 'drupal/core' ] ) || isset ( $ composerJson [ 'require' ] [ 'drupal/phing-drush-task' ] ) ) { return true ; } } return false ; }
Detect if there are any Drupal applications in a folder.

@param string $directory
@param mixed  $depth

@return bool
Detect if there are any Drupal applications in a folder .