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