name = $name; return $file; } public final function setType($type) { $this->type = $type; } public final function getPath() { if (!defined('LAZER_DATA_PATH')) { throw new LazerException('Please define constant LAZER_DATA_PATH (check README.md)'); } else if (!empty($this->type)) { return LAZER_DATA_PATH . $this->name . '.' . $this->type . '.json'; } else { throw new LazerException('Please specify the type of file in class: ' . __CLASS__); } } public final function get($assoc = false) { return json_decode(file_get_contents($this->getPath()), $assoc); } public final function put($data) { return file_put_contents($this->getPath(), json_encode($data)); } public final function exists() { return file_exists($this->getPath()); } public final function remove() { $type = ucfirst($this->type); if ($this->exists()) { if (unlink($this->getPath())) return TRUE; throw new LazerException($type . ': Deleting failed'); } throw new LazerException($type . ': File does not exists'); } }