]> git.mxchange.org Git - friendica.git/blob - src/Model/Storage/IStorage.php
a7b7f6f56667bd19c43b9b048c8133c29a078c54
[friendica.git] / src / Model / Storage / IStorage.php
1 <?php
2 /**
3  * @file src/Model/Storage/IStorage.php
4  * @brief Storage backend system
5  */
6
7 namespace Friendica\Model\Storage;
8
9 /**
10  * @brief Interface for storage backends
11  */
12 interface IStorage
13 {
14         /**
15          * @brief Get data from backend
16          *
17          * @param string $reference Data reference
18          *
19          * @return string
20          */
21         public function get(string $reference);
22
23         /**
24          * @brief Put data in backend as $ref. If $ref is not defined a new reference is created.
25          *
26          * @param string $data      Data to save
27          * @param string $reference Data reference. Optional.
28          *
29          * @return string Saved data reference
30          */
31         public function put(string $data, string $reference = "");
32
33         /**
34          * @brief Remove data from backend
35          *
36          * @param string $reference Data reference
37          *
38          * @return boolean  True on success
39          */
40         public function delete(string $reference);
41
42         /**
43          * @brief Get info about storage options
44          *
45          * @return array
46          *
47          * This method return an array with informations about storage options
48          * from which the form presented to the user is build.
49          *
50          * The returned array is:
51          *
52          *    [
53          *      'option1name' => [ ..info.. ],
54          *      'option2name' => [ ..info.. ],
55          *      ...
56          *    ]
57          *
58          * An empty array can be returned if backend doesn't have any options
59          *
60          * The info array for each option MUST be as follows:
61          *
62          *    [
63          *      'type',      // define the field used in form, and the type of data.
64          *                   // one of 'checkbox', 'combobox', 'custom', 'datetime',
65          *                   // 'input', 'intcheckbox', 'password', 'radio', 'richtext'
66          *                   // 'select', 'select_raw', 'textarea', 'yesno'
67          *
68          *      'label',     // Translatable label of the field
69          *      'value',     // Current value
70          *      'help text', // Translatable description for the field
71          *      extra data   // Optional. Depends on 'type':
72          *                   // select: array [ value => label ] of choices
73          *                   // intcheckbox: value of input element
74          *                   // select_raw: prebuild html string of < option > tags
75          *                   // yesno: array [ 'label no', 'label yes']
76          *    ]
77          *
78          * See https://github.com/friendica/friendica/wiki/Quick-Template-Guide
79          */
80         public function getOptions();
81
82         /**
83          * @brief Validate and save options
84          *
85          * @param array $data Array [optionname => value] to be saved
86          *
87          * @return array  Validation errors: [optionname => error message]
88          *
89          * Return array must be empty if no error.
90          */
91         public function saveOptions(array $data);
92
93         /**
94          * The name of the backend
95          *
96          * @return string
97          */
98         public function __toString();
99 }