/** * * Returns the verified storage folder. If it does not exists, it is created. * * @return \Mbcraft\Piol\Dir the directory, as a \Mbcraft\Piol\Dir instance, pointing to the verified storage. * @throws \Mbcraft\Piol\IOException if the storage root does not exists or is not valid. * * @api */ public static function getProtectedStorage() { $protected_storage_dir = new Dir(self::$storage_root); if (!$protected_storage_dir->exists()) { throw new IOException("The storage folder does not exist : " . self::$storage_root); } if (!$protected_storage_dir->isWritable()) { throw new IOException("The storage folder is not readable and writable : " . self::$storage_root); } $results = $protected_storage_dir->listElements(); if (count($results[0]) == 0 && count($results[1]) <= 1) { if ($protected_storage_dir->isEmpty()) { $protected_storage_dir->newRandomSubdir(); } return $protected_storage_dir->getUniqueSubdir(); } else { throw new IOException("The storage root folder is invalid : it must contain at most just one folder."); } }
private static function get_verified_storage() { $protected_storage_dir = new Dir(self::$storage_root); if (!$protected_storage_dir->exists()) { throw new IOException("La cartella dello storage non esiste : " . self::$storage_root); } if (count($protected_storage_dir->listFiles()) > 1) { throw new IOException("Lo storage non è valido."); } if ($protected_storage_dir->isEmpty()) { $protected_storage_dir->newRandomSubdir(); } return $protected_storage_dir->getSingleSubdir(); }