Passed
Push — master ( 34aa51...29d78e )
by Roeland
12:50 queued 10s
created
lib/public/AppFramework/Http/NotFoundResponse.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -31,21 +31,21 @@
 block discarded – undo
31 31
  */
32 32
 class NotFoundResponse extends Response {
33 33
 
34
-	/**
35
-	 * @since 8.1.0
36
-	 */
37
-	public function __construct() {
38
-		parent::__construct();
34
+    /**
35
+     * @since 8.1.0
36
+     */
37
+    public function __construct() {
38
+        parent::__construct();
39 39
 
40
-		$this->setStatus(404);
41
-	}
40
+        $this->setStatus(404);
41
+    }
42 42
 
43
-	/**
44
-	 * @return string
45
-	 * @since 8.1.0
46
-	 */
47
-	public function render() {
48
-		$template = new Template('core', '404', 'guest');
49
-		return $template->fetchPage();
50
-	}
43
+    /**
44
+     * @return string
45
+     * @since 8.1.0
46
+     */
47
+    public function render() {
48
+        $template = new Template('core', '404', 'guest');
49
+        return $template->fetchPage();
50
+    }
51 51
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/OCSResponse.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -38,61 +38,61 @@
 block discarded – undo
38 38
  */
39 39
 class OCSResponse extends Response {
40 40
 
41
-	private $data;
42
-	private $format;
43
-	private $statuscode;
44
-	private $message;
45
-	private $itemscount;
46
-	private $itemsperpage;
41
+    private $data;
42
+    private $format;
43
+    private $statuscode;
44
+    private $message;
45
+    private $itemscount;
46
+    private $itemsperpage;
47 47
 
48
-	/**
49
-	 * generates the xml or json response for the API call from an multidimenional data array.
50
-	 * @param string $format
51
-	 * @param int $statuscode
52
-	 * @param string $message
53
-	 * @param array $data
54
-	 * @param int|string $itemscount
55
-	 * @param int|string $itemsperpage
56
-	 * @since 8.1.0
57
-	 * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
58
-	 */
59
-	public function __construct($format, $statuscode, $message,
60
-								$data=[], $itemscount='',
61
-								$itemsperpage='') {
62
-		parent::__construct();
48
+    /**
49
+     * generates the xml or json response for the API call from an multidimenional data array.
50
+     * @param string $format
51
+     * @param int $statuscode
52
+     * @param string $message
53
+     * @param array $data
54
+     * @param int|string $itemscount
55
+     * @param int|string $itemsperpage
56
+     * @since 8.1.0
57
+     * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
58
+     */
59
+    public function __construct($format, $statuscode, $message,
60
+                                $data=[], $itemscount='',
61
+                                $itemsperpage='') {
62
+        parent::__construct();
63 63
 
64
-		$this->format = $format;
65
-		$this->statuscode = $statuscode;
66
-		$this->message = $message;
67
-		$this->data = $data;
68
-		$this->itemscount = $itemscount;
69
-		$this->itemsperpage = $itemsperpage;
64
+        $this->format = $format;
65
+        $this->statuscode = $statuscode;
66
+        $this->message = $message;
67
+        $this->data = $data;
68
+        $this->itemscount = $itemscount;
69
+        $this->itemsperpage = $itemsperpage;
70 70
 
71
-		// set the correct header based on the format parameter
72
-		if ($format === 'json') {
73
-			$this->addHeader(
74
-				'Content-Type', 'application/json; charset=utf-8'
75
-			);
76
-		} else {
77
-			$this->addHeader(
78
-				'Content-Type', 'application/xml; charset=utf-8'
79
-			);
80
-		}
81
-	}
71
+        // set the correct header based on the format parameter
72
+        if ($format === 'json') {
73
+            $this->addHeader(
74
+                'Content-Type', 'application/json; charset=utf-8'
75
+            );
76
+        } else {
77
+            $this->addHeader(
78
+                'Content-Type', 'application/xml; charset=utf-8'
79
+            );
80
+        }
81
+    }
82 82
 
83
-	/**
84
-	 * @return string
85
-	 * @since 8.1.0
86
-	 * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
87
-	 * @suppress PhanDeprecatedClass
88
-	 */
89
-	public function render() {
90
-		$r = new \OC\OCS\Result($this->data, $this->statuscode, $this->message);
91
-		$r->setTotalItems($this->itemscount);
92
-		$r->setItemsPerPage($this->itemsperpage);
83
+    /**
84
+     * @return string
85
+     * @since 8.1.0
86
+     * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
87
+     * @suppress PhanDeprecatedClass
88
+     */
89
+    public function render() {
90
+        $r = new \OC\OCS\Result($this->data, $this->statuscode, $this->message);
91
+        $r->setTotalItems($this->itemscount);
92
+        $r->setItemsPerPage($this->itemsperpage);
93 93
 
94
-		return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
95
-	}
94
+        return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData());
95
+    }
96 96
 
97 97
 
98 98
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@
 block discarded – undo
57 57
 	 * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController
58 58
 	 */
59 59
 	public function __construct($format, $statuscode, $message,
60
-								$data=[], $itemscount='',
61
-								$itemsperpage='') {
60
+								$data = [], $itemscount = '',
61
+								$itemsperpage = '') {
62 62
 		parent::__construct();
63 63
 
64 64
 		$this->format = $format;
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DataResponse.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -37,50 +37,50 @@
 block discarded – undo
37 37
  */
38 38
 class DataResponse extends Response {
39 39
 
40
-	/**
41
-	 * response data
42
-	 * @var array|object
43
-	 */
44
-	protected $data;
40
+    /**
41
+     * response data
42
+     * @var array|object
43
+     */
44
+    protected $data;
45 45
 
46 46
 
47
-	/**
48
-	 * @param array|object $data the object or array that should be transformed
49
-	 * @param int $statusCode the Http status code, defaults to 200
50
-	 * @param array $headers additional key value based headers
51
-	 * @since 8.0.0
52
-	 */
53
-	public function __construct($data=array(), $statusCode=Http::STATUS_OK,
54
-	                            array $headers=array()) {
55
-		parent::__construct();
47
+    /**
48
+     * @param array|object $data the object or array that should be transformed
49
+     * @param int $statusCode the Http status code, defaults to 200
50
+     * @param array $headers additional key value based headers
51
+     * @since 8.0.0
52
+     */
53
+    public function __construct($data=array(), $statusCode=Http::STATUS_OK,
54
+                                array $headers=array()) {
55
+        parent::__construct();
56 56
 
57
-		$this->data = $data;
58
-		$this->setStatus($statusCode);
59
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
60
-	}
57
+        $this->data = $data;
58
+        $this->setStatus($statusCode);
59
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
60
+    }
61 61
 
62 62
 
63
-	/**
64
-	 * Sets values in the data json array
65
-	 * @param array|object $data an array or object which will be transformed
66
-	 * @return DataResponse Reference to this object
67
-	 * @since 8.0.0
68
-	 */
69
-	public function setData($data){
70
-		$this->data = $data;
63
+    /**
64
+     * Sets values in the data json array
65
+     * @param array|object $data an array or object which will be transformed
66
+     * @return DataResponse Reference to this object
67
+     * @since 8.0.0
68
+     */
69
+    public function setData($data){
70
+        $this->data = $data;
71 71
 
72
-		return $this;
73
-	}
72
+        return $this;
73
+    }
74 74
 
75 75
 
76
-	/**
77
-	 * Used to get the set parameters
78
-	 * @return array the data
79
-	 * @since 8.0.0
80
-	 */
81
-	public function getData(){
82
-		return $this->data;
83
-	}
76
+    /**
77
+     * Used to get the set parameters
78
+     * @return array the data
79
+     * @since 8.0.0
80
+     */
81
+    public function getData(){
82
+        return $this->data;
83
+    }
84 84
 
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @param array $headers additional key value based headers
51 51
 	 * @since 8.0.0
52 52
 	 */
53
-	public function __construct($data=array(), $statusCode=Http::STATUS_OK,
54
-	                            array $headers=array()) {
53
+	public function __construct($data = array(), $statusCode = Http::STATUS_OK,
54
+	                            array $headers = array()) {
55 55
 		parent::__construct();
56 56
 
57 57
 		$this->data = $data;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return DataResponse Reference to this object
67 67
 	 * @since 8.0.0
68 68
 	 */
69
-	public function setData($data){
69
+	public function setData($data) {
70 70
 		$this->data = $data;
71 71
 
72 72
 		return $this;
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @return array the data
79 79
 	 * @since 8.0.0
80 80
 	 */
81
-	public function getData(){
81
+	public function getData() {
82 82
 		return $this->data;
83 83
 	}
84 84
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/JSONResponse.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -39,65 +39,65 @@
 block discarded – undo
39 39
  */
40 40
 class JSONResponse extends Response {
41 41
 
42
-	/**
43
-	 * response data
44
-	 * @var array|object
45
-	 */
46
-	protected $data;
47
-
48
-
49
-	/**
50
-	 * constructor of JSONResponse
51
-	 * @param array|object $data the object or array that should be transformed
52
-	 * @param int $statusCode the Http status code, defaults to 200
53
-	 * @since 6.0.0
54
-	 */
55
-	public function __construct($data=array(), $statusCode=Http::STATUS_OK) {
56
-		parent::__construct();
57
-
58
-		$this->data = $data;
59
-		$this->setStatus($statusCode);
60
-		$this->addHeader('Content-Type', 'application/json; charset=utf-8');
61
-	}
62
-
63
-
64
-	/**
65
-	 * Returns the rendered json
66
-	 * @return string the rendered json
67
-	 * @since 6.0.0
68
-	 * @throws \Exception If data could not get encoded
69
-	 */
70
-	public function render() {
71
-		$response = json_encode($this->data, JSON_HEX_TAG);
72
-		if($response === false) {
73
-			throw new \Exception(sprintf('Could not json_encode due to invalid ' .
74
-				'non UTF-8 characters in the array: %s', var_export($this->data, true)));
75
-		}
76
-
77
-		return $response;
78
-	}
79
-
80
-	/**
81
-	 * Sets values in the data json array
82
-	 * @param array|object $data an array or object which will be transformed
83
-	 *                             to JSON
84
-	 * @return JSONResponse Reference to this object
85
-	 * @since 6.0.0 - return value was added in 7.0.0
86
-	 */
87
-	public function setData($data){
88
-		$this->data = $data;
89
-
90
-		return $this;
91
-	}
92
-
93
-
94
-	/**
95
-	 * Used to get the set parameters
96
-	 * @return array the data
97
-	 * @since 6.0.0
98
-	 */
99
-	public function getData(){
100
-		return $this->data;
101
-	}
42
+    /**
43
+     * response data
44
+     * @var array|object
45
+     */
46
+    protected $data;
47
+
48
+
49
+    /**
50
+     * constructor of JSONResponse
51
+     * @param array|object $data the object or array that should be transformed
52
+     * @param int $statusCode the Http status code, defaults to 200
53
+     * @since 6.0.0
54
+     */
55
+    public function __construct($data=array(), $statusCode=Http::STATUS_OK) {
56
+        parent::__construct();
57
+
58
+        $this->data = $data;
59
+        $this->setStatus($statusCode);
60
+        $this->addHeader('Content-Type', 'application/json; charset=utf-8');
61
+    }
62
+
63
+
64
+    /**
65
+     * Returns the rendered json
66
+     * @return string the rendered json
67
+     * @since 6.0.0
68
+     * @throws \Exception If data could not get encoded
69
+     */
70
+    public function render() {
71
+        $response = json_encode($this->data, JSON_HEX_TAG);
72
+        if($response === false) {
73
+            throw new \Exception(sprintf('Could not json_encode due to invalid ' .
74
+                'non UTF-8 characters in the array: %s', var_export($this->data, true)));
75
+        }
76
+
77
+        return $response;
78
+    }
79
+
80
+    /**
81
+     * Sets values in the data json array
82
+     * @param array|object $data an array or object which will be transformed
83
+     *                             to JSON
84
+     * @return JSONResponse Reference to this object
85
+     * @since 6.0.0 - return value was added in 7.0.0
86
+     */
87
+    public function setData($data){
88
+        $this->data = $data;
89
+
90
+        return $this;
91
+    }
92
+
93
+
94
+    /**
95
+     * Used to get the set parameters
96
+     * @return array the data
97
+     * @since 6.0.0
98
+     */
99
+    public function getData(){
100
+        return $this->data;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param int $statusCode the Http status code, defaults to 200
53 53
 	 * @since 6.0.0
54 54
 	 */
55
-	public function __construct($data=array(), $statusCode=Http::STATUS_OK) {
55
+	public function __construct($data = array(), $statusCode = Http::STATUS_OK) {
56 56
 		parent::__construct();
57 57
 
58 58
 		$this->data = $data;
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function render() {
71 71
 		$response = json_encode($this->data, JSON_HEX_TAG);
72
-		if($response === false) {
73
-			throw new \Exception(sprintf('Could not json_encode due to invalid ' .
72
+		if ($response === false) {
73
+			throw new \Exception(sprintf('Could not json_encode due to invalid '.
74 74
 				'non UTF-8 characters in the array: %s', var_export($this->data, true)));
75 75
 		}
76 76
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return JSONResponse Reference to this object
85 85
 	 * @since 6.0.0 - return value was added in 7.0.0
86 86
 	 */
87
-	public function setData($data){
87
+	public function setData($data) {
88 88
 		$this->data = $data;
89 89
 
90 90
 		return $this;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @return array the data
97 97
 	 * @since 6.0.0
98 98
 	 */
99
-	public function getData(){
99
+	public function getData() {
100 100
 		return $this->data;
101 101
 	}
102 102
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/RedirectResponse.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -35,29 +35,29 @@
 block discarded – undo
35 35
  */
36 36
 class RedirectResponse extends Response {
37 37
 
38
-	private $redirectURL;
39
-
40
-	/**
41
-	 * Creates a response that redirects to a url
42
-	 * @param string $redirectURL the url to redirect to
43
-	 * @since 7.0.0
44
-	 */
45
-	public function __construct($redirectURL) {
46
-		parent::__construct();
47
-
48
-		$this->redirectURL = $redirectURL;
49
-		$this->setStatus(Http::STATUS_SEE_OTHER);
50
-		$this->addHeader('Location', $redirectURL);
51
-	}
52
-
53
-
54
-	/**
55
-	 * @return string the url to redirect
56
-	 * @since 7.0.0
57
-	 */
58
-	public function getRedirectURL() {
59
-		return $this->redirectURL;
60
-	}
38
+    private $redirectURL;
39
+
40
+    /**
41
+     * Creates a response that redirects to a url
42
+     * @param string $redirectURL the url to redirect to
43
+     * @since 7.0.0
44
+     */
45
+    public function __construct($redirectURL) {
46
+        parent::__construct();
47
+
48
+        $this->redirectURL = $redirectURL;
49
+        $this->setStatus(Http::STATUS_SEE_OTHER);
50
+        $this->addHeader('Location', $redirectURL);
51
+    }
52
+
53
+
54
+    /**
55
+     * @return string the url to redirect
56
+     * @since 7.0.0
57
+     */
58
+    public function getRedirectURL() {
59
+        return $this->redirectURL;
60
+    }
61 61
 
62 62
 
63 63
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/TemplateResponse.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -37,131 +37,131 @@
 block discarded – undo
37 37
  */
38 38
 class TemplateResponse extends Response {
39 39
 
40
-	const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
41
-	const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn';
42
-
43
-	/**
44
-	 * name of the template
45
-	 * @var string
46
-	 */
47
-	protected $templateName;
48
-
49
-	/**
50
-	 * parameters
51
-	 * @var array
52
-	 */
53
-	protected $params;
54
-
55
-	/**
56
-	 * rendering type (admin, user, blank)
57
-	 * @var string
58
-	 */
59
-	protected $renderAs;
60
-
61
-	/**
62
-	 * app name
63
-	 * @var string
64
-	 */
65
-	protected $appName;
66
-
67
-	/**
68
-	 * constructor of TemplateResponse
69
-	 * @param string $appName the name of the app to load the template from
70
-	 * @param string $templateName the name of the template
71
-	 * @param array $params an array of parameters which should be passed to the
72
-	 * template
73
-	 * @param string $renderAs how the page should be rendered, defaults to user
74
-	 * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
75
-	 */
76
-	public function __construct($appName, $templateName, array $params=array(),
77
-	                            $renderAs='user') {
78
-		parent::__construct();
79
-
80
-		$this->templateName = $templateName;
81
-		$this->appName = $appName;
82
-		$this->params = $params;
83
-		$this->renderAs = $renderAs;
84
-
85
-		$this->setContentSecurityPolicy(new ContentSecurityPolicy());
86
-	}
87
-
88
-
89
-	/**
90
-	 * Sets template parameters
91
-	 * @param array $params an array with key => value structure which sets template
92
-	 *                      variables
93
-	 * @return TemplateResponse Reference to this object
94
-	 * @since 6.0.0 - return value was added in 7.0.0
95
-	 */
96
-	public function setParams(array $params){
97
-		$this->params = $params;
98
-
99
-		return $this;
100
-	}
101
-
102
-
103
-	/**
104
-	 * Used for accessing the set parameters
105
-	 * @return array the params
106
-	 * @since 6.0.0
107
-	 */
108
-	public function getParams(){
109
-		return $this->params;
110
-	}
111
-
112
-
113
-	/**
114
-	 * Used for accessing the name of the set template
115
-	 * @return string the name of the used template
116
-	 * @since 6.0.0
117
-	 */
118
-	public function getTemplateName(){
119
-		return $this->templateName;
120
-	}
121
-
122
-
123
-	/**
124
-	 * Sets the template page
125
-	 * @param string $renderAs admin, user or blank. Admin also prints the admin
126
-	 *                         settings header and footer, user renders the normal
127
-	 *                         normal page including footer and header and blank
128
-	 *                         just renders the plain template
129
-	 * @return TemplateResponse Reference to this object
130
-	 * @since 6.0.0 - return value was added in 7.0.0
131
-	 */
132
-	public function renderAs($renderAs){
133
-		$this->renderAs = $renderAs;
134
-
135
-		return $this;
136
-	}
137
-
138
-
139
-	/**
140
-	 * Returns the set renderAs
141
-	 * @return string the renderAs value
142
-	 * @since 6.0.0
143
-	 */
144
-	public function getRenderAs(){
145
-		return $this->renderAs;
146
-	}
147
-
148
-
149
-	/**
150
-	 * Returns the rendered html
151
-	 * @return string the rendered html
152
-	 * @since 6.0.0
153
-	 */
154
-	public function render(){
155
-		// \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
156
-		$renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
157
-
158
-		$template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
159
-
160
-		foreach($this->params as $key => $value){
161
-			$template->assign($key, $value);
162
-		}
163
-
164
-		return $template->fetchPage($this->params);
165
-	}
40
+    const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
41
+    const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn';
42
+
43
+    /**
44
+     * name of the template
45
+     * @var string
46
+     */
47
+    protected $templateName;
48
+
49
+    /**
50
+     * parameters
51
+     * @var array
52
+     */
53
+    protected $params;
54
+
55
+    /**
56
+     * rendering type (admin, user, blank)
57
+     * @var string
58
+     */
59
+    protected $renderAs;
60
+
61
+    /**
62
+     * app name
63
+     * @var string
64
+     */
65
+    protected $appName;
66
+
67
+    /**
68
+     * constructor of TemplateResponse
69
+     * @param string $appName the name of the app to load the template from
70
+     * @param string $templateName the name of the template
71
+     * @param array $params an array of parameters which should be passed to the
72
+     * template
73
+     * @param string $renderAs how the page should be rendered, defaults to user
74
+     * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
75
+     */
76
+    public function __construct($appName, $templateName, array $params=array(),
77
+                                $renderAs='user') {
78
+        parent::__construct();
79
+
80
+        $this->templateName = $templateName;
81
+        $this->appName = $appName;
82
+        $this->params = $params;
83
+        $this->renderAs = $renderAs;
84
+
85
+        $this->setContentSecurityPolicy(new ContentSecurityPolicy());
86
+    }
87
+
88
+
89
+    /**
90
+     * Sets template parameters
91
+     * @param array $params an array with key => value structure which sets template
92
+     *                      variables
93
+     * @return TemplateResponse Reference to this object
94
+     * @since 6.0.0 - return value was added in 7.0.0
95
+     */
96
+    public function setParams(array $params){
97
+        $this->params = $params;
98
+
99
+        return $this;
100
+    }
101
+
102
+
103
+    /**
104
+     * Used for accessing the set parameters
105
+     * @return array the params
106
+     * @since 6.0.0
107
+     */
108
+    public function getParams(){
109
+        return $this->params;
110
+    }
111
+
112
+
113
+    /**
114
+     * Used for accessing the name of the set template
115
+     * @return string the name of the used template
116
+     * @since 6.0.0
117
+     */
118
+    public function getTemplateName(){
119
+        return $this->templateName;
120
+    }
121
+
122
+
123
+    /**
124
+     * Sets the template page
125
+     * @param string $renderAs admin, user or blank. Admin also prints the admin
126
+     *                         settings header and footer, user renders the normal
127
+     *                         normal page including footer and header and blank
128
+     *                         just renders the plain template
129
+     * @return TemplateResponse Reference to this object
130
+     * @since 6.0.0 - return value was added in 7.0.0
131
+     */
132
+    public function renderAs($renderAs){
133
+        $this->renderAs = $renderAs;
134
+
135
+        return $this;
136
+    }
137
+
138
+
139
+    /**
140
+     * Returns the set renderAs
141
+     * @return string the renderAs value
142
+     * @since 6.0.0
143
+     */
144
+    public function getRenderAs(){
145
+        return $this->renderAs;
146
+    }
147
+
148
+
149
+    /**
150
+     * Returns the rendered html
151
+     * @return string the rendered html
152
+     * @since 6.0.0
153
+     */
154
+    public function render(){
155
+        // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
156
+        $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
157
+
158
+        $template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
159
+
160
+        foreach($this->params as $key => $value){
161
+            $template->assign($key, $value);
162
+        }
163
+
164
+        return $template->fetchPage($this->params);
165
+    }
166 166
 
167 167
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class TemplateResponse extends Response {
39 39
 
40
-	const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
41
-	const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn';
40
+	const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class.'::loadAdditionalScripts';
41
+	const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class.'::loadAdditionalScriptsLoggedIn';
42 42
 
43 43
 	/**
44 44
 	 * name of the template
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @param string $renderAs how the page should be rendered, defaults to user
74 74
 	 * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0
75 75
 	 */
76
-	public function __construct($appName, $templateName, array $params=array(),
77
-	                            $renderAs='user') {
76
+	public function __construct($appName, $templateName, array $params = array(),
77
+	                            $renderAs = 'user') {
78 78
 		parent::__construct();
79 79
 
80 80
 		$this->templateName = $templateName;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @return TemplateResponse Reference to this object
94 94
 	 * @since 6.0.0 - return value was added in 7.0.0
95 95
 	 */
96
-	public function setParams(array $params){
96
+	public function setParams(array $params) {
97 97
 		$this->params = $params;
98 98
 
99 99
 		return $this;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @return array the params
106 106
 	 * @since 6.0.0
107 107
 	 */
108
-	public function getParams(){
108
+	public function getParams() {
109 109
 		return $this->params;
110 110
 	}
111 111
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return string the name of the used template
116 116
 	 * @since 6.0.0
117 117
 	 */
118
-	public function getTemplateName(){
118
+	public function getTemplateName() {
119 119
 		return $this->templateName;
120 120
 	}
121 121
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 * @return TemplateResponse Reference to this object
130 130
 	 * @since 6.0.0 - return value was added in 7.0.0
131 131
 	 */
132
-	public function renderAs($renderAs){
132
+	public function renderAs($renderAs) {
133 133
 		$this->renderAs = $renderAs;
134 134
 
135 135
 		return $this;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @return string the renderAs value
142 142
 	 * @since 6.0.0
143 143
 	 */
144
-	public function getRenderAs(){
144
+	public function getRenderAs() {
145 145
 		return $this->renderAs;
146 146
 	}
147 147
 
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
 	 * @return string the rendered html
152 152
 	 * @since 6.0.0
153 153
 	 */
154
-	public function render(){
154
+	public function render() {
155 155
 		// \OCP\Template needs an empty string instead of 'blank' for an unwrapped response
156 156
 		$renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs;
157 157
 
158 158
 		$template = new \OCP\Template($this->appName, $this->templateName, $renderAs);
159 159
 
160
-		foreach($this->params as $key => $value){
160
+		foreach ($this->params as $key => $value) {
161 161
 			$template->assign($key, $value);
162 162
 		}
163 163
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/StreamResponse.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -34,35 +34,35 @@
 block discarded – undo
34 34
  * @since 8.1.0
35 35
  */
36 36
 class StreamResponse extends Response implements ICallbackResponse {
37
-	/** @var string */
38
-	private $filePath;
37
+    /** @var string */
38
+    private $filePath;
39 39
 
40
-	/**
41
-	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
42
-	 * @since 8.1.0
43
-	 */
44
-	public function __construct ($filePath) {
45
-		parent::__construct();
40
+    /**
41
+     * @param string|resource $filePath the path to the file or a file handle which should be streamed
42
+     * @since 8.1.0
43
+     */
44
+    public function __construct ($filePath) {
45
+        parent::__construct();
46 46
 
47
-		$this->filePath = $filePath;
48
-	}
47
+        $this->filePath = $filePath;
48
+    }
49 49
 
50 50
 
51
-	/**
52
-	 * Streams the file using readfile
53
-	 *
54
-	 * @param IOutput $output a small wrapper that handles output
55
-	 * @since 8.1.0
56
-	 */
57
-	public function callback (IOutput $output) {
58
-		// handle caching
59
-		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
60
-			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
61
-				$output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
62
-			} elseif ($output->setReadfile($this->filePath) === false) {
63
-				$output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
64
-			}
65
-		}
66
-	}
51
+    /**
52
+     * Streams the file using readfile
53
+     *
54
+     * @param IOutput $output a small wrapper that handles output
55
+     * @since 8.1.0
56
+     */
57
+    public function callback (IOutput $output) {
58
+        // handle caching
59
+        if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
60
+            if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
61
+                $output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
62
+            } elseif ($output->setReadfile($this->filePath) === false) {
63
+                $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
64
+            }
65
+        }
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
42 42
 	 * @since 8.1.0
43 43
 	 */
44
-	public function __construct ($filePath) {
44
+	public function __construct($filePath) {
45 45
 		parent::__construct();
46 46
 
47 47
 		$this->filePath = $filePath;
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @param IOutput $output a small wrapper that handles output
55 55
 	 * @since 8.1.0
56 56
 	 */
57
-	public function callback (IOutput $output) {
57
+	public function callback(IOutput $output) {
58 58
 		// handle caching
59 59
 		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
60 60
 			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/DataDisplayResponse.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -34,59 +34,59 @@
 block discarded – undo
34 34
  */
35 35
 class DataDisplayResponse extends Response {
36 36
 
37
-	/**
38
-	 * response data
39
-	 * @var string
40
-	 */
41
-	protected $data;
37
+    /**
38
+     * response data
39
+     * @var string
40
+     */
41
+    protected $data;
42 42
 
43 43
 
44
-	/**
45
-	 * @param string $data the data to display
46
-	 * @param int $statusCode the Http status code, defaults to 200
47
-	 * @param array $headers additional key value based headers
48
-	 * @since 8.1.0
49
-	 */
50
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
51
-	                            $headers=[]) {
52
-		parent::__construct();
44
+    /**
45
+     * @param string $data the data to display
46
+     * @param int $statusCode the Http status code, defaults to 200
47
+     * @param array $headers additional key value based headers
48
+     * @since 8.1.0
49
+     */
50
+    public function __construct($data='', $statusCode=Http::STATUS_OK,
51
+                                $headers=[]) {
52
+        parent::__construct();
53 53
 
54
-		$this->data = $data;
55
-		$this->setStatus($statusCode);
56
-		$this->setHeaders(array_merge($this->getHeaders(), $headers));
57
-		$this->addHeader('Content-Disposition', 'inline; filename=""');
58
-	}
54
+        $this->data = $data;
55
+        $this->setStatus($statusCode);
56
+        $this->setHeaders(array_merge($this->getHeaders(), $headers));
57
+        $this->addHeader('Content-Disposition', 'inline; filename=""');
58
+    }
59 59
 
60
-	/**
61
-	 * Outputs data. No processing is done.
62
-	 * @return string
63
-	 * @since 8.1.0
64
-	 */
65
-	public function render() {
66
-		return $this->data;
67
-	}
60
+    /**
61
+     * Outputs data. No processing is done.
62
+     * @return string
63
+     * @since 8.1.0
64
+     */
65
+    public function render() {
66
+        return $this->data;
67
+    }
68 68
 
69 69
 
70
-	/**
71
-	 * Sets values in the data
72
-	 * @param string $data the data to display
73
-	 * @return DataDisplayResponse Reference to this object
74
-	 * @since 8.1.0
75
-	 */
76
-	public function setData($data){
77
-		$this->data = $data;
70
+    /**
71
+     * Sets values in the data
72
+     * @param string $data the data to display
73
+     * @return DataDisplayResponse Reference to this object
74
+     * @since 8.1.0
75
+     */
76
+    public function setData($data){
77
+        $this->data = $data;
78 78
 
79
-		return $this;
80
-	}
79
+        return $this;
80
+    }
81 81
 
82 82
 
83
-	/**
84
-	 * Used to get the set parameters
85
-	 * @return string the data
86
-	 * @since 8.1.0
87
-	 */
88
-	public function getData(){
89
-		return $this->data;
90
-	}
83
+    /**
84
+     * Used to get the set parameters
85
+     * @return string the data
86
+     * @since 8.1.0
87
+     */
88
+    public function getData(){
89
+        return $this->data;
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param array $headers additional key value based headers
48 48
 	 * @since 8.1.0
49 49
 	 */
50
-	public function __construct($data='', $statusCode=Http::STATUS_OK,
51
-	                            $headers=[]) {
50
+	public function __construct($data = '', $statusCode = Http::STATUS_OK,
51
+	                            $headers = []) {
52 52
 		parent::__construct();
53 53
 
54 54
 		$this->data = $data;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return DataDisplayResponse Reference to this object
74 74
 	 * @since 8.1.0
75 75
 	 */
76
-	public function setData($data){
76
+	public function setData($data) {
77 77
 		$this->data = $data;
78 78
 
79 79
 		return $this;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @return string the data
86 86
 	 * @since 8.1.0
87 87
 	 */
88
-	public function getData(){
88
+	public function getData() {
89 89
 		return $this->data;
90 90
 	}
91 91
 
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Response.php 1 patch
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -45,338 +45,338 @@
 block discarded – undo
45 45
  */
46 46
 class Response {
47 47
 
48
-	/**
49
-	 * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
50
-	 * @var array
51
-	 */
52
-	private $headers = array(
53
-		'Cache-Control' => 'no-cache, no-store, must-revalidate'
54
-	);
55
-
56
-
57
-	/**
58
-	 * Cookies that will be need to be constructed as header
59
-	 * @var array
60
-	 */
61
-	private $cookies = array();
62
-
63
-
64
-	/**
65
-	 * HTTP status code - defaults to STATUS OK
66
-	 * @var int
67
-	 */
68
-	private $status = Http::STATUS_OK;
69
-
70
-
71
-	/**
72
-	 * Last modified date
73
-	 * @var \DateTime
74
-	 */
75
-	private $lastModified;
76
-
77
-
78
-	/**
79
-	 * ETag
80
-	 * @var string
81
-	 */
82
-	private $ETag;
83
-
84
-	/** @var ContentSecurityPolicy|null Used Content-Security-Policy */
85
-	private $contentSecurityPolicy = null;
86
-
87
-	/** @var bool */
88
-	private $throttled = false;
89
-	/** @var array */
90
-	private $throttleMetadata = [];
91
-
92
-	/**
93
-	 * Response constructor.
94
-	 *
95
-	 * @since 17.0.0
96
-	 */
97
-	public function __construct() {
98
-		$this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
99
-	}
100
-
101
-	/**
102
-	 * Caches the response
103
-	 * @param int $cacheSeconds the amount of seconds that should be cached
104
-	 * if 0 then caching will be disabled
105
-	 * @return $this
106
-	 * @since 6.0.0 - return value was added in 7.0.0
107
-	 */
108
-	public function cacheFor(int $cacheSeconds) {
109
-		if($cacheSeconds > 0) {
110
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
111
-
112
-			// Old scool prama caching
113
-			$this->addHeader('Pragma', 'public');
114
-
115
-			// Set expires header
116
-			$expires = new \DateTime();
117
-			/** @var ITimeFactory $time */
118
-			$time = \OC::$server->query(ITimeFactory::class);
119
-			$expires->setTimestamp($time->getTime());
120
-			$expires->add(new \DateInterval('PT'.$cacheSeconds.'S'));
121
-			$this->addHeader('Expires', $expires->format(\DateTime::RFC2822));
122
-		} else {
123
-			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
124
-			unset($this->headers['Expires'], $this->headers['Pragma']);
125
-		}
126
-
127
-		return $this;
128
-	}
129
-
130
-	/**
131
-	 * Adds a new cookie to the response
132
-	 * @param string $name The name of the cookie
133
-	 * @param string $value The value of the cookie
134
-	 * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
135
-	 * 									to null cookie will be considered as session
136
-	 * 									cookie.
137
-	 * @return $this
138
-	 * @since 8.0.0
139
-	 */
140
-	public function addCookie($name, $value, \DateTime $expireDate = null) {
141
-		$this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
142
-		return $this;
143
-	}
144
-
145
-
146
-	/**
147
-	 * Set the specified cookies
148
-	 * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
149
-	 * @return $this
150
-	 * @since 8.0.0
151
-	 */
152
-	public function setCookies(array $cookies) {
153
-		$this->cookies = $cookies;
154
-		return $this;
155
-	}
156
-
157
-
158
-	/**
159
-	 * Invalidates the specified cookie
160
-	 * @param string $name
161
-	 * @return $this
162
-	 * @since 8.0.0
163
-	 */
164
-	public function invalidateCookie($name) {
165
-		$this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
166
-		return $this;
167
-	}
168
-
169
-	/**
170
-	 * Invalidates the specified cookies
171
-	 * @param array $cookieNames array('foo', 'bar')
172
-	 * @return $this
173
-	 * @since 8.0.0
174
-	 */
175
-	public function invalidateCookies(array $cookieNames) {
176
-		foreach($cookieNames as $cookieName) {
177
-			$this->invalidateCookie($cookieName);
178
-		}
179
-		return $this;
180
-	}
181
-
182
-	/**
183
-	 * Returns the cookies
184
-	 * @return array
185
-	 * @since 8.0.0
186
-	 */
187
-	public function getCookies() {
188
-		return $this->cookies;
189
-	}
190
-
191
-	/**
192
-	 * Adds a new header to the response that will be called before the render
193
-	 * function
194
-	 * @param string $name The name of the HTTP header
195
-	 * @param string $value The value, null will delete it
196
-	 * @return $this
197
-	 * @since 6.0.0 - return value was added in 7.0.0
198
-	 */
199
-	public function addHeader($name, $value) {
200
-		$name = trim($name);  // always remove leading and trailing whitespace
201
-		                      // to be able to reliably check for security
202
-		                      // headers
203
-
204
-		if(is_null($value)) {
205
-			unset($this->headers[$name]);
206
-		} else {
207
-			$this->headers[$name] = $value;
208
-		}
209
-
210
-		return $this;
211
-	}
212
-
213
-
214
-	/**
215
-	 * Set the headers
216
-	 * @param array $headers value header pairs
217
-	 * @return $this
218
-	 * @since 8.0.0
219
-	 */
220
-	public function setHeaders(array $headers) {
221
-		$this->headers = $headers;
222
-
223
-		return $this;
224
-	}
225
-
226
-
227
-	/**
228
-	 * Returns the set headers
229
-	 * @return array the headers
230
-	 * @since 6.0.0
231
-	 */
232
-	public function getHeaders() {
233
-		$mergeWith = [];
234
-
235
-		if($this->lastModified) {
236
-			$mergeWith['Last-Modified'] =
237
-				$this->lastModified->format(\DateTime::RFC2822);
238
-		}
239
-
240
-		// Build Content-Security-Policy and use default if none has been specified
241
-		if(is_null($this->contentSecurityPolicy)) {
242
-			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
243
-		}
244
-		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
245
-
246
-		if($this->ETag) {
247
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
248
-		}
249
-
250
-		return array_merge($mergeWith, $this->headers);
251
-	}
252
-
253
-
254
-	/**
255
-	 * By default renders no output
256
-	 * @return string
257
-	 * @since 6.0.0
258
-	 */
259
-	public function render() {
260
-		return '';
261
-	}
262
-
263
-
264
-	/**
265
-	 * Set response status
266
-	 * @param int $status a HTTP status code, see also the STATUS constants
267
-	 * @return Response Reference to this object
268
-	 * @since 6.0.0 - return value was added in 7.0.0
269
-	 */
270
-	public function setStatus($status) {
271
-		$this->status = $status;
272
-
273
-		return $this;
274
-	}
275
-
276
-	/**
277
-	 * Set a Content-Security-Policy
278
-	 * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
279
-	 * @return $this
280
-	 * @since 8.1.0
281
-	 */
282
-	public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
283
-		$this->contentSecurityPolicy = $csp;
284
-		return $this;
285
-	}
286
-
287
-	/**
288
-	 * Get the currently used Content-Security-Policy
289
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
290
-	 *                                    none specified.
291
-	 * @since 8.1.0
292
-	 */
293
-	public function getContentSecurityPolicy() {
294
-		return $this->contentSecurityPolicy;
295
-	}
296
-
297
-
298
-	/**
299
-	 * Get response status
300
-	 * @since 6.0.0
301
-	 */
302
-	public function getStatus() {
303
-		return $this->status;
304
-	}
305
-
306
-
307
-	/**
308
-	 * Get the ETag
309
-	 * @return string the etag
310
-	 * @since 6.0.0
311
-	 */
312
-	public function getETag() {
313
-		return $this->ETag;
314
-	}
315
-
316
-
317
-	/**
318
-	 * Get "last modified" date
319
-	 * @return \DateTime RFC2822 formatted last modified date
320
-	 * @since 6.0.0
321
-	 */
322
-	public function getLastModified() {
323
-		return $this->lastModified;
324
-	}
325
-
326
-
327
-	/**
328
-	 * Set the ETag
329
-	 * @param string $ETag
330
-	 * @return Response Reference to this object
331
-	 * @since 6.0.0 - return value was added in 7.0.0
332
-	 */
333
-	public function setETag($ETag) {
334
-		$this->ETag = $ETag;
335
-
336
-		return $this;
337
-	}
338
-
339
-
340
-	/**
341
-	 * Set "last modified" date
342
-	 * @param \DateTime $lastModified
343
-	 * @return Response Reference to this object
344
-	 * @since 6.0.0 - return value was added in 7.0.0
345
-	 */
346
-	public function setLastModified($lastModified) {
347
-		$this->lastModified = $lastModified;
348
-
349
-		return $this;
350
-	}
351
-
352
-	/**
353
-	 * Marks the response as to throttle. Will be throttled when the
354
-	 * @BruteForceProtection annotation is added.
355
-	 *
356
-	 * @param array $metadata
357
-	 * @since 12.0.0
358
-	 */
359
-	public function throttle(array $metadata = []) {
360
-		$this->throttled = true;
361
-		$this->throttleMetadata = $metadata;
362
-	}
363
-
364
-	/**
365
-	 * Returns the throttle metadata, defaults to empty array
366
-	 *
367
-	 * @return array
368
-	 * @since 13.0.0
369
-	 */
370
-	public function getThrottleMetadata() {
371
-		return $this->throttleMetadata;
372
-	}
373
-
374
-	/**
375
-	 * Whether the current response is throttled.
376
-	 *
377
-	 * @since 12.0.0
378
-	 */
379
-	public function isThrottled() {
380
-		return $this->throttled;
381
-	}
48
+    /**
49
+     * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
50
+     * @var array
51
+     */
52
+    private $headers = array(
53
+        'Cache-Control' => 'no-cache, no-store, must-revalidate'
54
+    );
55
+
56
+
57
+    /**
58
+     * Cookies that will be need to be constructed as header
59
+     * @var array
60
+     */
61
+    private $cookies = array();
62
+
63
+
64
+    /**
65
+     * HTTP status code - defaults to STATUS OK
66
+     * @var int
67
+     */
68
+    private $status = Http::STATUS_OK;
69
+
70
+
71
+    /**
72
+     * Last modified date
73
+     * @var \DateTime
74
+     */
75
+    private $lastModified;
76
+
77
+
78
+    /**
79
+     * ETag
80
+     * @var string
81
+     */
82
+    private $ETag;
83
+
84
+    /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
85
+    private $contentSecurityPolicy = null;
86
+
87
+    /** @var bool */
88
+    private $throttled = false;
89
+    /** @var array */
90
+    private $throttleMetadata = [];
91
+
92
+    /**
93
+     * Response constructor.
94
+     *
95
+     * @since 17.0.0
96
+     */
97
+    public function __construct() {
98
+        $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
99
+    }
100
+
101
+    /**
102
+     * Caches the response
103
+     * @param int $cacheSeconds the amount of seconds that should be cached
104
+     * if 0 then caching will be disabled
105
+     * @return $this
106
+     * @since 6.0.0 - return value was added in 7.0.0
107
+     */
108
+    public function cacheFor(int $cacheSeconds) {
109
+        if($cacheSeconds > 0) {
110
+            $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
111
+
112
+            // Old scool prama caching
113
+            $this->addHeader('Pragma', 'public');
114
+
115
+            // Set expires header
116
+            $expires = new \DateTime();
117
+            /** @var ITimeFactory $time */
118
+            $time = \OC::$server->query(ITimeFactory::class);
119
+            $expires->setTimestamp($time->getTime());
120
+            $expires->add(new \DateInterval('PT'.$cacheSeconds.'S'));
121
+            $this->addHeader('Expires', $expires->format(\DateTime::RFC2822));
122
+        } else {
123
+            $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
124
+            unset($this->headers['Expires'], $this->headers['Pragma']);
125
+        }
126
+
127
+        return $this;
128
+    }
129
+
130
+    /**
131
+     * Adds a new cookie to the response
132
+     * @param string $name The name of the cookie
133
+     * @param string $value The value of the cookie
134
+     * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
135
+     * 									to null cookie will be considered as session
136
+     * 									cookie.
137
+     * @return $this
138
+     * @since 8.0.0
139
+     */
140
+    public function addCookie($name, $value, \DateTime $expireDate = null) {
141
+        $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
142
+        return $this;
143
+    }
144
+
145
+
146
+    /**
147
+     * Set the specified cookies
148
+     * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
149
+     * @return $this
150
+     * @since 8.0.0
151
+     */
152
+    public function setCookies(array $cookies) {
153
+        $this->cookies = $cookies;
154
+        return $this;
155
+    }
156
+
157
+
158
+    /**
159
+     * Invalidates the specified cookie
160
+     * @param string $name
161
+     * @return $this
162
+     * @since 8.0.0
163
+     */
164
+    public function invalidateCookie($name) {
165
+        $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
166
+        return $this;
167
+    }
168
+
169
+    /**
170
+     * Invalidates the specified cookies
171
+     * @param array $cookieNames array('foo', 'bar')
172
+     * @return $this
173
+     * @since 8.0.0
174
+     */
175
+    public function invalidateCookies(array $cookieNames) {
176
+        foreach($cookieNames as $cookieName) {
177
+            $this->invalidateCookie($cookieName);
178
+        }
179
+        return $this;
180
+    }
181
+
182
+    /**
183
+     * Returns the cookies
184
+     * @return array
185
+     * @since 8.0.0
186
+     */
187
+    public function getCookies() {
188
+        return $this->cookies;
189
+    }
190
+
191
+    /**
192
+     * Adds a new header to the response that will be called before the render
193
+     * function
194
+     * @param string $name The name of the HTTP header
195
+     * @param string $value The value, null will delete it
196
+     * @return $this
197
+     * @since 6.0.0 - return value was added in 7.0.0
198
+     */
199
+    public function addHeader($name, $value) {
200
+        $name = trim($name);  // always remove leading and trailing whitespace
201
+                                // to be able to reliably check for security
202
+                                // headers
203
+
204
+        if(is_null($value)) {
205
+            unset($this->headers[$name]);
206
+        } else {
207
+            $this->headers[$name] = $value;
208
+        }
209
+
210
+        return $this;
211
+    }
212
+
213
+
214
+    /**
215
+     * Set the headers
216
+     * @param array $headers value header pairs
217
+     * @return $this
218
+     * @since 8.0.0
219
+     */
220
+    public function setHeaders(array $headers) {
221
+        $this->headers = $headers;
222
+
223
+        return $this;
224
+    }
225
+
226
+
227
+    /**
228
+     * Returns the set headers
229
+     * @return array the headers
230
+     * @since 6.0.0
231
+     */
232
+    public function getHeaders() {
233
+        $mergeWith = [];
234
+
235
+        if($this->lastModified) {
236
+            $mergeWith['Last-Modified'] =
237
+                $this->lastModified->format(\DateTime::RFC2822);
238
+        }
239
+
240
+        // Build Content-Security-Policy and use default if none has been specified
241
+        if(is_null($this->contentSecurityPolicy)) {
242
+            $this->setContentSecurityPolicy(new ContentSecurityPolicy());
243
+        }
244
+        $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
245
+
246
+        if($this->ETag) {
247
+            $mergeWith['ETag'] = '"' . $this->ETag . '"';
248
+        }
249
+
250
+        return array_merge($mergeWith, $this->headers);
251
+    }
252
+
253
+
254
+    /**
255
+     * By default renders no output
256
+     * @return string
257
+     * @since 6.0.0
258
+     */
259
+    public function render() {
260
+        return '';
261
+    }
262
+
263
+
264
+    /**
265
+     * Set response status
266
+     * @param int $status a HTTP status code, see also the STATUS constants
267
+     * @return Response Reference to this object
268
+     * @since 6.0.0 - return value was added in 7.0.0
269
+     */
270
+    public function setStatus($status) {
271
+        $this->status = $status;
272
+
273
+        return $this;
274
+    }
275
+
276
+    /**
277
+     * Set a Content-Security-Policy
278
+     * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
279
+     * @return $this
280
+     * @since 8.1.0
281
+     */
282
+    public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
283
+        $this->contentSecurityPolicy = $csp;
284
+        return $this;
285
+    }
286
+
287
+    /**
288
+     * Get the currently used Content-Security-Policy
289
+     * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
290
+     *                                    none specified.
291
+     * @since 8.1.0
292
+     */
293
+    public function getContentSecurityPolicy() {
294
+        return $this->contentSecurityPolicy;
295
+    }
296
+
297
+
298
+    /**
299
+     * Get response status
300
+     * @since 6.0.0
301
+     */
302
+    public function getStatus() {
303
+        return $this->status;
304
+    }
305
+
306
+
307
+    /**
308
+     * Get the ETag
309
+     * @return string the etag
310
+     * @since 6.0.0
311
+     */
312
+    public function getETag() {
313
+        return $this->ETag;
314
+    }
315
+
316
+
317
+    /**
318
+     * Get "last modified" date
319
+     * @return \DateTime RFC2822 formatted last modified date
320
+     * @since 6.0.0
321
+     */
322
+    public function getLastModified() {
323
+        return $this->lastModified;
324
+    }
325
+
326
+
327
+    /**
328
+     * Set the ETag
329
+     * @param string $ETag
330
+     * @return Response Reference to this object
331
+     * @since 6.0.0 - return value was added in 7.0.0
332
+     */
333
+    public function setETag($ETag) {
334
+        $this->ETag = $ETag;
335
+
336
+        return $this;
337
+    }
338
+
339
+
340
+    /**
341
+     * Set "last modified" date
342
+     * @param \DateTime $lastModified
343
+     * @return Response Reference to this object
344
+     * @since 6.0.0 - return value was added in 7.0.0
345
+     */
346
+    public function setLastModified($lastModified) {
347
+        $this->lastModified = $lastModified;
348
+
349
+        return $this;
350
+    }
351
+
352
+    /**
353
+     * Marks the response as to throttle. Will be throttled when the
354
+     * @BruteForceProtection annotation is added.
355
+     *
356
+     * @param array $metadata
357
+     * @since 12.0.0
358
+     */
359
+    public function throttle(array $metadata = []) {
360
+        $this->throttled = true;
361
+        $this->throttleMetadata = $metadata;
362
+    }
363
+
364
+    /**
365
+     * Returns the throttle metadata, defaults to empty array
366
+     *
367
+     * @return array
368
+     * @since 13.0.0
369
+     */
370
+    public function getThrottleMetadata() {
371
+        return $this->throttleMetadata;
372
+    }
373
+
374
+    /**
375
+     * Whether the current response is throttled.
376
+     *
377
+     * @since 12.0.0
378
+     */
379
+    public function isThrottled() {
380
+        return $this->throttled;
381
+    }
382 382
 }
Please login to merge, or discard this patch.