Airship\Cabin\Bridge\Blueprint\Files::dirExists PHP Method

dirExists() public method

Does the directory already exist?
public dirExists ( null $parent = null, string $cabin = '', string $dirName = '' ) : boolean
$parent null
$cabin string
$dirName string
return boolean
    public function dirExists($parent = null, string $cabin = '', string $dirName = '') : bool
    {
        if (empty($parent)) {
            return $this->db->exists('SELECT
                     count(*)
                 FROM
                     airship_dirs
                 WHERE
                         parent IS NULL
                     AND name = ?
                     AND cabin = ?', $dirName, $cabin);
        }
        return $this->db->exists('SELECT
                 count(*)
             FROM
                 airship_dirs
             WHERE
                     parent = ?
                 AND name = ?
                 AND cabin = ?', $parent, $dirName, $cabin);
    }

Usage Example

Example #1
0
 /**
  * Create a new directory for file uploads
  *
  * @param int $directoryId
  * @param string $cabin
  * @param array $post
  * @return array
  */
 protected function createDir($directoryId = null, string $cabin = '', array $post = []) : array
 {
     if (!\array_key_exists('directory', $post)) {
         return ['status' => 'ERROR', 'message' => 'Directory names cannot be empty'];
     }
     if (!$this->files->isValidName($post['directory'])) {
         return ['status' => 'ERROR', 'message' => 'Invalid directory name'];
     }
     if ($this->files->dirExists($directoryId, $cabin, $post['directory'])) {
         return ['status' => 'ERROR', 'message' => 'This directory already exists'];
     }
     if ($this->files->createDirectory($directoryId, $cabin, $post['directory'])) {
         return ['status' => 'SUCCESS', 'message' => 'This directory has been created sucessfully'];
     }
     return ['status' => 'UNKNOWN', 'message' => 'An unknown error has occurred.'];
 }