Add Addresses class

Fixes #11
This commit is contained in:
Oliver Davies 2018-08-20 14:03:55 +01:00
parent 3f9d4d081b
commit b63ebb59b3

42
src/Helpers/Addresses.php Normal file
View 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;
}
}