mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-09-06 05:25:33 +01:00
parent
bac720c679
commit
d8b10d8f49
4 changed files with 101 additions and 0 deletions
43
src/Service/Partials.php
Normal file
43
src/Service/Partials.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder\Service;
|
||||
|
||||
/**
|
||||
* Load and combine partials from multiple files.
|
||||
*/
|
||||
class Partials
|
||||
{
|
||||
/**
|
||||
* Load partials from a directory.
|
||||
*
|
||||
* @param string $directoryName The name of the directory containing the partials.
|
||||
*
|
||||
* @return array The loaded filters.
|
||||
*/
|
||||
public static function load($directoryName = 'filters')
|
||||
{
|
||||
$files = (new static())->getFilePattern($directoryName);
|
||||
|
||||
return collect(glob($files))
|
||||
->map(function (string $filename) {
|
||||
return include $filename;
|
||||
})
|
||||
->flatten(1)
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the glob pattern to load partials from the directory.
|
||||
*
|
||||
* Assumes it is always relative to the current directory, and that the
|
||||
* filters are always in files with a .php extension.
|
||||
*
|
||||
* @param string $directoryName The name of the directory.
|
||||
*
|
||||
* @return string The full path.
|
||||
*/
|
||||
protected function getFilePattern(string $directoryName)
|
||||
{
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . $directoryName . DIRECTORY_SEPARATOR . '/*.php';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue