-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filesystem: Consistent method names, Write streams, WP_Uploaded_Direc…
…tory_Tree_Filesystem
- Loading branch information
Showing
7 changed files
with
470 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace WordPress\Filesystem; | ||
|
||
/** | ||
* A filesystem wrapper that chroot's the filesystem to a specific path. | ||
*/ | ||
class WP_Filesystem_Chroot extends WP_Abstract_Filesystem { | ||
|
||
/** | ||
* @var WP_Abstract_Filesystem | ||
*/ | ||
private $fs; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $root; | ||
|
||
/** | ||
* @param WP_Abstract_Filesystem $fs The filesystem to chroot. | ||
* @param string $root The root path to chroot to. | ||
*/ | ||
public function __construct(WP_Abstract_Filesystem $fs, $root) { | ||
$this->fs = $fs; | ||
$this->root = rtrim($root, '/'); | ||
} | ||
|
||
public function exists($path) { | ||
return $this->fs->exists($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function is_file($path) { | ||
return $this->fs->is_file($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function is_dir($path) { | ||
return $this->fs->is_dir($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function mkdir($path, $options = []) { | ||
return $this->fs->mkdir($this->to_chrooted_path($path), $options); | ||
} | ||
|
||
public function rmdir($path, $options = []) { | ||
return $this->fs->rmdir($this->to_chrooted_path($path), $options); | ||
} | ||
|
||
public function ls($path = '/') { | ||
return $this->fs->ls($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function open_read_stream($path) { | ||
return $this->fs->open_read_stream($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function next_file_chunk() { | ||
return $this->fs->next_file_chunk(); | ||
} | ||
|
||
public function get_file_chunk() { | ||
return $this->fs->get_file_chunk(); | ||
} | ||
|
||
public function get_streamed_file_length() { | ||
return $this->fs->get_streamed_file_length(); | ||
} | ||
|
||
public function get_last_error() { | ||
return $this->fs->get_last_error(); | ||
} | ||
|
||
public function close_read_stream() { | ||
return $this->fs->close_read_stream(); | ||
} | ||
|
||
public function get_contents($path) { | ||
return $this->fs->get_contents($this->to_chrooted_path($path)); | ||
} | ||
|
||
public function put_contents($path, $contents, $options = []) { | ||
return $this->fs->put_contents($this->to_chrooted_path($path), $contents, $options); | ||
} | ||
|
||
private function to_chrooted_path($path) { | ||
return wp_join_paths($this->root, $path); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.