mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-03-13 05:26:57 +00:00
parent
3f9d4d081b
commit
b63ebb59b3
42
src/Helpers/Addresses.php
Normal file
42
src/Helpers/Addresses.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\GmailFilterBuilder\Helpers;
|
||||
|
||||
/**
|
||||
* A helper class for loading addresses from separate files.
|
||||
*/
|
||||
class Addresses
|
||||
{
|
||||
/**
|
||||
* The name of the default directory containing the address files.
|
||||
*/
|
||||
const DIRECTORY_NAME = '.gmail-filters';
|
||||
|
||||
/**
|
||||
* Load addresses from a file.
|
||||
*
|
||||
* @param string $filename The filename to load.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function load($filename = 'my-addresses.php')
|
||||
{
|
||||
if (file_exists($file = (new static())->getDirectoryPath() . $filename)) {
|
||||
return include $file;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory name containing the addresses file.
|
||||
*
|
||||
* Defaults to a .gmail-filters directory within the user's home directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDirectoryPath()
|
||||
{
|
||||
return getenv('HOME') . DIRECTORY_SEPARATOR . self::DIRECTORY_NAME . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue