Platformsh\Cli\Local\Toolstack\Drupal::isDrupal PHP Method

isDrupal() public static method

Detect if there are any Drupal applications in a folder.
public static isDrupal ( string $directory, mixed $depth = '< 2' ) : boolean
$directory string
$depth mixed
return boolean
    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)->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;
    }

Usage Example

 public function isEnabled()
 {
     $projectRoot = $this->getProjectRoot();
     if ($projectRoot) {
         return Drupal::isDrupal($projectRoot . '/' . LocalProject::REPOSITORY_DIR);
     }
     return true;
 }
All Usage Examples Of Platformsh\Cli\Local\Toolstack\Drupal::isDrupal