@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3abstract class PhabricatorFileStorageFormat
4 extends Phobject {
5
6 private $file;
7
8 final public function setFile(PhabricatorFile $file) {
9 $this->file = $file;
10 return $this;
11 }
12
13 final public function getFile() {
14 if (!$this->file) {
15 throw new PhutilInvalidStateException('setFile');
16 }
17 return $this->file;
18 }
19
20 abstract public function getStorageFormatName();
21
22 abstract public function newReadIterator($raw_iterator);
23 abstract public function newWriteIterator($raw_iterator);
24
25 public function newFormatIntegrityHash() {
26 return null;
27 }
28
29 public function newStorageProperties() {
30 return array();
31 }
32
33 public function canGenerateNewKeyMaterial() {
34 return false;
35 }
36
37 public function generateNewKeyMaterial() {
38 throw new PhutilMethodNotImplementedException();
39 }
40
41 public function canCycleMasterKey() {
42 return false;
43 }
44
45 public function cycleStorageProperties() {
46 throw new PhutilMethodNotImplementedException();
47 }
48
49 public function selectMasterKey($key_name) {
50 throw new Exception(
51 pht(
52 'This storage format ("%s") does not support key selection.',
53 $this->getStorageFormatName()));
54 }
55
56 final public function getStorageFormatKey() {
57 return $this->getPhobjectClassConstant('FORMATKEY');
58 }
59
60 final public static function getAllFormats() {
61 return id(new PhutilClassMapQuery())
62 ->setAncestorClass(self::class)
63 ->setUniqueMethod('getStorageFormatKey')
64 ->execute();
65 }
66
67 final public static function getFormat($key) {
68 $formats = self::getAllFormats();
69 return idx($formats, $key);
70 }
71
72 final public static function requireFormat($key) {
73 $format = self::getFormat($key);
74
75 if (!$format) {
76 throw new Exception(
77 pht(
78 'No file storage format with key "%s" exists.',
79 $key));
80 }
81
82 return $format;
83 }
84
85}