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);
     }
 }