mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
parent
f80587b493
commit
6aeeb5b2c4
|
@ -7,11 +7,6 @@ namespace Opdavies\GmailFilterBuilder\Service;
|
|||
*/
|
||||
class Addresses
|
||||
{
|
||||
/**
|
||||
* The name of the default directory containing the address files.
|
||||
*/
|
||||
const DIRECTORY_NAME = '.gmail-filters';
|
||||
|
||||
/**
|
||||
* Load addresses from a file.
|
||||
*
|
||||
|
@ -21,7 +16,15 @@ class Addresses
|
|||
*/
|
||||
public static function load($filename = 'my-addresses.php')
|
||||
{
|
||||
if (file_exists($file = (new static())->getDirectoryPath() . $filename)) {
|
||||
$file = (new static())->getDirectoryPaths()
|
||||
->map(function ($path) use ($filename) {
|
||||
return $path . $filename;
|
||||
})
|
||||
->first(function ($file) {
|
||||
return file_exists($file);
|
||||
});
|
||||
|
||||
if ($file) {
|
||||
return include $file;
|
||||
}
|
||||
|
||||
|
@ -29,14 +32,15 @@ class Addresses
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the directory name containing the addresses file.
|
||||
* Get the potential directory names containing the addresses file.
|
||||
*
|
||||
* Defaults to a .gmail-filters directory within the user's home directory.
|
||||
*
|
||||
* @return string
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
protected function getDirectoryPath()
|
||||
protected function getDirectoryPaths()
|
||||
{
|
||||
return getenv('HOME') . DIRECTORY_SEPARATOR . self::DIRECTORY_NAME . DIRECTORY_SEPARATOR;
|
||||
return collect([
|
||||
getenv('HOME') . DIRECTORY_SEPARATOR . '.gmail-filters' . DIRECTORY_SEPARATOR,
|
||||
getenv('HOME') . DIRECTORY_SEPARATOR . '.config/gmail-filters' . DIRECTORY_SEPARATOR,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ class FakeAddresses extends Addresses
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDirectoryPath()
|
||||
protected function getDirectoryPaths()
|
||||
{
|
||||
return __DIR__ . '/../../stubs/addresses/';
|
||||
return collect(__DIR__ . '/../../stubs/addresses/');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue