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

ensureDirExists() public method

Programmatically ensure that the directory exists.
public ensureDirExists ( string $absolutePath, string $cabin = 'Hull' ) : boolean
$absolutePath string
$cabin string
return boolean
    public function ensureDirExists(string $absolutePath, string $cabin = 'Hull') : bool
    {
        $this->db->beginTransaction();
        $parent = null;
        $pieces = \Airship\chunk($absolutePath, '/');
        while (!empty($pieces)) {
            $piece = \array_shift($pieces);
            if (empty($piece)) {
                continue;
            }
            if (empty($parent)) {
                $dir = $this->db->row('SELECT
                         *
                     FROM
                         airship_dirs
                     WHERE
                             parent IS NULL
                         AND name = ?
                         AND cabin = ?', $piece, $cabin);
            } else {
                $dir = $this->db->row('SELECT
                         *
                     FROM
                         airship_dirs
                     WHERE
                             parent = ?
                         AND name = ?
                         AND cabin = ?', $parent, $piece, $cabin);
            }
            // Did we get something?
            if (empty($dir)) {
                $parent = $this->db->insertGet('airship_dirs', ['cabin' => $cabin, 'parent' => $parent, 'name' => $piece], 'directoryid');
            } else {
                $parent = (int) $dir['directoryid'];
            }
        }
        return $this->db->commit();
    }