public function make($object, $recursive = true)
 {
     $this->checkDirectory();
     if (!$object) {
         $this->safeClean();
         return $this->directory;
     }
     $realDirectory = null;
     if (is_link($this->directory)) {
         $realDirectory = readlink($this->directory);
         if ($realDirectory === false) {
             throw new WrongStateException('invalid pointer: ' . $this->directory);
         }
     }
     $reversePath = $this->identityMap->reverseLookup($object);
     if (!$reversePath && is_link($this->directory)) {
         throw new WrongStateException('you must always store your object somewhere ' . 'before you going to update pointer ' . $this->directory);
     }
     if ($reversePath && file_exists($this->directory) && !$realDirectory && $this->directory != $reversePath) {
         throw new WrongStateException('you should relocate object ' . $this->directory . ' to ' . $reversePath . ' by yourself.' . ' cannot replace object with a link');
     }
     if ($reversePath && (!file_exists($this->directory) || $realDirectory)) {
         if (!$realDirectory || $realDirectory != $reversePath) {
             $this->safeClean();
             $status = symlink($reversePath, $this->directory);
             if ($status !== true) {
                 throw new WrongStateException('error creating symlink');
             }
         }
         return $reversePath;
     }
     $result = parent::make($object, $recursive);
     $this->identityMap->bind($result, $object);
     return $result;
 }
Esempio n. 2
0
 public function destroy()
 {
     $this->dirBuilder->remove();
 }