You are here

trait fileExistsOrDirectoryisWritableTrait in Acquia Content Hub 8

Trait for consistency in file checking.

@package Drupal\acquia_contenthub_audit

Hierarchy

1 file declares its use of fileExistsOrDirectoryisWritableTrait
AcquiaContenthubAuditCommands.php in acquia_contenthub_audit/src/Commands/AcquiaContenthubAuditCommands.php

File

acquia_contenthub_audit/src/fileExistsOrDirectoryisWritableTrait.php, line 10

Namespace

Drupal\acquia_contenthub_audit
View source
trait fileExistsOrDirectoryisWritableTrait {

  /**
   * Checks whether directory/file is writable.
   */
  protected function fileExistsOrDirectoryIsWritable(string $file_path) {
    if (!file_exists($file_path) && !is_writable(dirname($file_path))) {
      throw new \Exception(sprintf("The %s directory is not writable.", dirname($file_path)));
    }
    if (file_exists($file_path) && !is_writable($file_path)) {
      throw new \Exception(sprintf("The %s file is not writable.", $file_path));
    }
    return TRUE;
  }

}

Members