Move Addresses into Service

This commit is contained in:
Oliver Davies 2018-08-21 08:42:35 +01:00
parent 1ce1139008
commit 7b2ffc5b55
2 changed files with 4 additions and 4 deletions

42
src/Service/Addresses.php Normal file
View file

@ -0,0 +1,42 @@
<?php
namespace Opdavies\GmailFilterBuilder\Service;
/**
* A service 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;
}
}