/** * Creates a file on the filesystem and returns an object representing it. * * This operation will be reverted by a filesystem transaction being rolled back. * * @throws fValidationException When no file was specified or the file already exists * * @param string $file_path The path to the new file * @param string $contents The contents to write to the file, must be a non-NULL value to be written * @return fFile */ public static function create($file_path, $contents) { if (empty($file_path)) { throw new fValidationException('No filename was specified'); } if (file_exists($file_path)) { throw new fValidationException('The file specified, %s, already exists', $file_path); } $directory = fFilesystem::getPathInfo($file_path, 'dirname'); if (!is_writable($directory)) { throw new fEnvironmentException('The file path specified, %s, is inside of a directory that is not writable', $file_path); } file_put_contents($file_path, $contents); $file = new fFile($file_path); fFilesystem::recordCreate($file); return $file; }
/** * Creates a directory on the filesystem and returns an object representing it * * The directory creation is done recursively, so if any of the parent * directories do not exist, they will be created. * * This operation will be reverted by a filesystem transaction being rolled back. * * @throws fValidationException When no directory was specified, or the directory already exists * * @param string $directory The path to the new directory * @param numeric $mode The mode (permissions) to use when creating the directory. This should be an octal number (requires a leading zero). This has no effect on the Windows platform. * @return fDirectory */ public static function create($directory, $mode = 0777) { if (empty($directory)) { throw new fValidationException('No directory name was specified'); } if (file_exists($directory)) { throw new fValidationException('The directory specified, %s, already exists', $directory); } $parent_directory = fFilesystem::getPathInfo($directory, 'dirname'); if (!file_exists($parent_directory)) { fDirectory::create($parent_directory, $mode); } if (!is_writable($parent_directory)) { throw new fEnvironmentException('The directory specified, %s, is inside of a directory that is not writable', $directory); } mkdir($directory, $mode); $directory = new fDirectory($directory); fFilesystem::recordCreate($directory); return $directory; }