Updated FileKey with setters
This commit is contained in:
parent
31634c5054
commit
d6aacd841f
@ -17,18 +17,8 @@ class FileKey implements KeyInterface
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user