Completed
Pull Request — master (#3233)
by Christoph
95:52 queued 83:56
created
lib/public/AppFramework/Http.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -35,63 +35,63 @@
 block discarded – undo
35 35
  */
36 36
 class Http {
37 37
 
38
-	const STATUS_CONTINUE = 100;
39
-	const STATUS_SWITCHING_PROTOCOLS = 101;
40
-	const STATUS_PROCESSING = 102;
41
-	const STATUS_OK = 200;
42
-	const STATUS_CREATED = 201;
43
-	const STATUS_ACCEPTED = 202;
44
-	const STATUS_NON_AUTHORATIVE_INFORMATION = 203;
45
-	const STATUS_NO_CONTENT = 204;
46
-	const STATUS_RESET_CONTENT = 205;
47
-	const STATUS_PARTIAL_CONTENT = 206;
48
-	const STATUS_MULTI_STATUS = 207;
49
-	const STATUS_ALREADY_REPORTED = 208;
50
-	const STATUS_IM_USED = 226;
51
-	const STATUS_MULTIPLE_CHOICES = 300;
52
-	const STATUS_MOVED_PERMANENTLY = 301;
53
-	const STATUS_FOUND = 302;
54
-	const STATUS_SEE_OTHER = 303;
55
-	const STATUS_NOT_MODIFIED = 304;
56
-	const STATUS_USE_PROXY = 305;
57
-	const STATUS_RESERVED = 306;
58
-	const STATUS_TEMPORARY_REDIRECT = 307;
59
-	const STATUS_BAD_REQUEST = 400;
60
-	const STATUS_UNAUTHORIZED = 401;
61
-	const STATUS_PAYMENT_REQUIRED = 402;
62
-	const STATUS_FORBIDDEN = 403;
63
-	const STATUS_NOT_FOUND = 404;
64
-	const STATUS_METHOD_NOT_ALLOWED = 405;
65
-	const STATUS_NOT_ACCEPTABLE = 406;
66
-	const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407;
67
-	const STATUS_REQUEST_TIMEOUT = 408;
68
-	const STATUS_CONFLICT = 409;
69
-	const STATUS_GONE = 410;
70
-	const STATUS_LENGTH_REQUIRED = 411;
71
-	const STATUS_PRECONDITION_FAILED = 412;
72
-	const STATUS_REQUEST_ENTITY_TOO_LARGE = 413;
73
-	const STATUS_REQUEST_URI_TOO_LONG = 414;
74
-	const STATUS_UNSUPPORTED_MEDIA_TYPE = 415;
75
-	const STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416;
76
-	const STATUS_EXPECTATION_FAILED = 417;
77
-	const STATUS_IM_A_TEAPOT = 418;
78
-	const STATUS_UNPROCESSABLE_ENTITY = 422;
79
-	const STATUS_LOCKED = 423;
80
-	const STATUS_FAILED_DEPENDENCY = 424;
81
-	const STATUS_UPGRADE_REQUIRED = 426;
82
-	const STATUS_PRECONDITION_REQUIRED = 428;
83
-	const STATUS_TOO_MANY_REQUESTS = 429;
84
-	const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
85
-	const STATUS_INTERNAL_SERVER_ERROR = 500;
86
-	const STATUS_NOT_IMPLEMENTED = 501;
87
-	const STATUS_BAD_GATEWAY = 502;
88
-	const STATUS_SERVICE_UNAVAILABLE = 503;
89
-	const STATUS_GATEWAY_TIMEOUT = 504;
90
-	const STATUS_HTTP_VERSION_NOT_SUPPORTED = 505;
91
-	const STATUS_VARIANT_ALSO_NEGOTIATES = 506;
92
-	const STATUS_INSUFFICIENT_STORAGE = 507;
93
-	const STATUS_LOOP_DETECTED = 508;
94
-	const STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509;
95
-	const STATUS_NOT_EXTENDED = 510;
96
-	const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511;
38
+    const STATUS_CONTINUE = 100;
39
+    const STATUS_SWITCHING_PROTOCOLS = 101;
40
+    const STATUS_PROCESSING = 102;
41
+    const STATUS_OK = 200;
42
+    const STATUS_CREATED = 201;
43
+    const STATUS_ACCEPTED = 202;
44
+    const STATUS_NON_AUTHORATIVE_INFORMATION = 203;
45
+    const STATUS_NO_CONTENT = 204;
46
+    const STATUS_RESET_CONTENT = 205;
47
+    const STATUS_PARTIAL_CONTENT = 206;
48
+    const STATUS_MULTI_STATUS = 207;
49
+    const STATUS_ALREADY_REPORTED = 208;
50
+    const STATUS_IM_USED = 226;
51
+    const STATUS_MULTIPLE_CHOICES = 300;
52
+    const STATUS_MOVED_PERMANENTLY = 301;
53
+    const STATUS_FOUND = 302;
54
+    const STATUS_SEE_OTHER = 303;
55
+    const STATUS_NOT_MODIFIED = 304;
56
+    const STATUS_USE_PROXY = 305;
57
+    const STATUS_RESERVED = 306;
58
+    const STATUS_TEMPORARY_REDIRECT = 307;
59
+    const STATUS_BAD_REQUEST = 400;
60
+    const STATUS_UNAUTHORIZED = 401;
61
+    const STATUS_PAYMENT_REQUIRED = 402;
62
+    const STATUS_FORBIDDEN = 403;
63
+    const STATUS_NOT_FOUND = 404;
64
+    const STATUS_METHOD_NOT_ALLOWED = 405;
65
+    const STATUS_NOT_ACCEPTABLE = 406;
66
+    const STATUS_PROXY_AUTHENTICATION_REQUIRED = 407;
67
+    const STATUS_REQUEST_TIMEOUT = 408;
68
+    const STATUS_CONFLICT = 409;
69
+    const STATUS_GONE = 410;
70
+    const STATUS_LENGTH_REQUIRED = 411;
71
+    const STATUS_PRECONDITION_FAILED = 412;
72
+    const STATUS_REQUEST_ENTITY_TOO_LARGE = 413;
73
+    const STATUS_REQUEST_URI_TOO_LONG = 414;
74
+    const STATUS_UNSUPPORTED_MEDIA_TYPE = 415;
75
+    const STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416;
76
+    const STATUS_EXPECTATION_FAILED = 417;
77
+    const STATUS_IM_A_TEAPOT = 418;
78
+    const STATUS_UNPROCESSABLE_ENTITY = 422;
79
+    const STATUS_LOCKED = 423;
80
+    const STATUS_FAILED_DEPENDENCY = 424;
81
+    const STATUS_UPGRADE_REQUIRED = 426;
82
+    const STATUS_PRECONDITION_REQUIRED = 428;
83
+    const STATUS_TOO_MANY_REQUESTS = 429;
84
+    const STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
85
+    const STATUS_INTERNAL_SERVER_ERROR = 500;
86
+    const STATUS_NOT_IMPLEMENTED = 501;
87
+    const STATUS_BAD_GATEWAY = 502;
88
+    const STATUS_SERVICE_UNAVAILABLE = 503;
89
+    const STATUS_GATEWAY_TIMEOUT = 504;
90
+    const STATUS_HTTP_VERSION_NOT_SUPPORTED = 505;
91
+    const STATUS_VARIANT_ALSO_NEGOTIATES = 506;
92
+    const STATUS_INSUFFICIENT_STORAGE = 507;
93
+    const STATUS_LOOP_DETECTED = 508;
94
+    const STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509;
95
+    const STATUS_NOT_EXTENDED = 510;
96
+    const STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511;
97 97
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/IAppContainer.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -38,61 +38,61 @@
 block discarded – undo
38 38
  */
39 39
 interface IAppContainer extends IContainer {
40 40
 
41
-	/**
42
-	 * used to return the appname of the set application
43
-	 * @return string the name of your application
44
-	 * @since 6.0.0
45
-	 */
46
-	function getAppName();
41
+    /**
42
+     * used to return the appname of the set application
43
+     * @return string the name of your application
44
+     * @since 6.0.0
45
+     */
46
+    function getAppName();
47 47
 
48
-	/**
49
-	 * @deprecated 8.0.0 implements only deprecated methods
50
-	 * @return IApi
51
-	 * @since 6.0.0
52
-	 */
53
-	function getCoreApi();
48
+    /**
49
+     * @deprecated 8.0.0 implements only deprecated methods
50
+     * @return IApi
51
+     * @since 6.0.0
52
+     */
53
+    function getCoreApi();
54 54
 
55
-	/**
56
-	 * @return \OCP\IServerContainer
57
-	 * @since 6.0.0
58
-	 */
59
-	function getServer();
55
+    /**
56
+     * @return \OCP\IServerContainer
57
+     * @since 6.0.0
58
+     */
59
+    function getServer();
60 60
 
61
-	/**
62
-	 * @param string $middleWare
63
-	 * @return boolean
64
-	 * @since 6.0.0
65
-	 */
66
-	function registerMiddleWare($middleWare);
61
+    /**
62
+     * @param string $middleWare
63
+     * @return boolean
64
+     * @since 6.0.0
65
+     */
66
+    function registerMiddleWare($middleWare);
67 67
 
68
-	/**
69
-	 * @deprecated 8.0.0 use IUserSession->isLoggedIn()
70
-	 * @return boolean
71
-	 * @since 6.0.0
72
-	 */
73
-	function isLoggedIn();
68
+    /**
69
+     * @deprecated 8.0.0 use IUserSession->isLoggedIn()
70
+     * @return boolean
71
+     * @since 6.0.0
72
+     */
73
+    function isLoggedIn();
74 74
 
75
-	/**
76
-	 * @deprecated 8.0.0 use IGroupManager->isAdmin($userId)
77
-	 * @return boolean
78
-	 * @since 6.0.0
79
-	 */
80
-	function isAdminUser();
75
+    /**
76
+     * @deprecated 8.0.0 use IGroupManager->isAdmin($userId)
77
+     * @return boolean
78
+     * @since 6.0.0
79
+     */
80
+    function isAdminUser();
81 81
 
82
-	/**
83
-	 * @deprecated 8.0.0 use the ILogger instead
84
-	 * @param string $message
85
-	 * @param string $level
86
-	 * @return mixed
87
-	 * @since 6.0.0
88
-	 */
89
-	function log($message, $level);
82
+    /**
83
+     * @deprecated 8.0.0 use the ILogger instead
84
+     * @param string $message
85
+     * @param string $level
86
+     * @return mixed
87
+     * @since 6.0.0
88
+     */
89
+    function log($message, $level);
90 90
 
91
-	/**
92
-	 * Register a capability
93
-	 *
94
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
95
-	 * @since 8.2.0
96
-	 */
97
-	 public function registerCapability($serviceName);
91
+    /**
92
+     * Register a capability
93
+     *
94
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
95
+     * @since 8.2.0
96
+     */
97
+        public function registerCapability($serviceName);
98 98
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSForbiddenException.php 1 patch
Indentation   +10 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-
4 3
  *
5 4
  * @author Roeland Jago Douma <[email protected]>
6 5
  *
@@ -32,14 +31,14 @@  discard block
 block discarded – undo
32 31
  * @since 9.1.0
33 32
  */
34 33
 class OCSForbiddenException extends OCSException {
35
-	/**
36
-	 * OCSForbiddenException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
44
-	}
34
+    /**
35
+     * OCSForbiddenException constructor.
36
+     *
37
+     * @param string $message
38
+     * @param Exception|null $previous
39
+     * @since 9.1.0
40
+     */
41
+    public function __construct($message = '', Exception $previous = null) {
42
+        parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
43
+    }
45 44
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSBadRequestException.php 1 patch
Indentation   +10 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-
4 3
  *
5 4
  * @author Roeland Jago Douma <[email protected]>
6 5
  *
@@ -32,15 +31,15 @@  discard block
 block discarded – undo
32 31
  * @since 9.1.0
33 32
  */
34 33
 class OCSBadRequestException extends OCSException {
35
-	/**
36
-	 * OCSBadRequestException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
44
-	}
34
+    /**
35
+     * OCSBadRequestException constructor.
36
+     *
37
+     * @param string $message
38
+     * @param Exception|null $previous
39
+     * @since 9.1.0
40
+     */
41
+    public function __construct($message = '', Exception $previous = null) {
42
+        parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
43
+    }
45 44
 
46 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSNotFoundException.php 1 patch
Indentation   +10 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-
4 3
  *
5 4
  * @author Roeland Jago Douma <[email protected]>
6 5
  *
@@ -32,14 +31,14 @@  discard block
 block discarded – undo
32 31
  * @since 9.1.0
33 32
  */
34 33
 class OCSNotFoundException extends OCSException {
35
-	/**
36
-	 * OCSNotFoundException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
44
-	}
34
+    /**
35
+     * OCSNotFoundException constructor.
36
+     *
37
+     * @param string $message
38
+     * @param Exception|null $previous
39
+     * @since 9.1.0
40
+     */
41
+    public function __construct($message = '', Exception $previous = null) {
42
+        parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
43
+    }
45 44
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSException.php 1 patch
Indentation   -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
-
4 3
  *
5 4
  * @author Roeland Jago Douma <[email protected]>
6 5
  *
Please login to merge, or discard this patch.
lib/public/AppFramework/Controller.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -45,219 +45,219 @@
 block discarded – undo
45 45
  */
46 46
 abstract class Controller {
47 47
 
48
-	/**
49
-	 * app name
50
-	 * @var string
51
-	 * @since 7.0.0
52
-	 */
53
-	protected $appName;
54
-
55
-	/**
56
-	 * current request
57
-	 * @var \OCP\IRequest
58
-	 * @since 6.0.0
59
-	 */
60
-	protected $request;
61
-
62
-	/**
63
-	 * @var array
64
-	 * @since 7.0.0
65
-	 */
66
-	private $responders;
67
-
68
-	/**
69
-	 * constructor of the controller
70
-	 * @param string $appName the name of the app
71
-	 * @param IRequest $request an instance of the request
72
-	 * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
73
-	 */
74
-	public function __construct($appName,
75
-	                            IRequest $request) {
76
-		$this->appName = $appName;
77
-		$this->request = $request;
78
-
79
-		// default responders
80
-		$this->responders = array(
81
-			'json' => function ($data) {
82
-				if ($data instanceof DataResponse) {
83
-					$response = new JSONResponse(
84
-						$data->getData(),
85
-						$data->getStatus()
86
-					);
87
-					$dataHeaders = $data->getHeaders();
88
-					$headers = $response->getHeaders();
89
-					// do not overwrite Content-Type if it already exists
90
-					if (isset($dataHeaders['Content-Type'])) {
91
-						unset($headers['Content-Type']);
92
-					}
93
-					$response->setHeaders(array_merge($dataHeaders, $headers));
94
-					return $response;
95
-				}
96
-				return new JSONResponse($data);
97
-			}
98
-		);
99
-	}
100
-
101
-
102
-	/**
103
-	 * Parses an HTTP accept header and returns the supported responder type
104
-	 * @param string $acceptHeader
105
-	 * @return string the responder type
106
-	 * @since 7.0.0
107
-	 * @since 9.1.0 Added default parameter
108
-	 */
109
-	public function getResponderByHTTPHeader($acceptHeader, $default='json') {
110
-		$headers = explode(',', $acceptHeader);
111
-
112
-		// return the first matching responder
113
-		foreach ($headers as $header) {
114
-			$header = strtolower(trim($header));
115
-
116
-			$responder = str_replace('application/', '', $header);
117
-
118
-			if (array_key_exists($responder, $this->responders)) {
119
-				return $responder;
120
-			}
121
-		}
122
-
123
-		// no matching header return default
124
-		return $default;
125
-	}
126
-
127
-
128
-	/**
129
-	 * Registers a formatter for a type
130
-	 * @param string $format
131
-	 * @param \Closure $responder
132
-	 * @since 7.0.0
133
-	 */
134
-	protected function registerResponder($format, \Closure $responder) {
135
-		$this->responders[$format] = $responder;
136
-	}
137
-
138
-
139
-	/**
140
-	 * Serializes and formats a response
141
-	 * @param mixed $response the value that was returned from a controller and
142
-	 * is not a Response instance
143
-	 * @param string $format the format for which a formatter has been registered
144
-	 * @throws \DomainException if format does not match a registered formatter
145
-	 * @return Response
146
-	 * @since 7.0.0
147
-	 */
148
-	public function buildResponse($response, $format='json') {
149
-		if(array_key_exists($format, $this->responders)) {
150
-
151
-			$responder = $this->responders[$format];
152
-
153
-			return $responder($response);
154
-
155
-		}
156
-		throw new \DomainException('No responder registered for format '.
157
-			$format . '!');
158
-	}
159
-
160
-
161
-	/**
162
-	 * Lets you access post and get parameters by the index
163
-	 * @deprecated 7.0.0 write your parameters as method arguments instead
164
-	 * @param string $key the key which you want to access in the URL Parameter
165
-	 *                     placeholder, $_POST or $_GET array.
166
-	 *                     The priority how they're returned is the following:
167
-	 *                     1. URL parameters
168
-	 *                     2. POST parameters
169
-	 *                     3. GET parameters
170
-	 * @param string $default If the key is not found, this value will be returned
171
-	 * @return mixed the content of the array
172
-	 * @since 6.0.0
173
-	 */
174
-	public function params($key, $default=null){
175
-		return $this->request->getParam($key, $default);
176
-	}
177
-
178
-
179
-	/**
180
-	 * Returns all params that were received, be it from the request
181
-	 * (as GET or POST) or through the URL by the route
182
-	 * @deprecated 7.0.0 use $this->request instead
183
-	 * @return array the array with all parameters
184
-	 * @since 6.0.0
185
-	 */
186
-	public function getParams() {
187
-		return $this->request->getParams();
188
-	}
189
-
190
-
191
-	/**
192
-	 * Returns the method of the request
193
-	 * @deprecated 7.0.0 use $this->request instead
194
-	 * @return string the method of the request (POST, GET, etc)
195
-	 * @since 6.0.0
196
-	 */
197
-	public function method() {
198
-		return $this->request->getMethod();
199
-	}
200
-
201
-
202
-	/**
203
-	 * Shortcut for accessing an uploaded file through the $_FILES array
204
-	 * @deprecated 7.0.0 use $this->request instead
205
-	 * @param string $key the key that will be taken from the $_FILES array
206
-	 * @return array the file in the $_FILES element
207
-	 * @since 6.0.0
208
-	 */
209
-	public function getUploadedFile($key) {
210
-		return $this->request->getUploadedFile($key);
211
-	}
212
-
213
-
214
-	/**
215
-	 * Shortcut for getting env variables
216
-	 * @deprecated 7.0.0 use $this->request instead
217
-	 * @param string $key the key that will be taken from the $_ENV array
218
-	 * @return array the value in the $_ENV element
219
-	 * @since 6.0.0
220
-	 */
221
-	public function env($key) {
222
-		return $this->request->getEnv($key);
223
-	}
224
-
225
-
226
-	/**
227
-	 * Shortcut for getting cookie variables
228
-	 * @deprecated 7.0.0 use $this->request instead
229
-	 * @param string $key the key that will be taken from the $_COOKIE array
230
-	 * @return array the value in the $_COOKIE element
231
-	 * @since 6.0.0
232
-	 */
233
-	public function cookie($key) {
234
-		return $this->request->getCookie($key);
235
-	}
236
-
237
-
238
-	/**
239
-	 * Shortcut for rendering a template
240
-	 * @deprecated 7.0.0 return a template response instead
241
-	 * @param string $templateName the name of the template
242
-	 * @param array $params the template parameters in key => value structure
243
-	 * @param string $renderAs user renders a full page, blank only your template
244
-	 *                          admin an entry in the admin settings
245
-	 * @param string[] $headers set additional headers in name/value pairs
246
-	 * @return \OCP\AppFramework\Http\TemplateResponse containing the page
247
-	 * @since 6.0.0
248
-	 */
249
-	public function render($templateName, array $params=array(),
250
-							$renderAs='user', array $headers=array()){
251
-		$response = new TemplateResponse($this->appName, $templateName);
252
-		$response->setParams($params);
253
-		$response->renderAs($renderAs);
254
-
255
-		foreach($headers as $name => $value){
256
-			$response->addHeader($name, $value);
257
-		}
258
-
259
-		return $response;
260
-	}
48
+    /**
49
+     * app name
50
+     * @var string
51
+     * @since 7.0.0
52
+     */
53
+    protected $appName;
54
+
55
+    /**
56
+     * current request
57
+     * @var \OCP\IRequest
58
+     * @since 6.0.0
59
+     */
60
+    protected $request;
61
+
62
+    /**
63
+     * @var array
64
+     * @since 7.0.0
65
+     */
66
+    private $responders;
67
+
68
+    /**
69
+     * constructor of the controller
70
+     * @param string $appName the name of the app
71
+     * @param IRequest $request an instance of the request
72
+     * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
73
+     */
74
+    public function __construct($appName,
75
+                                IRequest $request) {
76
+        $this->appName = $appName;
77
+        $this->request = $request;
78
+
79
+        // default responders
80
+        $this->responders = array(
81
+            'json' => function ($data) {
82
+                if ($data instanceof DataResponse) {
83
+                    $response = new JSONResponse(
84
+                        $data->getData(),
85
+                        $data->getStatus()
86
+                    );
87
+                    $dataHeaders = $data->getHeaders();
88
+                    $headers = $response->getHeaders();
89
+                    // do not overwrite Content-Type if it already exists
90
+                    if (isset($dataHeaders['Content-Type'])) {
91
+                        unset($headers['Content-Type']);
92
+                    }
93
+                    $response->setHeaders(array_merge($dataHeaders, $headers));
94
+                    return $response;
95
+                }
96
+                return new JSONResponse($data);
97
+            }
98
+        );
99
+    }
100
+
101
+
102
+    /**
103
+     * Parses an HTTP accept header and returns the supported responder type
104
+     * @param string $acceptHeader
105
+     * @return string the responder type
106
+     * @since 7.0.0
107
+     * @since 9.1.0 Added default parameter
108
+     */
109
+    public function getResponderByHTTPHeader($acceptHeader, $default='json') {
110
+        $headers = explode(',', $acceptHeader);
111
+
112
+        // return the first matching responder
113
+        foreach ($headers as $header) {
114
+            $header = strtolower(trim($header));
115
+
116
+            $responder = str_replace('application/', '', $header);
117
+
118
+            if (array_key_exists($responder, $this->responders)) {
119
+                return $responder;
120
+            }
121
+        }
122
+
123
+        // no matching header return default
124
+        return $default;
125
+    }
126
+
127
+
128
+    /**
129
+     * Registers a formatter for a type
130
+     * @param string $format
131
+     * @param \Closure $responder
132
+     * @since 7.0.0
133
+     */
134
+    protected function registerResponder($format, \Closure $responder) {
135
+        $this->responders[$format] = $responder;
136
+    }
137
+
138
+
139
+    /**
140
+     * Serializes and formats a response
141
+     * @param mixed $response the value that was returned from a controller and
142
+     * is not a Response instance
143
+     * @param string $format the format for which a formatter has been registered
144
+     * @throws \DomainException if format does not match a registered formatter
145
+     * @return Response
146
+     * @since 7.0.0
147
+     */
148
+    public function buildResponse($response, $format='json') {
149
+        if(array_key_exists($format, $this->responders)) {
150
+
151
+            $responder = $this->responders[$format];
152
+
153
+            return $responder($response);
154
+
155
+        }
156
+        throw new \DomainException('No responder registered for format '.
157
+            $format . '!');
158
+    }
159
+
160
+
161
+    /**
162
+     * Lets you access post and get parameters by the index
163
+     * @deprecated 7.0.0 write your parameters as method arguments instead
164
+     * @param string $key the key which you want to access in the URL Parameter
165
+     *                     placeholder, $_POST or $_GET array.
166
+     *                     The priority how they're returned is the following:
167
+     *                     1. URL parameters
168
+     *                     2. POST parameters
169
+     *                     3. GET parameters
170
+     * @param string $default If the key is not found, this value will be returned
171
+     * @return mixed the content of the array
172
+     * @since 6.0.0
173
+     */
174
+    public function params($key, $default=null){
175
+        return $this->request->getParam($key, $default);
176
+    }
177
+
178
+
179
+    /**
180
+     * Returns all params that were received, be it from the request
181
+     * (as GET or POST) or through the URL by the route
182
+     * @deprecated 7.0.0 use $this->request instead
183
+     * @return array the array with all parameters
184
+     * @since 6.0.0
185
+     */
186
+    public function getParams() {
187
+        return $this->request->getParams();
188
+    }
189
+
190
+
191
+    /**
192
+     * Returns the method of the request
193
+     * @deprecated 7.0.0 use $this->request instead
194
+     * @return string the method of the request (POST, GET, etc)
195
+     * @since 6.0.0
196
+     */
197
+    public function method() {
198
+        return $this->request->getMethod();
199
+    }
200
+
201
+
202
+    /**
203
+     * Shortcut for accessing an uploaded file through the $_FILES array
204
+     * @deprecated 7.0.0 use $this->request instead
205
+     * @param string $key the key that will be taken from the $_FILES array
206
+     * @return array the file in the $_FILES element
207
+     * @since 6.0.0
208
+     */
209
+    public function getUploadedFile($key) {
210
+        return $this->request->getUploadedFile($key);
211
+    }
212
+
213
+
214
+    /**
215
+     * Shortcut for getting env variables
216
+     * @deprecated 7.0.0 use $this->request instead
217
+     * @param string $key the key that will be taken from the $_ENV array
218
+     * @return array the value in the $_ENV element
219
+     * @since 6.0.0
220
+     */
221
+    public function env($key) {
222
+        return $this->request->getEnv($key);
223
+    }
224
+
225
+
226
+    /**
227
+     * Shortcut for getting cookie variables
228
+     * @deprecated 7.0.0 use $this->request instead
229
+     * @param string $key the key that will be taken from the $_COOKIE array
230
+     * @return array the value in the $_COOKIE element
231
+     * @since 6.0.0
232
+     */
233
+    public function cookie($key) {
234
+        return $this->request->getCookie($key);
235
+    }
236
+
237
+
238
+    /**
239
+     * Shortcut for rendering a template
240
+     * @deprecated 7.0.0 return a template response instead
241
+     * @param string $templateName the name of the template
242
+     * @param array $params the template parameters in key => value structure
243
+     * @param string $renderAs user renders a full page, blank only your template
244
+     *                          admin an entry in the admin settings
245
+     * @param string[] $headers set additional headers in name/value pairs
246
+     * @return \OCP\AppFramework\Http\TemplateResponse containing the page
247
+     * @since 6.0.0
248
+     */
249
+    public function render($templateName, array $params=array(),
250
+                            $renderAs='user', array $headers=array()){
251
+        $response = new TemplateResponse($this->appName, $templateName);
252
+        $response->setParams($params);
253
+        $response->renderAs($renderAs);
254
+
255
+        foreach($headers as $name => $value){
256
+            $response->addHeader($name, $value);
257
+        }
258
+
259
+        return $response;
260
+    }
261 261
 
262 262
 
263 263
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/ApiController.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * defaults to 'Authorization, Content-Type, Accept'
56 56
      * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS
57 57
      * request should be cached, defaults to 1728000 seconds
58
-	 * @since 7.0.0
58
+     * @since 7.0.0
59 59
      */
60 60
     public function __construct($appName,
61 61
                                 IRequest $request,
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * @NoAdminRequired
77 77
      * @NoCSRFRequired
78 78
      * @PublicPage
79
-	 * @since 7.0.0
79
+     * @since 7.0.0
80 80
      */
81 81
     public function preflightedCors() {
82 82
         if(isset($this->request->server['HTTP_ORIGIN'])) {
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/MultipleObjectsReturnedException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  */
33 33
 class MultipleObjectsReturnedException extends \Exception {
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 * @param string $msg the error message
38
-	 * @since 7.0.0
39
-	 */
40
-	public function __construct($msg){
41
-		parent::__construct($msg);
42
-	}
35
+    /**
36
+     * Constructor
37
+     * @param string $msg the error message
38
+     * @since 7.0.0
39
+     */
40
+    public function __construct($msg){
41
+        parent::__construct($msg);
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.