@@ -28,190 +28,190 @@ |
||
28 | 28 | |
29 | 29 | class L10N implements IL10N { |
30 | 30 | |
31 | - /** @var IFactory */ |
|
32 | - protected $factory; |
|
33 | - |
|
34 | - /** @var string App of this object */ |
|
35 | - protected $app; |
|
36 | - |
|
37 | - /** @var string Language of this object */ |
|
38 | - protected $lang; |
|
39 | - |
|
40 | - /** @var string Plural forms (string) */ |
|
41 | - private $pluralFormString = 'nplurals=2; plural=(n != 1);'; |
|
42 | - |
|
43 | - /** @var string Plural forms (function) */ |
|
44 | - private $pluralFormFunction = null; |
|
45 | - |
|
46 | - /** @var string[] */ |
|
47 | - private $translations = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IFactory $factory |
|
51 | - * @param string $app |
|
52 | - * @param string $lang |
|
53 | - * @param array $files |
|
54 | - */ |
|
55 | - public function __construct(IFactory $factory, $app, $lang, array $files) { |
|
56 | - $this->factory = $factory; |
|
57 | - $this->app = $app; |
|
58 | - $this->lang = $lang; |
|
59 | - |
|
60 | - $this->translations = []; |
|
61 | - foreach ($files as $languageFile) { |
|
62 | - $this->load($languageFile); |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * The code (en, de, ...) of the language that is used for this instance |
|
68 | - * |
|
69 | - * @return string language |
|
70 | - */ |
|
71 | - public function getLanguageCode() { |
|
72 | - return $this->lang; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Translating |
|
77 | - * @param string $text The text we need a translation for |
|
78 | - * @param array $parameters default:array() Parameters for sprintf |
|
79 | - * @return string Translation or the same text |
|
80 | - * |
|
81 | - * Returns the translation. If no translation is found, $text will be |
|
82 | - * returned. |
|
83 | - */ |
|
84 | - public function t($text, $parameters = array()) { |
|
85 | - return (string) new \OC_L10N_String($this, $text, $parameters); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Translating |
|
90 | - * @param string $text_singular the string to translate for exactly one object |
|
91 | - * @param string $text_plural the string to translate for n objects |
|
92 | - * @param integer $count Number of objects |
|
93 | - * @param array $parameters default:array() Parameters for sprintf |
|
94 | - * @return string Translation or the same text |
|
95 | - * |
|
96 | - * Returns the translation. If no translation is found, $text will be |
|
97 | - * returned. %n will be replaced with the number of objects. |
|
98 | - * |
|
99 | - * The correct plural is determined by the plural_forms-function |
|
100 | - * provided by the po file. |
|
101 | - * |
|
102 | - */ |
|
103 | - public function n($text_singular, $text_plural, $count, $parameters = array()) { |
|
104 | - $identifier = "_${text_singular}_::_${text_plural}_"; |
|
105 | - if (isset($this->translations[$identifier])) { |
|
106 | - return (string) new \OC_L10N_String($this, $identifier, $parameters, $count); |
|
107 | - } else { |
|
108 | - if ($count === 1) { |
|
109 | - return (string) new \OC_L10N_String($this, $text_singular, $parameters, $count); |
|
110 | - } else { |
|
111 | - return (string) new \OC_L10N_String($this, $text_plural, $parameters, $count); |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Localization |
|
118 | - * @param string $type Type of localization |
|
119 | - * @param \DateTime|int|string $data parameters for this localization |
|
120 | - * @param array $options |
|
121 | - * @return string|int|false |
|
122 | - * |
|
123 | - * Returns the localized data. |
|
124 | - * |
|
125 | - * Implemented types: |
|
126 | - * - date |
|
127 | - * - Creates a date |
|
128 | - * - params: timestamp (int/string) |
|
129 | - * - datetime |
|
130 | - * - Creates date and time |
|
131 | - * - params: timestamp (int/string) |
|
132 | - * - time |
|
133 | - * - Creates a time |
|
134 | - * - params: timestamp (int/string) |
|
135 | - * - firstday: Returns the first day of the week (0 sunday - 6 saturday) |
|
136 | - * - jsdate: Returns the short JS date format |
|
137 | - */ |
|
138 | - public function l($type, $data = null, $options = array()) { |
|
139 | - // Use the language of the instance |
|
140 | - $locale = $this->getLanguageCode(); |
|
141 | - if ($locale === 'sr@latin') { |
|
142 | - $locale = 'sr_latn'; |
|
143 | - } |
|
144 | - |
|
145 | - if ($type === 'firstday') { |
|
146 | - return (int) Calendar::getFirstWeekday($locale); |
|
147 | - } |
|
148 | - if ($type === 'jsdate') { |
|
149 | - return (string) Calendar::getDateFormat('short', $locale); |
|
150 | - } |
|
151 | - |
|
152 | - $value = new \DateTime(); |
|
153 | - if ($data instanceof \DateTime) { |
|
154 | - $value = $data; |
|
155 | - } else if (is_string($data) && !is_numeric($data)) { |
|
156 | - $data = strtotime($data); |
|
157 | - $value->setTimestamp($data); |
|
158 | - } else if ($data !== null) { |
|
159 | - $value->setTimestamp($data); |
|
160 | - } |
|
161 | - |
|
162 | - $options = array_merge(array('width' => 'long'), $options); |
|
163 | - $width = $options['width']; |
|
164 | - switch ($type) { |
|
165 | - case 'date': |
|
166 | - return (string) Calendar::formatDate($value, $width, $locale); |
|
167 | - case 'datetime': |
|
168 | - return (string) Calendar::formatDatetime($value, $width, $locale); |
|
169 | - case 'time': |
|
170 | - return (string) Calendar::formatTime($value, $width, $locale); |
|
171 | - default: |
|
172 | - return false; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Returns an associative array with all translations |
|
178 | - * |
|
179 | - * Called by \OC_L10N_String |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public function getTranslations() { |
|
183 | - return $this->translations; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returnsed function accepts the argument $n |
|
188 | - * |
|
189 | - * Called by \OC_L10N_String |
|
190 | - * @return string the plural form function |
|
191 | - */ |
|
192 | - public function getPluralFormFunction() { |
|
193 | - if (is_null($this->pluralFormFunction)) { |
|
194 | - $this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString); |
|
195 | - } |
|
196 | - return $this->pluralFormFunction; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param $translationFile |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - protected function load($translationFile) { |
|
204 | - $json = json_decode(file_get_contents($translationFile), true); |
|
205 | - if (!is_array($json)) { |
|
206 | - $jsonError = json_last_error(); |
|
207 | - \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - if (!empty($json['pluralForm'])) { |
|
212 | - $this->pluralFormString = $json['pluralForm']; |
|
213 | - } |
|
214 | - $this->translations = array_merge($this->translations, $json['translations']); |
|
215 | - return true; |
|
216 | - } |
|
31 | + /** @var IFactory */ |
|
32 | + protected $factory; |
|
33 | + |
|
34 | + /** @var string App of this object */ |
|
35 | + protected $app; |
|
36 | + |
|
37 | + /** @var string Language of this object */ |
|
38 | + protected $lang; |
|
39 | + |
|
40 | + /** @var string Plural forms (string) */ |
|
41 | + private $pluralFormString = 'nplurals=2; plural=(n != 1);'; |
|
42 | + |
|
43 | + /** @var string Plural forms (function) */ |
|
44 | + private $pluralFormFunction = null; |
|
45 | + |
|
46 | + /** @var string[] */ |
|
47 | + private $translations = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IFactory $factory |
|
51 | + * @param string $app |
|
52 | + * @param string $lang |
|
53 | + * @param array $files |
|
54 | + */ |
|
55 | + public function __construct(IFactory $factory, $app, $lang, array $files) { |
|
56 | + $this->factory = $factory; |
|
57 | + $this->app = $app; |
|
58 | + $this->lang = $lang; |
|
59 | + |
|
60 | + $this->translations = []; |
|
61 | + foreach ($files as $languageFile) { |
|
62 | + $this->load($languageFile); |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * The code (en, de, ...) of the language that is used for this instance |
|
68 | + * |
|
69 | + * @return string language |
|
70 | + */ |
|
71 | + public function getLanguageCode() { |
|
72 | + return $this->lang; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Translating |
|
77 | + * @param string $text The text we need a translation for |
|
78 | + * @param array $parameters default:array() Parameters for sprintf |
|
79 | + * @return string Translation or the same text |
|
80 | + * |
|
81 | + * Returns the translation. If no translation is found, $text will be |
|
82 | + * returned. |
|
83 | + */ |
|
84 | + public function t($text, $parameters = array()) { |
|
85 | + return (string) new \OC_L10N_String($this, $text, $parameters); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Translating |
|
90 | + * @param string $text_singular the string to translate for exactly one object |
|
91 | + * @param string $text_plural the string to translate for n objects |
|
92 | + * @param integer $count Number of objects |
|
93 | + * @param array $parameters default:array() Parameters for sprintf |
|
94 | + * @return string Translation or the same text |
|
95 | + * |
|
96 | + * Returns the translation. If no translation is found, $text will be |
|
97 | + * returned. %n will be replaced with the number of objects. |
|
98 | + * |
|
99 | + * The correct plural is determined by the plural_forms-function |
|
100 | + * provided by the po file. |
|
101 | + * |
|
102 | + */ |
|
103 | + public function n($text_singular, $text_plural, $count, $parameters = array()) { |
|
104 | + $identifier = "_${text_singular}_::_${text_plural}_"; |
|
105 | + if (isset($this->translations[$identifier])) { |
|
106 | + return (string) new \OC_L10N_String($this, $identifier, $parameters, $count); |
|
107 | + } else { |
|
108 | + if ($count === 1) { |
|
109 | + return (string) new \OC_L10N_String($this, $text_singular, $parameters, $count); |
|
110 | + } else { |
|
111 | + return (string) new \OC_L10N_String($this, $text_plural, $parameters, $count); |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Localization |
|
118 | + * @param string $type Type of localization |
|
119 | + * @param \DateTime|int|string $data parameters for this localization |
|
120 | + * @param array $options |
|
121 | + * @return string|int|false |
|
122 | + * |
|
123 | + * Returns the localized data. |
|
124 | + * |
|
125 | + * Implemented types: |
|
126 | + * - date |
|
127 | + * - Creates a date |
|
128 | + * - params: timestamp (int/string) |
|
129 | + * - datetime |
|
130 | + * - Creates date and time |
|
131 | + * - params: timestamp (int/string) |
|
132 | + * - time |
|
133 | + * - Creates a time |
|
134 | + * - params: timestamp (int/string) |
|
135 | + * - firstday: Returns the first day of the week (0 sunday - 6 saturday) |
|
136 | + * - jsdate: Returns the short JS date format |
|
137 | + */ |
|
138 | + public function l($type, $data = null, $options = array()) { |
|
139 | + // Use the language of the instance |
|
140 | + $locale = $this->getLanguageCode(); |
|
141 | + if ($locale === 'sr@latin') { |
|
142 | + $locale = 'sr_latn'; |
|
143 | + } |
|
144 | + |
|
145 | + if ($type === 'firstday') { |
|
146 | + return (int) Calendar::getFirstWeekday($locale); |
|
147 | + } |
|
148 | + if ($type === 'jsdate') { |
|
149 | + return (string) Calendar::getDateFormat('short', $locale); |
|
150 | + } |
|
151 | + |
|
152 | + $value = new \DateTime(); |
|
153 | + if ($data instanceof \DateTime) { |
|
154 | + $value = $data; |
|
155 | + } else if (is_string($data) && !is_numeric($data)) { |
|
156 | + $data = strtotime($data); |
|
157 | + $value->setTimestamp($data); |
|
158 | + } else if ($data !== null) { |
|
159 | + $value->setTimestamp($data); |
|
160 | + } |
|
161 | + |
|
162 | + $options = array_merge(array('width' => 'long'), $options); |
|
163 | + $width = $options['width']; |
|
164 | + switch ($type) { |
|
165 | + case 'date': |
|
166 | + return (string) Calendar::formatDate($value, $width, $locale); |
|
167 | + case 'datetime': |
|
168 | + return (string) Calendar::formatDatetime($value, $width, $locale); |
|
169 | + case 'time': |
|
170 | + return (string) Calendar::formatTime($value, $width, $locale); |
|
171 | + default: |
|
172 | + return false; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Returns an associative array with all translations |
|
178 | + * |
|
179 | + * Called by \OC_L10N_String |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public function getTranslations() { |
|
183 | + return $this->translations; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returnsed function accepts the argument $n |
|
188 | + * |
|
189 | + * Called by \OC_L10N_String |
|
190 | + * @return string the plural form function |
|
191 | + */ |
|
192 | + public function getPluralFormFunction() { |
|
193 | + if (is_null($this->pluralFormFunction)) { |
|
194 | + $this->pluralFormFunction = $this->factory->createPluralFunction($this->pluralFormString); |
|
195 | + } |
|
196 | + return $this->pluralFormFunction; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param $translationFile |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + protected function load($translationFile) { |
|
204 | + $json = json_decode(file_get_contents($translationFile), true); |
|
205 | + if (!is_array($json)) { |
|
206 | + $jsonError = json_last_error(); |
|
207 | + \OC::$server->getLogger()->warning("Failed to load $translationFile - json error code: $jsonError", ['app' => 'l10n']); |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + if (!empty($json['pluralForm'])) { |
|
212 | + $this->pluralFormString = $json['pluralForm']; |
|
213 | + } |
|
214 | + $this->translations = array_merge($this->translations, $json['translations']); |
|
215 | + return true; |
|
216 | + } |
|
217 | 217 | } |
@@ -32,51 +32,51 @@ |
||
32 | 32 | * @package OC\Http |
33 | 33 | */ |
34 | 34 | class Response implements IResponse { |
35 | - /** @var GuzzleResponse */ |
|
36 | - private $response; |
|
35 | + /** @var GuzzleResponse */ |
|
36 | + private $response; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var bool |
|
40 | - */ |
|
41 | - private $stream; |
|
38 | + /** |
|
39 | + * @var bool |
|
40 | + */ |
|
41 | + private $stream; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param GuzzleResponse $response |
|
45 | - * @param bool $stream |
|
46 | - */ |
|
47 | - public function __construct(GuzzleResponse $response, $stream = false) { |
|
48 | - $this->response = $response; |
|
49 | - $this->stream = $stream; |
|
50 | - } |
|
43 | + /** |
|
44 | + * @param GuzzleResponse $response |
|
45 | + * @param bool $stream |
|
46 | + */ |
|
47 | + public function __construct(GuzzleResponse $response, $stream = false) { |
|
48 | + $this->response = $response; |
|
49 | + $this->stream = $stream; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return string|resource |
|
54 | - */ |
|
55 | - public function getBody() { |
|
56 | - return $this->stream ? |
|
57 | - $this->response->getBody()->detach(): |
|
58 | - $this->response->getBody()->getContents(); |
|
59 | - } |
|
52 | + /** |
|
53 | + * @return string|resource |
|
54 | + */ |
|
55 | + public function getBody() { |
|
56 | + return $this->stream ? |
|
57 | + $this->response->getBody()->detach(): |
|
58 | + $this->response->getBody()->getContents(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return int |
|
63 | - */ |
|
64 | - public function getStatusCode() { |
|
65 | - return $this->response->getStatusCode(); |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return int |
|
63 | + */ |
|
64 | + public function getStatusCode() { |
|
65 | + return $this->response->getStatusCode(); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param $key |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getHeader($key) { |
|
73 | - return $this->response->getHeader($key); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @param $key |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getHeader($key) { |
|
73 | + return $this->response->getHeader($key); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function getHeaders() { |
|
80 | - return $this->response->getHeaders(); |
|
81 | - } |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function getHeaders() { |
|
80 | + return $this->response->getHeaders(); |
|
81 | + } |
|
82 | 82 | } |
@@ -34,280 +34,280 @@ |
||
34 | 34 | * @package OC\Http |
35 | 35 | */ |
36 | 36 | class Client implements IClient { |
37 | - /** @var GuzzleClient */ |
|
38 | - private $client; |
|
39 | - /** @var IConfig */ |
|
40 | - private $config; |
|
41 | - /** @var ICertificateManager */ |
|
42 | - private $certificateManager; |
|
43 | - private $configured = false; |
|
37 | + /** @var GuzzleClient */ |
|
38 | + private $client; |
|
39 | + /** @var IConfig */ |
|
40 | + private $config; |
|
41 | + /** @var ICertificateManager */ |
|
42 | + private $certificateManager; |
|
43 | + private $configured = false; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IConfig $config |
|
47 | - * @param ICertificateManager $certificateManager |
|
48 | - * @param GuzzleClient $client |
|
49 | - */ |
|
50 | - public function __construct(IConfig $config, |
|
51 | - ICertificateManager $certificateManager, |
|
52 | - GuzzleClient $client) { |
|
53 | - $this->config = $config; |
|
54 | - $this->client = $client; |
|
55 | - $this->certificateManager = $certificateManager; |
|
56 | - } |
|
45 | + /** |
|
46 | + * @param IConfig $config |
|
47 | + * @param ICertificateManager $certificateManager |
|
48 | + * @param GuzzleClient $client |
|
49 | + */ |
|
50 | + public function __construct(IConfig $config, |
|
51 | + ICertificateManager $certificateManager, |
|
52 | + GuzzleClient $client) { |
|
53 | + $this->config = $config; |
|
54 | + $this->client = $client; |
|
55 | + $this->certificateManager = $certificateManager; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Sets the default options to the client |
|
60 | - */ |
|
61 | - private function setDefaultOptions() { |
|
62 | - if ($this->configured) { |
|
63 | - return; |
|
64 | - } |
|
65 | - $this->configured = true; |
|
66 | - // Either use user bundle or the system bundle if nothing is specified |
|
67 | - if ($this->certificateManager->listCertificates() !== []) { |
|
68 | - $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath()); |
|
69 | - } else { |
|
70 | - // If the instance is not yet setup we need to use the static path as |
|
71 | - // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate |
|
72 | - // a view |
|
73 | - if ($this->config->getSystemValue('installed', false)) { |
|
74 | - $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null)); |
|
75 | - } else { |
|
76 | - $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
77 | - } |
|
78 | - } |
|
58 | + /** |
|
59 | + * Sets the default options to the client |
|
60 | + */ |
|
61 | + private function setDefaultOptions() { |
|
62 | + if ($this->configured) { |
|
63 | + return; |
|
64 | + } |
|
65 | + $this->configured = true; |
|
66 | + // Either use user bundle or the system bundle if nothing is specified |
|
67 | + if ($this->certificateManager->listCertificates() !== []) { |
|
68 | + $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath()); |
|
69 | + } else { |
|
70 | + // If the instance is not yet setup we need to use the static path as |
|
71 | + // $this->certificateManager->getAbsoluteBundlePath() tries to instantiiate |
|
72 | + // a view |
|
73 | + if ($this->config->getSystemValue('installed', false)) { |
|
74 | + $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null)); |
|
75 | + } else { |
|
76 | + $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/resources/config/ca-bundle.crt'); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | |
80 | - $this->client->setDefaultOption('headers/User-Agent', 'Nextcloud Server Crawler'); |
|
81 | - $proxyUri = $this->getProxyUri(); |
|
82 | - if ($proxyUri !== '') { |
|
83 | - $this->client->setDefaultOption('proxy', $proxyUri); |
|
84 | - } |
|
85 | - } |
|
80 | + $this->client->setDefaultOption('headers/User-Agent', 'Nextcloud Server Crawler'); |
|
81 | + $proxyUri = $this->getProxyUri(); |
|
82 | + if ($proxyUri !== '') { |
|
83 | + $this->client->setDefaultOption('proxy', $proxyUri); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Get the proxy URI |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - private function getProxyUri() { |
|
93 | - $proxyHost = $this->config->getSystemValue('proxy', null); |
|
94 | - $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null); |
|
95 | - $proxyUri = ''; |
|
87 | + /** |
|
88 | + * Get the proxy URI |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + private function getProxyUri() { |
|
93 | + $proxyHost = $this->config->getSystemValue('proxy', null); |
|
94 | + $proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null); |
|
95 | + $proxyUri = ''; |
|
96 | 96 | |
97 | - if ($proxyUserPwd !== null) { |
|
98 | - $proxyUri .= $proxyUserPwd . '@'; |
|
99 | - } |
|
100 | - if ($proxyHost !== null) { |
|
101 | - $proxyUri .= $proxyHost; |
|
102 | - } |
|
97 | + if ($proxyUserPwd !== null) { |
|
98 | + $proxyUri .= $proxyUserPwd . '@'; |
|
99 | + } |
|
100 | + if ($proxyHost !== null) { |
|
101 | + $proxyUri .= $proxyHost; |
|
102 | + } |
|
103 | 103 | |
104 | - return $proxyUri; |
|
105 | - } |
|
104 | + return $proxyUri; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Sends a GET request |
|
109 | - * |
|
110 | - * @param string $uri |
|
111 | - * @param array $options Array such as |
|
112 | - * 'query' => [ |
|
113 | - * 'field' => 'abc', |
|
114 | - * 'other_field' => '123', |
|
115 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
116 | - * ], |
|
117 | - * 'headers' => [ |
|
118 | - * 'foo' => 'bar', |
|
119 | - * ], |
|
120 | - * 'cookies' => [' |
|
121 | - * 'foo' => 'bar', |
|
122 | - * ], |
|
123 | - * 'allow_redirects' => [ |
|
124 | - * 'max' => 10, // allow at most 10 redirects. |
|
125 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
126 | - * 'referer' => true, // add a Referer header |
|
127 | - * 'protocols' => ['https'] // only allow https URLs |
|
128 | - * ], |
|
129 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
130 | - * 'verify' => true, // bool or string to CA file |
|
131 | - * 'debug' => true, |
|
132 | - * 'timeout' => 5, |
|
133 | - * @return Response |
|
134 | - * @throws \Exception If the request could not get completed |
|
135 | - */ |
|
136 | - public function get($uri, array $options = []) { |
|
137 | - $this->setDefaultOptions(); |
|
138 | - $response = $this->client->get($uri, $options); |
|
139 | - $isStream = isset($options['stream']) && $options['stream']; |
|
140 | - return new Response($response, $isStream); |
|
141 | - } |
|
107 | + /** |
|
108 | + * Sends a GET request |
|
109 | + * |
|
110 | + * @param string $uri |
|
111 | + * @param array $options Array such as |
|
112 | + * 'query' => [ |
|
113 | + * 'field' => 'abc', |
|
114 | + * 'other_field' => '123', |
|
115 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
116 | + * ], |
|
117 | + * 'headers' => [ |
|
118 | + * 'foo' => 'bar', |
|
119 | + * ], |
|
120 | + * 'cookies' => [' |
|
121 | + * 'foo' => 'bar', |
|
122 | + * ], |
|
123 | + * 'allow_redirects' => [ |
|
124 | + * 'max' => 10, // allow at most 10 redirects. |
|
125 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
126 | + * 'referer' => true, // add a Referer header |
|
127 | + * 'protocols' => ['https'] // only allow https URLs |
|
128 | + * ], |
|
129 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
130 | + * 'verify' => true, // bool or string to CA file |
|
131 | + * 'debug' => true, |
|
132 | + * 'timeout' => 5, |
|
133 | + * @return Response |
|
134 | + * @throws \Exception If the request could not get completed |
|
135 | + */ |
|
136 | + public function get($uri, array $options = []) { |
|
137 | + $this->setDefaultOptions(); |
|
138 | + $response = $this->client->get($uri, $options); |
|
139 | + $isStream = isset($options['stream']) && $options['stream']; |
|
140 | + return new Response($response, $isStream); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Sends a HEAD request |
|
145 | - * |
|
146 | - * @param string $uri |
|
147 | - * @param array $options Array such as |
|
148 | - * 'headers' => [ |
|
149 | - * 'foo' => 'bar', |
|
150 | - * ], |
|
151 | - * 'cookies' => [' |
|
152 | - * 'foo' => 'bar', |
|
153 | - * ], |
|
154 | - * 'allow_redirects' => [ |
|
155 | - * 'max' => 10, // allow at most 10 redirects. |
|
156 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
157 | - * 'referer' => true, // add a Referer header |
|
158 | - * 'protocols' => ['https'] // only allow https URLs |
|
159 | - * ], |
|
160 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
161 | - * 'verify' => true, // bool or string to CA file |
|
162 | - * 'debug' => true, |
|
163 | - * 'timeout' => 5, |
|
164 | - * @return Response |
|
165 | - * @throws \Exception If the request could not get completed |
|
166 | - */ |
|
167 | - public function head($uri, $options = []) { |
|
168 | - $this->setDefaultOptions(); |
|
169 | - $response = $this->client->head($uri, $options); |
|
170 | - return new Response($response); |
|
171 | - } |
|
143 | + /** |
|
144 | + * Sends a HEAD request |
|
145 | + * |
|
146 | + * @param string $uri |
|
147 | + * @param array $options Array such as |
|
148 | + * 'headers' => [ |
|
149 | + * 'foo' => 'bar', |
|
150 | + * ], |
|
151 | + * 'cookies' => [' |
|
152 | + * 'foo' => 'bar', |
|
153 | + * ], |
|
154 | + * 'allow_redirects' => [ |
|
155 | + * 'max' => 10, // allow at most 10 redirects. |
|
156 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
157 | + * 'referer' => true, // add a Referer header |
|
158 | + * 'protocols' => ['https'] // only allow https URLs |
|
159 | + * ], |
|
160 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
161 | + * 'verify' => true, // bool or string to CA file |
|
162 | + * 'debug' => true, |
|
163 | + * 'timeout' => 5, |
|
164 | + * @return Response |
|
165 | + * @throws \Exception If the request could not get completed |
|
166 | + */ |
|
167 | + public function head($uri, $options = []) { |
|
168 | + $this->setDefaultOptions(); |
|
169 | + $response = $this->client->head($uri, $options); |
|
170 | + return new Response($response); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Sends a POST request |
|
175 | - * |
|
176 | - * @param string $uri |
|
177 | - * @param array $options Array such as |
|
178 | - * 'body' => [ |
|
179 | - * 'field' => 'abc', |
|
180 | - * 'other_field' => '123', |
|
181 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
182 | - * ], |
|
183 | - * 'headers' => [ |
|
184 | - * 'foo' => 'bar', |
|
185 | - * ], |
|
186 | - * 'cookies' => [' |
|
187 | - * 'foo' => 'bar', |
|
188 | - * ], |
|
189 | - * 'allow_redirects' => [ |
|
190 | - * 'max' => 10, // allow at most 10 redirects. |
|
191 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
192 | - * 'referer' => true, // add a Referer header |
|
193 | - * 'protocols' => ['https'] // only allow https URLs |
|
194 | - * ], |
|
195 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
196 | - * 'verify' => true, // bool or string to CA file |
|
197 | - * 'debug' => true, |
|
198 | - * 'timeout' => 5, |
|
199 | - * @return Response |
|
200 | - * @throws \Exception If the request could not get completed |
|
201 | - */ |
|
202 | - public function post($uri, array $options = []) { |
|
203 | - $this->setDefaultOptions(); |
|
204 | - $response = $this->client->post($uri, $options); |
|
205 | - return new Response($response); |
|
206 | - } |
|
173 | + /** |
|
174 | + * Sends a POST request |
|
175 | + * |
|
176 | + * @param string $uri |
|
177 | + * @param array $options Array such as |
|
178 | + * 'body' => [ |
|
179 | + * 'field' => 'abc', |
|
180 | + * 'other_field' => '123', |
|
181 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
182 | + * ], |
|
183 | + * 'headers' => [ |
|
184 | + * 'foo' => 'bar', |
|
185 | + * ], |
|
186 | + * 'cookies' => [' |
|
187 | + * 'foo' => 'bar', |
|
188 | + * ], |
|
189 | + * 'allow_redirects' => [ |
|
190 | + * 'max' => 10, // allow at most 10 redirects. |
|
191 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
192 | + * 'referer' => true, // add a Referer header |
|
193 | + * 'protocols' => ['https'] // only allow https URLs |
|
194 | + * ], |
|
195 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
196 | + * 'verify' => true, // bool or string to CA file |
|
197 | + * 'debug' => true, |
|
198 | + * 'timeout' => 5, |
|
199 | + * @return Response |
|
200 | + * @throws \Exception If the request could not get completed |
|
201 | + */ |
|
202 | + public function post($uri, array $options = []) { |
|
203 | + $this->setDefaultOptions(); |
|
204 | + $response = $this->client->post($uri, $options); |
|
205 | + return new Response($response); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Sends a PUT request |
|
210 | - * |
|
211 | - * @param string $uri |
|
212 | - * @param array $options Array such as |
|
213 | - * 'body' => [ |
|
214 | - * 'field' => 'abc', |
|
215 | - * 'other_field' => '123', |
|
216 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
217 | - * ], |
|
218 | - * 'headers' => [ |
|
219 | - * 'foo' => 'bar', |
|
220 | - * ], |
|
221 | - * 'cookies' => [' |
|
222 | - * 'foo' => 'bar', |
|
223 | - * ], |
|
224 | - * 'allow_redirects' => [ |
|
225 | - * 'max' => 10, // allow at most 10 redirects. |
|
226 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
227 | - * 'referer' => true, // add a Referer header |
|
228 | - * 'protocols' => ['https'] // only allow https URLs |
|
229 | - * ], |
|
230 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
231 | - * 'verify' => true, // bool or string to CA file |
|
232 | - * 'debug' => true, |
|
233 | - * 'timeout' => 5, |
|
234 | - * @return Response |
|
235 | - * @throws \Exception If the request could not get completed |
|
236 | - */ |
|
237 | - public function put($uri, array $options = []) { |
|
238 | - $this->setDefaultOptions(); |
|
239 | - $response = $this->client->put($uri, $options); |
|
240 | - return new Response($response); |
|
241 | - } |
|
208 | + /** |
|
209 | + * Sends a PUT request |
|
210 | + * |
|
211 | + * @param string $uri |
|
212 | + * @param array $options Array such as |
|
213 | + * 'body' => [ |
|
214 | + * 'field' => 'abc', |
|
215 | + * 'other_field' => '123', |
|
216 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
217 | + * ], |
|
218 | + * 'headers' => [ |
|
219 | + * 'foo' => 'bar', |
|
220 | + * ], |
|
221 | + * 'cookies' => [' |
|
222 | + * 'foo' => 'bar', |
|
223 | + * ], |
|
224 | + * 'allow_redirects' => [ |
|
225 | + * 'max' => 10, // allow at most 10 redirects. |
|
226 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
227 | + * 'referer' => true, // add a Referer header |
|
228 | + * 'protocols' => ['https'] // only allow https URLs |
|
229 | + * ], |
|
230 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
231 | + * 'verify' => true, // bool or string to CA file |
|
232 | + * 'debug' => true, |
|
233 | + * 'timeout' => 5, |
|
234 | + * @return Response |
|
235 | + * @throws \Exception If the request could not get completed |
|
236 | + */ |
|
237 | + public function put($uri, array $options = []) { |
|
238 | + $this->setDefaultOptions(); |
|
239 | + $response = $this->client->put($uri, $options); |
|
240 | + return new Response($response); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Sends a DELETE request |
|
245 | - * |
|
246 | - * @param string $uri |
|
247 | - * @param array $options Array such as |
|
248 | - * 'body' => [ |
|
249 | - * 'field' => 'abc', |
|
250 | - * 'other_field' => '123', |
|
251 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
252 | - * ], |
|
253 | - * 'headers' => [ |
|
254 | - * 'foo' => 'bar', |
|
255 | - * ], |
|
256 | - * 'cookies' => [' |
|
257 | - * 'foo' => 'bar', |
|
258 | - * ], |
|
259 | - * 'allow_redirects' => [ |
|
260 | - * 'max' => 10, // allow at most 10 redirects. |
|
261 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
262 | - * 'referer' => true, // add a Referer header |
|
263 | - * 'protocols' => ['https'] // only allow https URLs |
|
264 | - * ], |
|
265 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
266 | - * 'verify' => true, // bool or string to CA file |
|
267 | - * 'debug' => true, |
|
268 | - * 'timeout' => 5, |
|
269 | - * @return Response |
|
270 | - * @throws \Exception If the request could not get completed |
|
271 | - */ |
|
272 | - public function delete($uri, array $options = []) { |
|
273 | - $this->setDefaultOptions(); |
|
274 | - $response = $this->client->delete($uri, $options); |
|
275 | - return new Response($response); |
|
276 | - } |
|
243 | + /** |
|
244 | + * Sends a DELETE request |
|
245 | + * |
|
246 | + * @param string $uri |
|
247 | + * @param array $options Array such as |
|
248 | + * 'body' => [ |
|
249 | + * 'field' => 'abc', |
|
250 | + * 'other_field' => '123', |
|
251 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
252 | + * ], |
|
253 | + * 'headers' => [ |
|
254 | + * 'foo' => 'bar', |
|
255 | + * ], |
|
256 | + * 'cookies' => [' |
|
257 | + * 'foo' => 'bar', |
|
258 | + * ], |
|
259 | + * 'allow_redirects' => [ |
|
260 | + * 'max' => 10, // allow at most 10 redirects. |
|
261 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
262 | + * 'referer' => true, // add a Referer header |
|
263 | + * 'protocols' => ['https'] // only allow https URLs |
|
264 | + * ], |
|
265 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
266 | + * 'verify' => true, // bool or string to CA file |
|
267 | + * 'debug' => true, |
|
268 | + * 'timeout' => 5, |
|
269 | + * @return Response |
|
270 | + * @throws \Exception If the request could not get completed |
|
271 | + */ |
|
272 | + public function delete($uri, array $options = []) { |
|
273 | + $this->setDefaultOptions(); |
|
274 | + $response = $this->client->delete($uri, $options); |
|
275 | + return new Response($response); |
|
276 | + } |
|
277 | 277 | |
278 | 278 | |
279 | - /** |
|
280 | - * Sends a options request |
|
281 | - * |
|
282 | - * @param string $uri |
|
283 | - * @param array $options Array such as |
|
284 | - * 'body' => [ |
|
285 | - * 'field' => 'abc', |
|
286 | - * 'other_field' => '123', |
|
287 | - * 'file_name' => fopen('/path/to/file', 'r'), |
|
288 | - * ], |
|
289 | - * 'headers' => [ |
|
290 | - * 'foo' => 'bar', |
|
291 | - * ], |
|
292 | - * 'cookies' => [' |
|
293 | - * 'foo' => 'bar', |
|
294 | - * ], |
|
295 | - * 'allow_redirects' => [ |
|
296 | - * 'max' => 10, // allow at most 10 redirects. |
|
297 | - * 'strict' => true, // use "strict" RFC compliant redirects. |
|
298 | - * 'referer' => true, // add a Referer header |
|
299 | - * 'protocols' => ['https'] // only allow https URLs |
|
300 | - * ], |
|
301 | - * 'save_to' => '/path/to/file', // save to a file or a stream |
|
302 | - * 'verify' => true, // bool or string to CA file |
|
303 | - * 'debug' => true, |
|
304 | - * 'timeout' => 5, |
|
305 | - * @return Response |
|
306 | - * @throws \Exception If the request could not get completed |
|
307 | - */ |
|
308 | - public function options($uri, array $options = []) { |
|
309 | - $this->setDefaultOptions(); |
|
310 | - $response = $this->client->options($uri, $options); |
|
311 | - return new Response($response); |
|
312 | - } |
|
279 | + /** |
|
280 | + * Sends a options request |
|
281 | + * |
|
282 | + * @param string $uri |
|
283 | + * @param array $options Array such as |
|
284 | + * 'body' => [ |
|
285 | + * 'field' => 'abc', |
|
286 | + * 'other_field' => '123', |
|
287 | + * 'file_name' => fopen('/path/to/file', 'r'), |
|
288 | + * ], |
|
289 | + * 'headers' => [ |
|
290 | + * 'foo' => 'bar', |
|
291 | + * ], |
|
292 | + * 'cookies' => [' |
|
293 | + * 'foo' => 'bar', |
|
294 | + * ], |
|
295 | + * 'allow_redirects' => [ |
|
296 | + * 'max' => 10, // allow at most 10 redirects. |
|
297 | + * 'strict' => true, // use "strict" RFC compliant redirects. |
|
298 | + * 'referer' => true, // add a Referer header |
|
299 | + * 'protocols' => ['https'] // only allow https URLs |
|
300 | + * ], |
|
301 | + * 'save_to' => '/path/to/file', // save to a file or a stream |
|
302 | + * 'verify' => true, // bool or string to CA file |
|
303 | + * 'debug' => true, |
|
304 | + * 'timeout' => 5, |
|
305 | + * @return Response |
|
306 | + * @throws \Exception If the request could not get completed |
|
307 | + */ |
|
308 | + public function options($uri, array $options = []) { |
|
309 | + $this->setDefaultOptions(); |
|
310 | + $response = $this->client->options($uri, $options); |
|
311 | + return new Response($response); |
|
312 | + } |
|
313 | 313 | } |
@@ -33,25 +33,25 @@ |
||
33 | 33 | * @package OC\Http |
34 | 34 | */ |
35 | 35 | class ClientService implements IClientService { |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
38 | - /** @var ICertificateManager */ |
|
39 | - private $certificateManager; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | + /** @var ICertificateManager */ |
|
39 | + private $certificateManager; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IConfig $config |
|
43 | - * @param ICertificateManager $certificateManager |
|
44 | - */ |
|
45 | - public function __construct(IConfig $config, |
|
46 | - ICertificateManager $certificateManager) { |
|
47 | - $this->config = $config; |
|
48 | - $this->certificateManager = $certificateManager; |
|
49 | - } |
|
41 | + /** |
|
42 | + * @param IConfig $config |
|
43 | + * @param ICertificateManager $certificateManager |
|
44 | + */ |
|
45 | + public function __construct(IConfig $config, |
|
46 | + ICertificateManager $certificateManager) { |
|
47 | + $this->config = $config; |
|
48 | + $this->certificateManager = $certificateManager; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return Client |
|
53 | - */ |
|
54 | - public function newClient() { |
|
55 | - return new Client($this->config, $this->certificateManager, new GuzzleClient()); |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return Client |
|
53 | + */ |
|
54 | + public function newClient() { |
|
55 | + return new Client($this->config, $this->certificateManager, new GuzzleClient()); |
|
56 | + } |
|
57 | 57 | } |
@@ -38,86 +38,86 @@ |
||
38 | 38 | * @package OC\Session |
39 | 39 | */ |
40 | 40 | class Memory extends Session { |
41 | - protected $data; |
|
41 | + protected $data; |
|
42 | 42 | |
43 | - public function __construct($name) { |
|
44 | - //no need to use $name since all data is already scoped to this instance |
|
45 | - $this->data = array(); |
|
46 | - } |
|
43 | + public function __construct($name) { |
|
44 | + //no need to use $name since all data is already scoped to this instance |
|
45 | + $this->data = array(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $key |
|
50 | - * @param integer $value |
|
51 | - */ |
|
52 | - public function set($key, $value) { |
|
53 | - $this->validateSession(); |
|
54 | - $this->data[$key] = $value; |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param string $key |
|
50 | + * @param integer $value |
|
51 | + */ |
|
52 | + public function set($key, $value) { |
|
53 | + $this->validateSession(); |
|
54 | + $this->data[$key] = $value; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param string $key |
|
59 | - * @return mixed |
|
60 | - */ |
|
61 | - public function get($key) { |
|
62 | - if (!$this->exists($key)) { |
|
63 | - return null; |
|
64 | - } |
|
65 | - return $this->data[$key]; |
|
66 | - } |
|
57 | + /** |
|
58 | + * @param string $key |
|
59 | + * @return mixed |
|
60 | + */ |
|
61 | + public function get($key) { |
|
62 | + if (!$this->exists($key)) { |
|
63 | + return null; |
|
64 | + } |
|
65 | + return $this->data[$key]; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $key |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function exists($key) { |
|
73 | - return isset($this->data[$key]); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @param string $key |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function exists($key) { |
|
73 | + return isset($this->data[$key]); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param string $key |
|
78 | - */ |
|
79 | - public function remove($key) { |
|
80 | - $this->validateSession(); |
|
81 | - unset($this->data[$key]); |
|
82 | - } |
|
76 | + /** |
|
77 | + * @param string $key |
|
78 | + */ |
|
79 | + public function remove($key) { |
|
80 | + $this->validateSession(); |
|
81 | + unset($this->data[$key]); |
|
82 | + } |
|
83 | 83 | |
84 | - public function clear() { |
|
85 | - $this->data = array(); |
|
86 | - } |
|
84 | + public function clear() { |
|
85 | + $this->data = array(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Stub since the session ID does not need to get regenerated for the cache |
|
90 | - * |
|
91 | - * @param bool $deleteOldSession |
|
92 | - */ |
|
93 | - public function regenerateId($deleteOldSession = true) {} |
|
88 | + /** |
|
89 | + * Stub since the session ID does not need to get regenerated for the cache |
|
90 | + * |
|
91 | + * @param bool $deleteOldSession |
|
92 | + */ |
|
93 | + public function regenerateId($deleteOldSession = true) {} |
|
94 | 94 | |
95 | - /** |
|
96 | - * Wrapper around session_id |
|
97 | - * |
|
98 | - * @return string |
|
99 | - * @throws SessionNotAvailableException |
|
100 | - * @since 9.1.0 |
|
101 | - */ |
|
102 | - public function getId() { |
|
103 | - throw new SessionNotAvailableException('Memory session does not have an ID'); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Wrapper around session_id |
|
97 | + * |
|
98 | + * @return string |
|
99 | + * @throws SessionNotAvailableException |
|
100 | + * @since 9.1.0 |
|
101 | + */ |
|
102 | + public function getId() { |
|
103 | + throw new SessionNotAvailableException('Memory session does not have an ID'); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Helper function for PHPUnit execution - don't use in non-test code |
|
108 | - */ |
|
109 | - public function reopen() { |
|
110 | - $this->sessionClosed = false; |
|
111 | - } |
|
106 | + /** |
|
107 | + * Helper function for PHPUnit execution - don't use in non-test code |
|
108 | + */ |
|
109 | + public function reopen() { |
|
110 | + $this->sessionClosed = false; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * In case the session has already been locked an exception will be thrown |
|
115 | - * |
|
116 | - * @throws Exception |
|
117 | - */ |
|
118 | - private function validateSession() { |
|
119 | - if ($this->sessionClosed) { |
|
120 | - throw new Exception('Session has been closed - no further changes to the session are allowed'); |
|
121 | - } |
|
122 | - } |
|
113 | + /** |
|
114 | + * In case the session has already been locked an exception will be thrown |
|
115 | + * |
|
116 | + * @throws Exception |
|
117 | + */ |
|
118 | + private function validateSession() { |
|
119 | + if ($this->sessionClosed) { |
|
120 | + throw new Exception('Session has been closed - no further changes to the session are allowed'); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | } |
@@ -28,53 +28,53 @@ |
||
28 | 28 | |
29 | 29 | abstract class Session implements \ArrayAccess, ISession { |
30 | 30 | |
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - protected $sessionClosed = false; |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + protected $sessionClosed = false; |
|
35 | 35 | |
36 | - /** |
|
37 | - * $name serves as a namespace for the session keys |
|
38 | - * |
|
39 | - * @param string $name |
|
40 | - */ |
|
41 | - abstract public function __construct($name); |
|
36 | + /** |
|
37 | + * $name serves as a namespace for the session keys |
|
38 | + * |
|
39 | + * @param string $name |
|
40 | + */ |
|
41 | + abstract public function __construct($name); |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param mixed $offset |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - public function offsetExists($offset) { |
|
48 | - return $this->exists($offset); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param mixed $offset |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public function offsetExists($offset) { |
|
48 | + return $this->exists($offset); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param mixed $offset |
|
53 | - * @return mixed |
|
54 | - */ |
|
55 | - public function offsetGet($offset) { |
|
56 | - return $this->get($offset); |
|
57 | - } |
|
51 | + /** |
|
52 | + * @param mixed $offset |
|
53 | + * @return mixed |
|
54 | + */ |
|
55 | + public function offsetGet($offset) { |
|
56 | + return $this->get($offset); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param mixed $offset |
|
61 | - * @param mixed $value |
|
62 | - */ |
|
63 | - public function offsetSet($offset, $value) { |
|
64 | - $this->set($offset, $value); |
|
65 | - } |
|
59 | + /** |
|
60 | + * @param mixed $offset |
|
61 | + * @param mixed $value |
|
62 | + */ |
|
63 | + public function offsetSet($offset, $value) { |
|
64 | + $this->set($offset, $value); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param mixed $offset |
|
69 | - */ |
|
70 | - public function offsetUnset($offset) { |
|
71 | - $this->remove($offset); |
|
72 | - } |
|
67 | + /** |
|
68 | + * @param mixed $offset |
|
69 | + */ |
|
70 | + public function offsetUnset($offset) { |
|
71 | + $this->remove($offset); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Close the session and release the lock |
|
76 | - */ |
|
77 | - public function close() { |
|
78 | - $this->sessionClosed = true; |
|
79 | - } |
|
74 | + /** |
|
75 | + * Close the session and release the lock |
|
76 | + */ |
|
77 | + public function close() { |
|
78 | + $this->sessionClosed = true; |
|
79 | + } |
|
80 | 80 | } |
@@ -48,56 +48,56 @@ |
||
48 | 48 | * @package OC\Session |
49 | 49 | */ |
50 | 50 | class CryptoWrapper { |
51 | - const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
51 | + const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
52 | 52 | |
53 | - /** @var ISession */ |
|
54 | - protected $session; |
|
53 | + /** @var ISession */ |
|
54 | + protected $session; |
|
55 | 55 | |
56 | - /** @var \OCP\Security\ICrypto */ |
|
57 | - protected $crypto; |
|
56 | + /** @var \OCP\Security\ICrypto */ |
|
57 | + protected $crypto; |
|
58 | 58 | |
59 | - /** @var ISecureRandom */ |
|
60 | - protected $random; |
|
59 | + /** @var ISecureRandom */ |
|
60 | + protected $random; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param IConfig $config |
|
64 | - * @param ICrypto $crypto |
|
65 | - * @param ISecureRandom $random |
|
66 | - * @param IRequest $request |
|
67 | - */ |
|
68 | - public function __construct(IConfig $config, |
|
69 | - ICrypto $crypto, |
|
70 | - ISecureRandom $random, |
|
71 | - IRequest $request) { |
|
72 | - $this->crypto = $crypto; |
|
73 | - $this->config = $config; |
|
74 | - $this->random = $random; |
|
62 | + /** |
|
63 | + * @param IConfig $config |
|
64 | + * @param ICrypto $crypto |
|
65 | + * @param ISecureRandom $random |
|
66 | + * @param IRequest $request |
|
67 | + */ |
|
68 | + public function __construct(IConfig $config, |
|
69 | + ICrypto $crypto, |
|
70 | + ISecureRandom $random, |
|
71 | + IRequest $request) { |
|
72 | + $this->crypto = $crypto; |
|
73 | + $this->config = $config; |
|
74 | + $this->random = $random; |
|
75 | 75 | |
76 | - if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
77 | - $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
78 | - } else { |
|
79 | - $this->passphrase = $this->random->generate(128); |
|
80 | - $secureCookie = $request->getServerProtocol() === 'https'; |
|
81 | - // FIXME: Required for CI |
|
82 | - if (!defined('PHPUNIT_RUN')) { |
|
83 | - $webRoot = \OC::$WEBROOT; |
|
84 | - if($webRoot === '') { |
|
85 | - $webRoot = '/'; |
|
86 | - } |
|
87 | - setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
76 | + if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
77 | + $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
78 | + } else { |
|
79 | + $this->passphrase = $this->random->generate(128); |
|
80 | + $secureCookie = $request->getServerProtocol() === 'https'; |
|
81 | + // FIXME: Required for CI |
|
82 | + if (!defined('PHPUNIT_RUN')) { |
|
83 | + $webRoot = \OC::$WEBROOT; |
|
84 | + if($webRoot === '') { |
|
85 | + $webRoot = '/'; |
|
86 | + } |
|
87 | + setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param ISession $session |
|
94 | - * @return ISession |
|
95 | - */ |
|
96 | - public function wrapSession(ISession $session) { |
|
97 | - if (!($session instanceof CryptoSessionData)) { |
|
98 | - return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
99 | - } |
|
92 | + /** |
|
93 | + * @param ISession $session |
|
94 | + * @return ISession |
|
95 | + */ |
|
96 | + public function wrapSession(ISession $session) { |
|
97 | + if (!($session instanceof CryptoSessionData)) { |
|
98 | + return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
99 | + } |
|
100 | 100 | |
101 | - return $session; |
|
102 | - } |
|
101 | + return $session; |
|
102 | + } |
|
103 | 103 | } |
@@ -30,34 +30,34 @@ |
||
30 | 30 | |
31 | 31 | class ManagerFactory implements ICommentsManagerFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * Server container |
|
35 | - * |
|
36 | - * @var IServerContainer |
|
37 | - */ |
|
38 | - private $serverContainer; |
|
33 | + /** |
|
34 | + * Server container |
|
35 | + * |
|
36 | + * @var IServerContainer |
|
37 | + */ |
|
38 | + private $serverContainer; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for the comments manager factory |
|
42 | - * |
|
43 | - * @param IServerContainer $serverContainer server container |
|
44 | - */ |
|
45 | - public function __construct(IServerContainer $serverContainer) { |
|
46 | - $this->serverContainer = $serverContainer; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Constructor for the comments manager factory |
|
42 | + * |
|
43 | + * @param IServerContainer $serverContainer server container |
|
44 | + */ |
|
45 | + public function __construct(IServerContainer $serverContainer) { |
|
46 | + $this->serverContainer = $serverContainer; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * creates and returns an instance of the ICommentsManager |
|
51 | - * |
|
52 | - * @return ICommentsManager |
|
53 | - * @since 9.0.0 |
|
54 | - */ |
|
55 | - public function getManager() { |
|
56 | - return new Manager( |
|
57 | - $this->serverContainer->getDatabaseConnection(), |
|
58 | - $this->serverContainer->getLogger(), |
|
59 | - $this->serverContainer->getConfig(), |
|
60 | - $this->serverContainer->getEventDispatcher() |
|
61 | - ); |
|
62 | - } |
|
49 | + /** |
|
50 | + * creates and returns an instance of the ICommentsManager |
|
51 | + * |
|
52 | + * @return ICommentsManager |
|
53 | + * @since 9.0.0 |
|
54 | + */ |
|
55 | + public function getManager() { |
|
56 | + return new Manager( |
|
57 | + $this->serverContainer->getDatabaseConnection(), |
|
58 | + $this->serverContainer->getLogger(), |
|
59 | + $this->serverContainer->getConfig(), |
|
60 | + $this->serverContainer->getEventDispatcher() |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | } |
@@ -29,393 +29,393 @@ |
||
29 | 29 | |
30 | 30 | class Comment implements IComment { |
31 | 31 | |
32 | - protected $data = [ |
|
33 | - 'id' => '', |
|
34 | - 'parentId' => '0', |
|
35 | - 'topmostParentId' => '0', |
|
36 | - 'childrenCount' => '0', |
|
37 | - 'message' => '', |
|
38 | - 'verb' => '', |
|
39 | - 'actorType' => '', |
|
40 | - 'actorId' => '', |
|
41 | - 'objectType' => '', |
|
42 | - 'objectId' => '', |
|
43 | - 'creationDT' => null, |
|
44 | - 'latestChildDT' => null, |
|
45 | - ]; |
|
46 | - |
|
47 | - /** |
|
48 | - * Comment constructor. |
|
49 | - * |
|
50 | - * @param array $data optional, array with keys according to column names from |
|
51 | - * the comments database scheme |
|
52 | - */ |
|
53 | - public function __construct(array $data = null) { |
|
54 | - if(is_array($data)) { |
|
55 | - $this->fromArray($data); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * returns the ID of the comment |
|
61 | - * |
|
62 | - * It may return an empty string, if the comment was not stored. |
|
63 | - * It is expected that the concrete Comment implementation gives an ID |
|
64 | - * by itself (e.g. after saving). |
|
65 | - * |
|
66 | - * @return string |
|
67 | - * @since 9.0.0 |
|
68 | - */ |
|
69 | - public function getId() { |
|
70 | - return $this->data['id']; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * sets the ID of the comment and returns itself |
|
75 | - * |
|
76 | - * It is only allowed to set the ID only, if the current id is an empty |
|
77 | - * string (which means it is not stored in a database, storage or whatever |
|
78 | - * the concrete implementation does), or vice versa. Changing a given ID is |
|
79 | - * not permitted and must result in an IllegalIDChangeException. |
|
80 | - * |
|
81 | - * @param string $id |
|
82 | - * @return IComment |
|
83 | - * @throws IllegalIDChangeException |
|
84 | - * @since 9.0.0 |
|
85 | - */ |
|
86 | - public function setId($id) { |
|
87 | - if(!is_string($id)) { |
|
88 | - throw new \InvalidArgumentException('String expected.'); |
|
89 | - } |
|
90 | - |
|
91 | - $id = trim($id); |
|
92 | - if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
93 | - $this->data['id'] = $id; |
|
94 | - return $this; |
|
95 | - } |
|
96 | - |
|
97 | - throw new IllegalIDChangeException('Not allowed to assign a new ID to an already saved comment.'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * returns the parent ID of the comment |
|
102 | - * |
|
103 | - * @return string |
|
104 | - * @since 9.0.0 |
|
105 | - */ |
|
106 | - public function getParentId() { |
|
107 | - return $this->data['parentId']; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * sets the parent ID and returns itself |
|
112 | - * |
|
113 | - * @param string $parentId |
|
114 | - * @return IComment |
|
115 | - * @since 9.0.0 |
|
116 | - */ |
|
117 | - public function setParentId($parentId) { |
|
118 | - if(!is_string($parentId)) { |
|
119 | - throw new \InvalidArgumentException('String expected.'); |
|
120 | - } |
|
121 | - $this->data['parentId'] = trim($parentId); |
|
122 | - return $this; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * returns the topmost parent ID of the comment |
|
127 | - * |
|
128 | - * @return string |
|
129 | - * @since 9.0.0 |
|
130 | - */ |
|
131 | - public function getTopmostParentId() { |
|
132 | - return $this->data['topmostParentId']; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * sets the topmost parent ID and returns itself |
|
138 | - * |
|
139 | - * @param string $id |
|
140 | - * @return IComment |
|
141 | - * @since 9.0.0 |
|
142 | - */ |
|
143 | - public function setTopmostParentId($id) { |
|
144 | - if(!is_string($id)) { |
|
145 | - throw new \InvalidArgumentException('String expected.'); |
|
146 | - } |
|
147 | - $this->data['topmostParentId'] = trim($id); |
|
148 | - return $this; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * returns the number of children |
|
153 | - * |
|
154 | - * @return int |
|
155 | - * @since 9.0.0 |
|
156 | - */ |
|
157 | - public function getChildrenCount() { |
|
158 | - return $this->data['childrenCount']; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * sets the number of children |
|
163 | - * |
|
164 | - * @param int $count |
|
165 | - * @return IComment |
|
166 | - * @since 9.0.0 |
|
167 | - */ |
|
168 | - public function setChildrenCount($count) { |
|
169 | - if(!is_int($count)) { |
|
170 | - throw new \InvalidArgumentException('Integer expected.'); |
|
171 | - } |
|
172 | - $this->data['childrenCount'] = $count; |
|
173 | - return $this; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * returns the message of the comment |
|
178 | - * |
|
179 | - * @return string |
|
180 | - * @since 9.0.0 |
|
181 | - */ |
|
182 | - public function getMessage() { |
|
183 | - return $this->data['message']; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * sets the message of the comment and returns itself |
|
188 | - * |
|
189 | - * @param string $message |
|
190 | - * @return IComment |
|
191 | - * @throws MessageTooLongException |
|
192 | - * @since 9.0.0 |
|
193 | - */ |
|
194 | - public function setMessage($message) { |
|
195 | - if(!is_string($message)) { |
|
196 | - throw new \InvalidArgumentException('String expected.'); |
|
197 | - } |
|
198 | - $message = trim($message); |
|
199 | - if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
200 | - throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
201 | - } |
|
202 | - $this->data['message'] = $message; |
|
203 | - return $this; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * returns an array containing mentions that are included in the comment |
|
208 | - * |
|
209 | - * @return array each mention provides a 'type' and an 'id', see example below |
|
210 | - * @since 11.0.0 |
|
211 | - * |
|
212 | - * The return array looks like: |
|
213 | - * [ |
|
214 | - * [ |
|
215 | - * 'type' => 'user', |
|
216 | - * 'id' => 'citizen4' |
|
217 | - * ], |
|
218 | - * [ |
|
219 | - * 'type' => 'group', |
|
220 | - * 'id' => 'media' |
|
221 | - * ], |
|
222 | - * … |
|
223 | - * ] |
|
224 | - * |
|
225 | - */ |
|
226 | - public function getMentions() { |
|
227 | - $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
|
228 | - if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
229 | - return []; |
|
230 | - } |
|
231 | - $uids = array_unique($mentions[0]); |
|
232 | - $result = []; |
|
233 | - foreach ($uids as $uid) { |
|
234 | - // exclude author, no self-mentioning |
|
235 | - if($uid === '@' . $this->getActorId()) { |
|
236 | - continue; |
|
237 | - } |
|
238 | - $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; |
|
239 | - } |
|
240 | - return $result; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * returns the verb of the comment |
|
245 | - * |
|
246 | - * @return string |
|
247 | - * @since 9.0.0 |
|
248 | - */ |
|
249 | - public function getVerb() { |
|
250 | - return $this->data['verb']; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * sets the verb of the comment, e.g. 'comment' or 'like' |
|
255 | - * |
|
256 | - * @param string $verb |
|
257 | - * @return IComment |
|
258 | - * @since 9.0.0 |
|
259 | - */ |
|
260 | - public function setVerb($verb) { |
|
261 | - if(!is_string($verb) || !trim($verb)) { |
|
262 | - throw new \InvalidArgumentException('Non-empty String expected.'); |
|
263 | - } |
|
264 | - $this->data['verb'] = trim($verb); |
|
265 | - return $this; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * returns the actor type |
|
270 | - * |
|
271 | - * @return string |
|
272 | - * @since 9.0.0 |
|
273 | - */ |
|
274 | - public function getActorType() { |
|
275 | - return $this->data['actorType']; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * returns the actor ID |
|
280 | - * |
|
281 | - * @return string |
|
282 | - * @since 9.0.0 |
|
283 | - */ |
|
284 | - public function getActorId() { |
|
285 | - return $this->data['actorId']; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * sets (overwrites) the actor type and id |
|
290 | - * |
|
291 | - * @param string $actorType e.g. 'users' |
|
292 | - * @param string $actorId e.g. 'zombie234' |
|
293 | - * @return IComment |
|
294 | - * @since 9.0.0 |
|
295 | - */ |
|
296 | - public function setActor($actorType, $actorId) { |
|
297 | - if( |
|
298 | - !is_string($actorType) || !trim($actorType) |
|
299 | - || !is_string($actorId) || !trim($actorId) |
|
300 | - ) { |
|
301 | - throw new \InvalidArgumentException('String expected.'); |
|
302 | - } |
|
303 | - $this->data['actorType'] = trim($actorType); |
|
304 | - $this->data['actorId'] = trim($actorId); |
|
305 | - return $this; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * returns the creation date of the comment. |
|
310 | - * |
|
311 | - * If not explicitly set, it shall default to the time of initialization. |
|
312 | - * |
|
313 | - * @return \DateTime |
|
314 | - * @since 9.0.0 |
|
315 | - */ |
|
316 | - public function getCreationDateTime() { |
|
317 | - return $this->data['creationDT']; |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * sets the creation date of the comment and returns itself |
|
322 | - * |
|
323 | - * @param \DateTime $timestamp |
|
324 | - * @return IComment |
|
325 | - * @since 9.0.0 |
|
326 | - */ |
|
327 | - public function setCreationDateTime(\DateTime $timestamp) { |
|
328 | - $this->data['creationDT'] = $timestamp; |
|
329 | - return $this; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * returns the DateTime of the most recent child, if set, otherwise null |
|
334 | - * |
|
335 | - * @return \DateTime|null |
|
336 | - * @since 9.0.0 |
|
337 | - */ |
|
338 | - public function getLatestChildDateTime() { |
|
339 | - return $this->data['latestChildDT']; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * sets the date of the most recent child |
|
344 | - * |
|
345 | - * @param \DateTime $dateTime |
|
346 | - * @return IComment |
|
347 | - * @since 9.0.0 |
|
348 | - */ |
|
349 | - public function setLatestChildDateTime(\DateTime $dateTime = null) { |
|
350 | - $this->data['latestChildDT'] = $dateTime; |
|
351 | - return $this; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * returns the object type the comment is attached to |
|
356 | - * |
|
357 | - * @return string |
|
358 | - * @since 9.0.0 |
|
359 | - */ |
|
360 | - public function getObjectType() { |
|
361 | - return $this->data['objectType']; |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * returns the object id the comment is attached to |
|
366 | - * |
|
367 | - * @return string |
|
368 | - * @since 9.0.0 |
|
369 | - */ |
|
370 | - public function getObjectId() { |
|
371 | - return $this->data['objectId']; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * sets (overwrites) the object of the comment |
|
376 | - * |
|
377 | - * @param string $objectType e.g. 'files' |
|
378 | - * @param string $objectId e.g. '16435' |
|
379 | - * @return IComment |
|
380 | - * @since 9.0.0 |
|
381 | - */ |
|
382 | - public function setObject($objectType, $objectId) { |
|
383 | - if( |
|
384 | - !is_string($objectType) || !trim($objectType) |
|
385 | - || !is_string($objectId) || !trim($objectId) |
|
386 | - ) { |
|
387 | - throw new \InvalidArgumentException('String expected.'); |
|
388 | - } |
|
389 | - $this->data['objectType'] = trim($objectType); |
|
390 | - $this->data['objectId'] = trim($objectId); |
|
391 | - return $this; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * sets the comment data based on an array with keys as taken from the |
|
396 | - * database. |
|
397 | - * |
|
398 | - * @param array $data |
|
399 | - * @return IComment |
|
400 | - */ |
|
401 | - protected function fromArray($data) { |
|
402 | - foreach(array_keys($data) as $key) { |
|
403 | - // translate DB keys to internal setter names |
|
404 | - $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
405 | - $setter = str_replace('Timestamp', 'DateTime', $setter); |
|
406 | - |
|
407 | - if(method_exists($this, $setter)) { |
|
408 | - $this->$setter($data[$key]); |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - foreach(['actor', 'object'] as $role) { |
|
413 | - if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
414 | - $setter = 'set' . ucfirst($role); |
|
415 | - $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - return $this; |
|
420 | - } |
|
32 | + protected $data = [ |
|
33 | + 'id' => '', |
|
34 | + 'parentId' => '0', |
|
35 | + 'topmostParentId' => '0', |
|
36 | + 'childrenCount' => '0', |
|
37 | + 'message' => '', |
|
38 | + 'verb' => '', |
|
39 | + 'actorType' => '', |
|
40 | + 'actorId' => '', |
|
41 | + 'objectType' => '', |
|
42 | + 'objectId' => '', |
|
43 | + 'creationDT' => null, |
|
44 | + 'latestChildDT' => null, |
|
45 | + ]; |
|
46 | + |
|
47 | + /** |
|
48 | + * Comment constructor. |
|
49 | + * |
|
50 | + * @param array $data optional, array with keys according to column names from |
|
51 | + * the comments database scheme |
|
52 | + */ |
|
53 | + public function __construct(array $data = null) { |
|
54 | + if(is_array($data)) { |
|
55 | + $this->fromArray($data); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * returns the ID of the comment |
|
61 | + * |
|
62 | + * It may return an empty string, if the comment was not stored. |
|
63 | + * It is expected that the concrete Comment implementation gives an ID |
|
64 | + * by itself (e.g. after saving). |
|
65 | + * |
|
66 | + * @return string |
|
67 | + * @since 9.0.0 |
|
68 | + */ |
|
69 | + public function getId() { |
|
70 | + return $this->data['id']; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * sets the ID of the comment and returns itself |
|
75 | + * |
|
76 | + * It is only allowed to set the ID only, if the current id is an empty |
|
77 | + * string (which means it is not stored in a database, storage or whatever |
|
78 | + * the concrete implementation does), or vice versa. Changing a given ID is |
|
79 | + * not permitted and must result in an IllegalIDChangeException. |
|
80 | + * |
|
81 | + * @param string $id |
|
82 | + * @return IComment |
|
83 | + * @throws IllegalIDChangeException |
|
84 | + * @since 9.0.0 |
|
85 | + */ |
|
86 | + public function setId($id) { |
|
87 | + if(!is_string($id)) { |
|
88 | + throw new \InvalidArgumentException('String expected.'); |
|
89 | + } |
|
90 | + |
|
91 | + $id = trim($id); |
|
92 | + if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
93 | + $this->data['id'] = $id; |
|
94 | + return $this; |
|
95 | + } |
|
96 | + |
|
97 | + throw new IllegalIDChangeException('Not allowed to assign a new ID to an already saved comment.'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * returns the parent ID of the comment |
|
102 | + * |
|
103 | + * @return string |
|
104 | + * @since 9.0.0 |
|
105 | + */ |
|
106 | + public function getParentId() { |
|
107 | + return $this->data['parentId']; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * sets the parent ID and returns itself |
|
112 | + * |
|
113 | + * @param string $parentId |
|
114 | + * @return IComment |
|
115 | + * @since 9.0.0 |
|
116 | + */ |
|
117 | + public function setParentId($parentId) { |
|
118 | + if(!is_string($parentId)) { |
|
119 | + throw new \InvalidArgumentException('String expected.'); |
|
120 | + } |
|
121 | + $this->data['parentId'] = trim($parentId); |
|
122 | + return $this; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * returns the topmost parent ID of the comment |
|
127 | + * |
|
128 | + * @return string |
|
129 | + * @since 9.0.0 |
|
130 | + */ |
|
131 | + public function getTopmostParentId() { |
|
132 | + return $this->data['topmostParentId']; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * sets the topmost parent ID and returns itself |
|
138 | + * |
|
139 | + * @param string $id |
|
140 | + * @return IComment |
|
141 | + * @since 9.0.0 |
|
142 | + */ |
|
143 | + public function setTopmostParentId($id) { |
|
144 | + if(!is_string($id)) { |
|
145 | + throw new \InvalidArgumentException('String expected.'); |
|
146 | + } |
|
147 | + $this->data['topmostParentId'] = trim($id); |
|
148 | + return $this; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * returns the number of children |
|
153 | + * |
|
154 | + * @return int |
|
155 | + * @since 9.0.0 |
|
156 | + */ |
|
157 | + public function getChildrenCount() { |
|
158 | + return $this->data['childrenCount']; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * sets the number of children |
|
163 | + * |
|
164 | + * @param int $count |
|
165 | + * @return IComment |
|
166 | + * @since 9.0.0 |
|
167 | + */ |
|
168 | + public function setChildrenCount($count) { |
|
169 | + if(!is_int($count)) { |
|
170 | + throw new \InvalidArgumentException('Integer expected.'); |
|
171 | + } |
|
172 | + $this->data['childrenCount'] = $count; |
|
173 | + return $this; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * returns the message of the comment |
|
178 | + * |
|
179 | + * @return string |
|
180 | + * @since 9.0.0 |
|
181 | + */ |
|
182 | + public function getMessage() { |
|
183 | + return $this->data['message']; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * sets the message of the comment and returns itself |
|
188 | + * |
|
189 | + * @param string $message |
|
190 | + * @return IComment |
|
191 | + * @throws MessageTooLongException |
|
192 | + * @since 9.0.0 |
|
193 | + */ |
|
194 | + public function setMessage($message) { |
|
195 | + if(!is_string($message)) { |
|
196 | + throw new \InvalidArgumentException('String expected.'); |
|
197 | + } |
|
198 | + $message = trim($message); |
|
199 | + if(mb_strlen($message, 'UTF-8') > IComment::MAX_MESSAGE_LENGTH) { |
|
200 | + throw new MessageTooLongException('Comment message must not exceed ' . IComment::MAX_MESSAGE_LENGTH . ' characters'); |
|
201 | + } |
|
202 | + $this->data['message'] = $message; |
|
203 | + return $this; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * returns an array containing mentions that are included in the comment |
|
208 | + * |
|
209 | + * @return array each mention provides a 'type' and an 'id', see example below |
|
210 | + * @since 11.0.0 |
|
211 | + * |
|
212 | + * The return array looks like: |
|
213 | + * [ |
|
214 | + * [ |
|
215 | + * 'type' => 'user', |
|
216 | + * 'id' => 'citizen4' |
|
217 | + * ], |
|
218 | + * [ |
|
219 | + * 'type' => 'group', |
|
220 | + * 'id' => 'media' |
|
221 | + * ], |
|
222 | + * … |
|
223 | + * ] |
|
224 | + * |
|
225 | + */ |
|
226 | + public function getMentions() { |
|
227 | + $ok = preg_match_all('/\B@[a-z0-9_\-@\.\']+/i', $this->getMessage(), $mentions); |
|
228 | + if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
229 | + return []; |
|
230 | + } |
|
231 | + $uids = array_unique($mentions[0]); |
|
232 | + $result = []; |
|
233 | + foreach ($uids as $uid) { |
|
234 | + // exclude author, no self-mentioning |
|
235 | + if($uid === '@' . $this->getActorId()) { |
|
236 | + continue; |
|
237 | + } |
|
238 | + $result[] = ['type' => 'user', 'id' => substr($uid, 1)]; |
|
239 | + } |
|
240 | + return $result; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * returns the verb of the comment |
|
245 | + * |
|
246 | + * @return string |
|
247 | + * @since 9.0.0 |
|
248 | + */ |
|
249 | + public function getVerb() { |
|
250 | + return $this->data['verb']; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * sets the verb of the comment, e.g. 'comment' or 'like' |
|
255 | + * |
|
256 | + * @param string $verb |
|
257 | + * @return IComment |
|
258 | + * @since 9.0.0 |
|
259 | + */ |
|
260 | + public function setVerb($verb) { |
|
261 | + if(!is_string($verb) || !trim($verb)) { |
|
262 | + throw new \InvalidArgumentException('Non-empty String expected.'); |
|
263 | + } |
|
264 | + $this->data['verb'] = trim($verb); |
|
265 | + return $this; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * returns the actor type |
|
270 | + * |
|
271 | + * @return string |
|
272 | + * @since 9.0.0 |
|
273 | + */ |
|
274 | + public function getActorType() { |
|
275 | + return $this->data['actorType']; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * returns the actor ID |
|
280 | + * |
|
281 | + * @return string |
|
282 | + * @since 9.0.0 |
|
283 | + */ |
|
284 | + public function getActorId() { |
|
285 | + return $this->data['actorId']; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * sets (overwrites) the actor type and id |
|
290 | + * |
|
291 | + * @param string $actorType e.g. 'users' |
|
292 | + * @param string $actorId e.g. 'zombie234' |
|
293 | + * @return IComment |
|
294 | + * @since 9.0.0 |
|
295 | + */ |
|
296 | + public function setActor($actorType, $actorId) { |
|
297 | + if( |
|
298 | + !is_string($actorType) || !trim($actorType) |
|
299 | + || !is_string($actorId) || !trim($actorId) |
|
300 | + ) { |
|
301 | + throw new \InvalidArgumentException('String expected.'); |
|
302 | + } |
|
303 | + $this->data['actorType'] = trim($actorType); |
|
304 | + $this->data['actorId'] = trim($actorId); |
|
305 | + return $this; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * returns the creation date of the comment. |
|
310 | + * |
|
311 | + * If not explicitly set, it shall default to the time of initialization. |
|
312 | + * |
|
313 | + * @return \DateTime |
|
314 | + * @since 9.0.0 |
|
315 | + */ |
|
316 | + public function getCreationDateTime() { |
|
317 | + return $this->data['creationDT']; |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * sets the creation date of the comment and returns itself |
|
322 | + * |
|
323 | + * @param \DateTime $timestamp |
|
324 | + * @return IComment |
|
325 | + * @since 9.0.0 |
|
326 | + */ |
|
327 | + public function setCreationDateTime(\DateTime $timestamp) { |
|
328 | + $this->data['creationDT'] = $timestamp; |
|
329 | + return $this; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * returns the DateTime of the most recent child, if set, otherwise null |
|
334 | + * |
|
335 | + * @return \DateTime|null |
|
336 | + * @since 9.0.0 |
|
337 | + */ |
|
338 | + public function getLatestChildDateTime() { |
|
339 | + return $this->data['latestChildDT']; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * sets the date of the most recent child |
|
344 | + * |
|
345 | + * @param \DateTime $dateTime |
|
346 | + * @return IComment |
|
347 | + * @since 9.0.0 |
|
348 | + */ |
|
349 | + public function setLatestChildDateTime(\DateTime $dateTime = null) { |
|
350 | + $this->data['latestChildDT'] = $dateTime; |
|
351 | + return $this; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * returns the object type the comment is attached to |
|
356 | + * |
|
357 | + * @return string |
|
358 | + * @since 9.0.0 |
|
359 | + */ |
|
360 | + public function getObjectType() { |
|
361 | + return $this->data['objectType']; |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * returns the object id the comment is attached to |
|
366 | + * |
|
367 | + * @return string |
|
368 | + * @since 9.0.0 |
|
369 | + */ |
|
370 | + public function getObjectId() { |
|
371 | + return $this->data['objectId']; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * sets (overwrites) the object of the comment |
|
376 | + * |
|
377 | + * @param string $objectType e.g. 'files' |
|
378 | + * @param string $objectId e.g. '16435' |
|
379 | + * @return IComment |
|
380 | + * @since 9.0.0 |
|
381 | + */ |
|
382 | + public function setObject($objectType, $objectId) { |
|
383 | + if( |
|
384 | + !is_string($objectType) || !trim($objectType) |
|
385 | + || !is_string($objectId) || !trim($objectId) |
|
386 | + ) { |
|
387 | + throw new \InvalidArgumentException('String expected.'); |
|
388 | + } |
|
389 | + $this->data['objectType'] = trim($objectType); |
|
390 | + $this->data['objectId'] = trim($objectId); |
|
391 | + return $this; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * sets the comment data based on an array with keys as taken from the |
|
396 | + * database. |
|
397 | + * |
|
398 | + * @param array $data |
|
399 | + * @return IComment |
|
400 | + */ |
|
401 | + protected function fromArray($data) { |
|
402 | + foreach(array_keys($data) as $key) { |
|
403 | + // translate DB keys to internal setter names |
|
404 | + $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
405 | + $setter = str_replace('Timestamp', 'DateTime', $setter); |
|
406 | + |
|
407 | + if(method_exists($this, $setter)) { |
|
408 | + $this->$setter($data[$key]); |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + foreach(['actor', 'object'] as $role) { |
|
413 | + if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
414 | + $setter = 'set' . ucfirst($role); |
|
415 | + $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + return $this; |
|
420 | + } |
|
421 | 421 | } |