From d6aacd841fba1affb9819cef163e7b26225dc82d Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Mon, 16 Apr 2018 00:41:13 +0200 Subject: [PATCH] Updated FileKey with setters --- src/Key/FileKey.php | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Key/FileKey.php b/src/Key/FileKey.php index f8181d4..9790ebe 100644 --- a/src/Key/FileKey.php +++ b/src/Key/FileKey.php @@ -15,20 +15,10 @@ class FileKey implements KeyInterface * @param string $proj * @param boolean $create */ - public function __construct(string $pathname, $proj="\0", bool $create=false) + public function __construct(string $pathname, $proj="\0", bool $create = false) { - if (!file_exists($pathname)) { - if (!$create) { - throw new \RuntimeException("Path does not exist: {$pathname}"); - } - if (!is_dir(dirname($pathname))) { - throw new \RuntimeException("The directory ".dirname($pathname)." does not exist"); - } - touch($pathname); - } - - $this->pathname = $pathname; - $this->proj = substr($proj,0,1); + $this->setPathname($pathname, $create); + $this->setProjectIdentifier($proj); } /** @@ -41,6 +31,20 @@ class FileKey implements KeyInterface return $this->pathname; } + public function setPathname(string $pathname, bool $create = false) + { + if (!file_exists($pathname)) { + if (!$create) { + throw new \RuntimeException("Path does not exist: {$pathname}"); + } + if (!is_dir(dirname($pathname))) { + throw new \RuntimeException("The directory ".dirname($pathname)." does not exist"); + } + touch($pathname); + } + $this->pathname = $pathname; + } + /** * Get the project identifier. Not guaranteed to be printable * @@ -51,6 +55,17 @@ class FileKey implements KeyInterface return $this->proj; } + /** + * Set the project identifier + * + * @param string $proj + * @return void + */ + public function setProjectIdentifier(string $proj) + { + $this->proj = substr($proj, 0, 1); + } + /** * Get the key value *