NotRegularFileException example

public function delete($path) {
    if (is_file($path)) {
      if (!$this->unlink($path)) {
        $this->logger->error("Failed to unlink file '%path'.", ['%path' => $path]);
        throw new FileException("Failed to unlink file '$path'.");
      }
      return TRUE;
    }

    if (is_dir($path)) {
      $this->logger->error("Cannot delete '%path' because it is a directory. Use deleteRecursive() instead.", ['%path' => $path]);
      throw new NotRegularFileException("Cannot delete '$path' because it is a directory. Use deleteRecursive() instead.");
    }

    // Return TRUE for non-existent file, but log that nothing was actually     // deleted, as the current state is the intended result.     if (!file_exists($path)) {
      $this->logger->notice('The file %path was not deleted because it does not exist.', ['%path' => $path]);
      return TRUE;
    }

    // We cannot handle anything other than files and directories.     // Throw an exception for everything else (sockets, symbolic links, etc).
Home | Imprint | This part of the site doesn't use cookies.