Skip to content

Commit

Permalink
feat: add getFile() method
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jul 30, 2023
1 parent e99b80c commit ea94430
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions RockMigrations.module.php
Expand Up @@ -1927,6 +1927,28 @@ public function getFieldtype($type)
return false;
}

/**
* Get file from folders
*
* Usage:
* $rm->getFile('foo.latte', [
* '/folder1',
* '/folder2',
* ]);
*
* Returns the first file found, eg
* /path/to/pw/folder1/foo.latte
*/
public function getFile(string $file, array $folders): string|false
{
$root = $this->wire->config->paths->root;
foreach ($folders as $dir) {
$path = $this->path("$root/$dir/$file");
if (is_file($path)) return $path;
}
return false;
}

/**
* Get language
* Returns FALSE if language is not found
Expand Down

0 comments on commit ea94430

Please sign in to comment.