Newscoop\Storage::deleteItem PHP 메소드

deleteItem() 공개 메소드

Delete item
public deleteItem ( string $key ) : void
$key string
리턴 void
    public function deleteItem($key)
    {
        $path = $this->getPath($key, TRUE);
        if (!$path) {
            throw new \InvalidArgumentException($key, self::ERROR_NOT_FOUND);
        }
        if (is_dir($path)) {
            foreach ($this->listItems($key) as $item) {
                throw new \InvalidArgumentException($key, self::ERROR_NOT_EMPTY);
            }
            rmdir($path);
        } else {
            unlink($path);
        }
    }

Usage Example

예제 #1
0
 /**
  * Delete item
  *
  * @param string $key
  * @return void
  * @throws InvalidArgumentException
  */
 public function deleteItem($key)
 {
     if ($this->repository->isUsed($key) || $this->storage->isUsed($key)) {
         throw new \InvalidArgumentException(sprintf("The template object %s is in use and can not be deleted.", $key));
     }
     try {
         $this->storage->deleteItem($key);
         $this->repository->delete($key);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf("Can't remove non empty directory '%s'", basename($key)), $e->getCode(), $e);
     }
 }