Merge "Change php extract() to explicit code"
[lhc/web/wiklou.git] / includes / Storage / BlobStore.php
1 <?php
2 /**
3 * Service for loading and storing data blobs.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 namespace MediaWiki\Storage;
24
25 /**
26 * Service for loading and storing data blobs.
27 *
28 * @note This was written to act as a drop-in replacement for the corresponding
29 * static methods in Revision.
30 *
31 * @since 1.31
32 */
33 interface BlobStore {
34
35 /**
36 * Hint key for use with storeBlob, indicating the general role the block
37 * takes in the application. For instance, it should be "page-content" if
38 * the blob represents a Content object.
39 */
40 const DESIGNATION_HINT = 'designation';
41
42 /**
43 * Hint key for use with storeBlob, indicating the page the blob is associated with.
44 * This may be used for sharding.
45 */
46 const PAGE_HINT = 'page_id';
47
48 /**
49 * Hint key for use with storeBlob, indicating the slot the blob is associated with.
50 * May be relevant for reference counting.
51 */
52 const ROLE_HINT = 'role_name';
53
54 /**
55 * Hint key for use with storeBlob, indicating the revision the blob is associated with.
56 * This may be used for differential storage and reference counting.
57 */
58 const REVISION_HINT = 'rev_id';
59
60 /**
61 * Hint key for use with storeBlob, indicating the parent revision of the revision
62 * the blob is associated with. This may be used for differential storage.
63 */
64 const PARENT_HINT = 'rev_parent_id';
65
66 /**
67 * Hint key for use with storeBlob, providing the SHA1 hash of the blob as passed to the
68 * method. This can be used to avoid re-calculating the hash if it is needed by the BlobStore.
69 */
70 const SHA1_HINT = 'cont_sha1';
71
72 /**
73 * Hint key for use with storeBlob, indicating the model of the content encoded in the
74 * given blob. May be used to implement optimized storage for some well known models.
75 */
76 const MODEL_HINT = 'cont_model';
77
78 /**
79 * Hint key for use with storeBlob, indicating the serialization format used to create
80 * the blob, as a MIME type. May be used for optimized storage in the underlying database.
81 */
82 const FORMAT_HINT = 'cont_format';
83
84 /**
85 * Retrieve a blob, given an address.
86 *
87 * MCR migration note: this replaces Revision::loadText
88 *
89 * @param string $blobAddress The blob address as returned by storeBlob(),
90 * such as "tt:12345" or "ex:DB://s16/456/9876".
91 * @param int $queryFlags See IDBAccessObject.
92 *
93 * @throws BlobAccessException
94 * @return string binary blob data
95 */
96 public function getBlob( $blobAddress, $queryFlags = 0 );
97
98 /**
99 * Stores an arbitrary blob of data and returns an address that can be used with
100 * getBlob() to retrieve the same blob of data,
101 *
102 * @param string $data raw binary data
103 * @param array $hints An array of hints. Implementations may use the hints to optimize storage.
104 * All hints are optional, supported hints depend on the implementation. Hint names by
105 * convention correspond to the names of fields in the database. Callers are encouraged to
106 * provide the well known hints as defined by the XXX_HINT constants.
107 *
108 * @throws BlobAccessException
109 * @return string an address that can be used with getBlob() to retrieve the data.
110 */
111 public function storeBlob( $data, $hints = [] );
112
113 }