Updated FileKey with setters

This commit is contained in:
Chris 2018-04-16 00:41:13 +02:00
parent 31634c5054
commit d6aacd841f

View File

@ -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
*