Updated FileKey with setters
This commit is contained in:
		@@ -15,20 +15,10 @@ class FileKey implements KeyInterface
 | 
				
			|||||||
     * @param string $proj
 | 
					     * @param string $proj
 | 
				
			||||||
     * @param boolean $create
 | 
					     * @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)) {
 | 
					        $this->setPathname($pathname, $create);
 | 
				
			||||||
            if (!$create) {
 | 
					        $this->setProjectIdentifier($proj);
 | 
				
			||||||
                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);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@@ -41,6 +31,20 @@ class FileKey implements KeyInterface
 | 
				
			|||||||
        return $this->pathname;
 | 
					        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
 | 
					     * Get the project identifier. Not guaranteed to be printable
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@@ -51,6 +55,17 @@ class FileKey implements KeyInterface
 | 
				
			|||||||
        return $this->proj;
 | 
					        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
 | 
					     * Get the key value
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user