class-layer.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WordPress\Filesystem\Layer; |
| 4 | |
| 5 | use WordPress\ByteStream\ReadStream\ByteReadStream; |
| 6 | use WordPress\ByteStream\WriteStream\ByteWriteStream; |
| 7 | use WordPress\Filesystem\Filesystem; |
| 8 | |
| 9 | /** |
| 10 | * Layer base-class that delegates all calls to another filesystem. |
| 11 | * Every Filesystem layer can extend this class and override just the methods |
| 12 | * it needs to change. |
| 13 | */ |
| 14 | class Layer implements Filesystem { |
| 15 | |
| 16 | /** |
| 17 | * @var Filesystem |
| 18 | */ |
| 19 | protected $fs; |
| 20 | |
| 21 | /** |
| 22 | * @param Filesystem $fs The filesystem to delegate to. |
| 23 | */ |
| 24 | public function __construct( Filesystem $fs ) { |
| 25 | $this->fs = $fs; |
| 26 | } |
| 27 | |
| 28 | public function exists( $path ) { |
| 29 | return $this->fs->exists( $path ); |
| 30 | } |
| 31 | |
| 32 | public function is_file( $path ) { |
| 33 | return $this->fs->is_file( $path ); |
| 34 | } |
| 35 | |
| 36 | public function is_dir( $path ) { |
| 37 | return $this->fs->is_dir( $path ); |
| 38 | } |
| 39 | |
| 40 | public function mkdir( $path, $options = array() ) { |
| 41 | return $this->fs->mkdir( $path, $options ); |
| 42 | } |
| 43 | |
| 44 | public function rm( $path, $options = array() ) { |
| 45 | return $this->fs->rm( $path, $options ); |
| 46 | } |
| 47 | |
| 48 | public function rmdir( $path, $options = array() ) { |
| 49 | return $this->fs->rmdir( $path, $options ); |
| 50 | } |
| 51 | |
| 52 | public function ls( $path = '/' ) { |
| 53 | return $this->fs->ls( $path ); |
| 54 | } |
| 55 | |
| 56 | public function open_read_stream( $path ): ByteReadStream { |
| 57 | return $this->fs->open_read_stream( $path ); |
| 58 | } |
| 59 | |
| 60 | public function open_write_stream( $path ): ByteWriteStream { |
| 61 | return $this->fs->open_write_stream( $path ); |
| 62 | } |
| 63 | |
| 64 | public function copy( $source, $destination, $options = array() ) { |
| 65 | return $this->fs->copy( $source, $destination, $options ); |
| 66 | } |
| 67 | |
| 68 | public function rename( $source, $destination, $options = array() ) { |
| 69 | return $this->fs->rename( $source, $destination, $options ); |
| 70 | } |
| 71 | |
| 72 | public function get_contents( $path ) { |
| 73 | return $this->fs->get_contents( $path ); |
| 74 | } |
| 75 | |
| 76 | public function put_contents( $path, $contents, $options = array() ) { |
| 77 | return $this->fs->put_contents( $path, $contents, $options ); |
| 78 | } |
| 79 | |
| 80 | public function get_meta(): array { |
| 81 | return $this->fs->get_meta(); |
| 82 | } |
| 83 | } |
| 84 |