| 1 |
<?php |
| 2 |
namespace Dudlewebs\WPMCS; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
/** |
| 7 |
* Removes write/enumeration capability from a vendor stream wrapper class — |
| 8 |
* `use`d by ReadOnlyS3StreamWrapper and ReadOnlyGcsStreamWrapper, each still |
| 9 |
* extending its own real vendor parent for read support. |
| 10 |
* |
| 11 |
* @since 1.4.3 |
| 12 |
*/ |
| 13 |
trait ReadOnlyStreamWrapperTrait { |
| 14 |
public function stream_open($path, $mode, $options, &$opened_path) { |
| 15 |
if (!in_array($mode, ['r', 'rb'], true)) { |
| 16 |
return false; |
| 17 |
} |
| 18 |
// parent:: resolves to whichever vendor class the using class actually extends. |
| 19 |
return parent::stream_open($path, $mode, $options, $opened_path); |
| 20 |
} |
| 21 |
|
| 22 |
public function unlink($path) { |
| 23 |
return false; |
| 24 |
} |
| 25 |
|
| 26 |
public function rename($path_from, $path_to) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
|
| 30 |
public function mkdir($path, $mode, $options) { |
| 31 |
return false; |
| 32 |
} |
| 33 |
|
| 34 |
public function rmdir($path, $options) { |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
public function stream_metadata($path, $option, $value) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
/** dir_readdir()/dir_closedir()/dir_rewinddir() need no override — PHP never reaches them once opendir() itself fails. */ |
| 43 |
public function dir_opendir($path, $options) { |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
/** Defense in depth — stream_open()'s mode check should already make this unreachable. */ |
| 48 |
public function stream_write($data) { |
| 49 |
return 0; |
| 50 |
} |
| 51 |
} |
| 52 |
|