| 1 |
<?php |
| 2 |
namespace Code_Snippets; |
| 3 |
|
| 4 |
class WordPress_File_System_Adapter implements File_System_Interface { |
| 5 |
private $fs; |
| 6 |
|
| 7 |
public function __construct() { |
| 8 |
if ( ! function_exists( 'WP_Filesystem' ) ) { |
| 9 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 10 |
} |
| 11 |
WP_Filesystem(); |
| 12 |
global $wp_filesystem; |
| 13 |
$this->fs = $wp_filesystem; |
| 14 |
} |
| 15 |
|
| 16 |
public function put_contents( string $path, string $contents, $chmod ) { |
| 17 |
return $this->fs->put_contents( $path, $contents, $chmod ); |
| 18 |
} |
| 19 |
|
| 20 |
public function exists( string $path ): bool { |
| 21 |
return $this->fs->exists( $path ); |
| 22 |
} |
| 23 |
|
| 24 |
public function delete( $file, $recursive = false, $type = false ): bool { |
| 25 |
return $this->fs->delete( $file, $recursive, $type ); |
| 26 |
} |
| 27 |
|
| 28 |
public function is_dir( string $path ): bool { |
| 29 |
return $this->fs->is_dir( $path ); |
| 30 |
} |
| 31 |
|
| 32 |
public function mkdir( string $path, $chmod ) { |
| 33 |
return $this->fs->mkdir( $path, $chmod ); |
| 34 |
} |
| 35 |
|
| 36 |
public function rmdir( string $path, bool $recursive = false ): bool { |
| 37 |
return $this->fs->rmdir( $path, $recursive ); |
| 38 |
} |
| 39 |
|
| 40 |
public function chmod( string $path, $chmod ): bool { |
| 41 |
return $this->fs->chmod( $path, $chmod ); |
| 42 |
} |
| 43 |
|
| 44 |
public function is_writable( string $path ): bool { |
| 45 |
return $this->fs->is_writable( $path ); |
| 46 |
} |
| 47 |
} |
| 48 |
|