/** * Gets the SHA1 hash of the object * @return sting */ public function getSHA1() { if (!$this->sha1) { $this->sha1 = sha1(\gihp\Parser\File::exportObject($this)); } return $this->sha1; }
public function addObject(\gihp\Object\Internal $object) { $hash = $object->getSHA1(); $dir = $this->path . '/objects/' . substr($hash, 0, 2); if (!is_dir($dir)) { mkdir($dir); } $path = $dir . '/' . substr($hash, 2); if (file_exists($path)) { return true; } $object = \gihp\Parser\File::exportObject($object); $encoded = gzcompress($object); return file_put_contents($path, $encoded); }