/**
  * Checks whether the given directory exists and is writable.
  *
  * @param string $directory The directory to check
  * @param bool $createIfNotExists If TRUE, the directory will be created
  * @param int $directoryPermissions The permissions to apply to the directory when being created
  * @throws \Ableron\Core\Exception\SystemException In case the directory is not writable
  * @return void
  */
 public static function checkDirectoryIsWritable(string $directory, bool $createIfNotExists = true, int $directoryPermissions = 0775)
 {
     // create directory if needed
     if ($createIfNotExists && !FileUtil::createDirectoryIfNotExists($directory, $directoryPermissions)) {
         throw new SystemException(sprintf('Directory "%s" does not exist and could not be created', $directory), 0, E_USER_ERROR, __FILE__, __LINE__);
     }
     // check whether directory is writable
     if (!is_writable($directory)) {
         throw new SystemException(sprintf('Directory "%s" is not writable', $directory), 0, E_USER_ERROR, __FILE__, __LINE__);
     }
 }
Example #2
0
 /**
  * Tests whether removeDirectory() works correctly.
  *
  * @return void
  */
 public function testRemoveDirectory()
 {
     FileUtil::createDirectoryIfNotExists(ABLERON_TEMP_DIR . '/testRemoveDirectory/foo/bar/baz');
     $file = new File(ABLERON_TEMP_DIR . '/testRemoveDirectory/foo/bar/bar.txt');
     $file->append('foobar');
     $this->assertTrue(is_file($file->getPath()));
     FileUtil::removeDirectory(ABLERON_TEMP_DIR . '/testRemoveDirectory');
     $this->assertFalse(is_file($file->getPath()));
     $this->assertFalse(is_dir(ABLERON_TEMP_DIR . '/testRemoveDirectory'));
 }