@@ -31,11 +31,11 @@ |
||
31 | 31 | * @since 5.0.0 |
32 | 32 | */ |
33 | 33 | interface Share_Backend_Collection extends Share_Backend { |
34 | - /** |
|
35 | - * Get the sources of the children of the item |
|
36 | - * @param string $itemSource |
|
37 | - * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable |
|
38 | - * @since 5.0.0 |
|
39 | - */ |
|
40 | - public function getChildren($itemSource); |
|
34 | + /** |
|
35 | + * Get the sources of the children of the item |
|
36 | + * @param string $itemSource |
|
37 | + * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable |
|
38 | + * @since 5.0.0 |
|
39 | + */ |
|
40 | + public function getChildren($itemSource); |
|
41 | 41 | } |
@@ -31,10 +31,10 @@ |
||
31 | 31 | */ |
32 | 32 | interface ITimeFactory { |
33 | 33 | |
34 | - /** |
|
35 | - * @return int the result of a call to time() |
|
36 | - * @since 8.0.0 |
|
37 | - */ |
|
38 | - public function getTime(); |
|
34 | + /** |
|
35 | + * @return int the result of a call to time() |
|
36 | + * @since 8.0.0 |
|
37 | + */ |
|
38 | + public function getTime(); |
|
39 | 39 | |
40 | 40 | } |
@@ -34,38 +34,38 @@ |
||
34 | 34 | */ |
35 | 35 | interface IControllerMethodReflector { |
36 | 36 | |
37 | - /** |
|
38 | - * @param object $object an object or classname |
|
39 | - * @param string $method the method which we want to inspect |
|
40 | - * @return void |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public function reflect($object, $method); |
|
37 | + /** |
|
38 | + * @param object $object an object or classname |
|
39 | + * @param string $method the method which we want to inspect |
|
40 | + * @return void |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public function reflect($object, $method); |
|
44 | 44 | |
45 | - /** |
|
46 | - * Inspects the PHPDoc parameters for types |
|
47 | - * |
|
48 | - * @param string $parameter the parameter whose type comments should be |
|
49 | - * parsed |
|
50 | - * @return string|null type in the type parameters (@param int $something) |
|
51 | - * would return int or null if not existing |
|
52 | - * @since 8.0.0 |
|
53 | - */ |
|
54 | - public function getType($parameter); |
|
45 | + /** |
|
46 | + * Inspects the PHPDoc parameters for types |
|
47 | + * |
|
48 | + * @param string $parameter the parameter whose type comments should be |
|
49 | + * parsed |
|
50 | + * @return string|null type in the type parameters (@param int $something) |
|
51 | + * would return int or null if not existing |
|
52 | + * @since 8.0.0 |
|
53 | + */ |
|
54 | + public function getType($parameter); |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return array the arguments of the method with key => default value |
|
58 | - * @since 8.0.0 |
|
59 | - */ |
|
60 | - public function getParameters(); |
|
56 | + /** |
|
57 | + * @return array the arguments of the method with key => default value |
|
58 | + * @since 8.0.0 |
|
59 | + */ |
|
60 | + public function getParameters(); |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if a method contains an annotation |
|
64 | - * |
|
65 | - * @param string $name the name of the annotation |
|
66 | - * @return bool true if the annotation is found |
|
67 | - * @since 8.0.0 |
|
68 | - */ |
|
69 | - public function hasAnnotation($name); |
|
62 | + /** |
|
63 | + * Check if a method contains an annotation |
|
64 | + * |
|
65 | + * @param string $name the name of the annotation |
|
66 | + * @return bool true if the annotation is found |
|
67 | + * @since 8.0.0 |
|
68 | + */ |
|
69 | + public function hasAnnotation($name); |
|
70 | 70 | |
71 | 71 | } |
@@ -42,73 +42,73 @@ |
||
42 | 42 | */ |
43 | 43 | abstract class OCSController extends ApiController { |
44 | 44 | |
45 | - /** @var int */ |
|
46 | - private $ocsVersion; |
|
45 | + /** @var int */ |
|
46 | + private $ocsVersion; |
|
47 | 47 | |
48 | - /** |
|
49 | - * constructor of the controller |
|
50 | - * @param string $appName the name of the app |
|
51 | - * @param IRequest $request an instance of the request |
|
52 | - * @param string $corsMethods comma separated string of HTTP verbs which |
|
53 | - * should be allowed for websites or webapps when calling your API, defaults to |
|
54 | - * 'PUT, POST, GET, DELETE, PATCH' |
|
55 | - * @param string $corsAllowedHeaders comma separated string of HTTP headers |
|
56 | - * which should be allowed for websites or webapps when calling your API, |
|
57 | - * defaults to 'Authorization, Content-Type, Accept' |
|
58 | - * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS |
|
59 | - * request should be cached, defaults to 1728000 seconds |
|
60 | - * @since 8.1.0 |
|
61 | - */ |
|
62 | - public function __construct($appName, |
|
63 | - IRequest $request, |
|
64 | - $corsMethods='PUT, POST, GET, DELETE, PATCH', |
|
65 | - $corsAllowedHeaders='Authorization, Content-Type, Accept', |
|
66 | - $corsMaxAge=1728000){ |
|
67 | - parent::__construct($appName, $request, $corsMethods, |
|
68 | - $corsAllowedHeaders, $corsMaxAge); |
|
69 | - $this->registerResponder('json', function ($data) { |
|
70 | - return $this->buildOCSResponse('json', $data); |
|
71 | - }); |
|
72 | - $this->registerResponder('xml', function ($data) { |
|
73 | - return $this->buildOCSResponse('xml', $data); |
|
74 | - }); |
|
75 | - } |
|
48 | + /** |
|
49 | + * constructor of the controller |
|
50 | + * @param string $appName the name of the app |
|
51 | + * @param IRequest $request an instance of the request |
|
52 | + * @param string $corsMethods comma separated string of HTTP verbs which |
|
53 | + * should be allowed for websites or webapps when calling your API, defaults to |
|
54 | + * 'PUT, POST, GET, DELETE, PATCH' |
|
55 | + * @param string $corsAllowedHeaders comma separated string of HTTP headers |
|
56 | + * which should be allowed for websites or webapps when calling your API, |
|
57 | + * defaults to 'Authorization, Content-Type, Accept' |
|
58 | + * @param int $corsMaxAge number in seconds how long a preflighted OPTIONS |
|
59 | + * request should be cached, defaults to 1728000 seconds |
|
60 | + * @since 8.1.0 |
|
61 | + */ |
|
62 | + public function __construct($appName, |
|
63 | + IRequest $request, |
|
64 | + $corsMethods='PUT, POST, GET, DELETE, PATCH', |
|
65 | + $corsAllowedHeaders='Authorization, Content-Type, Accept', |
|
66 | + $corsMaxAge=1728000){ |
|
67 | + parent::__construct($appName, $request, $corsMethods, |
|
68 | + $corsAllowedHeaders, $corsMaxAge); |
|
69 | + $this->registerResponder('json', function ($data) { |
|
70 | + return $this->buildOCSResponse('json', $data); |
|
71 | + }); |
|
72 | + $this->registerResponder('xml', function ($data) { |
|
73 | + return $this->buildOCSResponse('xml', $data); |
|
74 | + }); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param int $version |
|
79 | - * @since 11.0.0 |
|
80 | - * @internal |
|
81 | - */ |
|
82 | - public function setOCSVersion($version) { |
|
83 | - $this->ocsVersion = $version; |
|
84 | - } |
|
77 | + /** |
|
78 | + * @param int $version |
|
79 | + * @since 11.0.0 |
|
80 | + * @internal |
|
81 | + */ |
|
82 | + public function setOCSVersion($version) { |
|
83 | + $this->ocsVersion = $version; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Since the OCS endpoints default to XML we need to find out the format |
|
88 | - * again |
|
89 | - * @param mixed $response the value that was returned from a controller and |
|
90 | - * is not a Response instance |
|
91 | - * @param string $format the format for which a formatter has been registered |
|
92 | - * @throws \DomainException if format does not match a registered formatter |
|
93 | - * @return Response |
|
94 | - * @since 9.1.0 |
|
95 | - */ |
|
96 | - public function buildResponse($response, $format = 'xml') { |
|
97 | - return parent::buildResponse($response, $format); |
|
98 | - } |
|
86 | + /** |
|
87 | + * Since the OCS endpoints default to XML we need to find out the format |
|
88 | + * again |
|
89 | + * @param mixed $response the value that was returned from a controller and |
|
90 | + * is not a Response instance |
|
91 | + * @param string $format the format for which a formatter has been registered |
|
92 | + * @throws \DomainException if format does not match a registered formatter |
|
93 | + * @return Response |
|
94 | + * @since 9.1.0 |
|
95 | + */ |
|
96 | + public function buildResponse($response, $format = 'xml') { |
|
97 | + return parent::buildResponse($response, $format); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * Unwrap data and build ocs response |
|
102 | - * @param string $format json or xml |
|
103 | - * @param DataResponse $data the data which should be transformed |
|
104 | - * @since 8.1.0 |
|
105 | - * @return \OC\AppFramework\OCS\BaseResponse |
|
106 | - */ |
|
107 | - private function buildOCSResponse($format, DataResponse $data) { |
|
108 | - if ($this->ocsVersion === 1) { |
|
109 | - return new \OC\AppFramework\OCS\V1Response($data, $format); |
|
110 | - } |
|
111 | - return new \OC\AppFramework\OCS\V2Response($data, $format); |
|
112 | - } |
|
100 | + /** |
|
101 | + * Unwrap data and build ocs response |
|
102 | + * @param string $format json or xml |
|
103 | + * @param DataResponse $data the data which should be transformed |
|
104 | + * @since 8.1.0 |
|
105 | + * @return \OC\AppFramework\OCS\BaseResponse |
|
106 | + */ |
|
107 | + private function buildOCSResponse($format, DataResponse $data) { |
|
108 | + if ($this->ocsVersion === 1) { |
|
109 | + return new \OC\AppFramework\OCS\V1Response($data, $format); |
|
110 | + } |
|
111 | + return new \OC\AppFramework\OCS\V2Response($data, $format); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | } |
@@ -61,15 +61,15 @@ |
||
61 | 61 | */ |
62 | 62 | public function __construct($appName, |
63 | 63 | IRequest $request, |
64 | - $corsMethods='PUT, POST, GET, DELETE, PATCH', |
|
65 | - $corsAllowedHeaders='Authorization, Content-Type, Accept', |
|
66 | - $corsMaxAge=1728000){ |
|
64 | + $corsMethods = 'PUT, POST, GET, DELETE, PATCH', |
|
65 | + $corsAllowedHeaders = 'Authorization, Content-Type, Accept', |
|
66 | + $corsMaxAge = 1728000) { |
|
67 | 67 | parent::__construct($appName, $request, $corsMethods, |
68 | 68 | $corsAllowedHeaders, $corsMaxAge); |
69 | - $this->registerResponder('json', function ($data) { |
|
69 | + $this->registerResponder('json', function($data) { |
|
70 | 70 | return $this->buildOCSResponse('json', $data); |
71 | 71 | }); |
72 | - $this->registerResponder('xml', function ($data) { |
|
72 | + $this->registerResponder('xml', function($data) { |
|
73 | 73 | return $this->buildOCSResponse('xml', $data); |
74 | 74 | }); |
75 | 75 | } |
@@ -55,8 +55,8 @@ |
||
55 | 55 | * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController |
56 | 56 | */ |
57 | 57 | public function __construct($format, $statuscode, $message, |
58 | - $data=[], $itemscount='', |
|
59 | - $itemsperpage='') { |
|
58 | + $data = [], $itemscount = '', |
|
59 | + $itemsperpage = '') { |
|
60 | 60 | $this->format = $format; |
61 | 61 | $this->statuscode = $statuscode; |
62 | 62 | $this->message = $message; |
@@ -36,59 +36,59 @@ |
||
36 | 36 | */ |
37 | 37 | class OCSResponse extends Response { |
38 | 38 | |
39 | - private $data; |
|
40 | - private $format; |
|
41 | - private $statuscode; |
|
42 | - private $message; |
|
43 | - private $itemscount; |
|
44 | - private $itemsperpage; |
|
39 | + private $data; |
|
40 | + private $format; |
|
41 | + private $statuscode; |
|
42 | + private $message; |
|
43 | + private $itemscount; |
|
44 | + private $itemsperpage; |
|
45 | 45 | |
46 | - /** |
|
47 | - * generates the xml or json response for the API call from an multidimenional data array. |
|
48 | - * @param string $format |
|
49 | - * @param int $statuscode |
|
50 | - * @param string $message |
|
51 | - * @param array $data |
|
52 | - * @param int|string $itemscount |
|
53 | - * @param int|string $itemsperpage |
|
54 | - * @since 8.1.0 |
|
55 | - * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController |
|
56 | - */ |
|
57 | - public function __construct($format, $statuscode, $message, |
|
58 | - $data=[], $itemscount='', |
|
59 | - $itemsperpage='') { |
|
60 | - $this->format = $format; |
|
61 | - $this->statuscode = $statuscode; |
|
62 | - $this->message = $message; |
|
63 | - $this->data = $data; |
|
64 | - $this->itemscount = $itemscount; |
|
65 | - $this->itemsperpage = $itemsperpage; |
|
46 | + /** |
|
47 | + * generates the xml or json response for the API call from an multidimenional data array. |
|
48 | + * @param string $format |
|
49 | + * @param int $statuscode |
|
50 | + * @param string $message |
|
51 | + * @param array $data |
|
52 | + * @param int|string $itemscount |
|
53 | + * @param int|string $itemsperpage |
|
54 | + * @since 8.1.0 |
|
55 | + * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController |
|
56 | + */ |
|
57 | + public function __construct($format, $statuscode, $message, |
|
58 | + $data=[], $itemscount='', |
|
59 | + $itemsperpage='') { |
|
60 | + $this->format = $format; |
|
61 | + $this->statuscode = $statuscode; |
|
62 | + $this->message = $message; |
|
63 | + $this->data = $data; |
|
64 | + $this->itemscount = $itemscount; |
|
65 | + $this->itemsperpage = $itemsperpage; |
|
66 | 66 | |
67 | - // set the correct header based on the format parameter |
|
68 | - if ($format === 'json') { |
|
69 | - $this->addHeader( |
|
70 | - 'Content-Type', 'application/json; charset=utf-8' |
|
71 | - ); |
|
72 | - } else { |
|
73 | - $this->addHeader( |
|
74 | - 'Content-Type', 'application/xml; charset=utf-8' |
|
75 | - ); |
|
76 | - } |
|
77 | - } |
|
67 | + // set the correct header based on the format parameter |
|
68 | + if ($format === 'json') { |
|
69 | + $this->addHeader( |
|
70 | + 'Content-Type', 'application/json; charset=utf-8' |
|
71 | + ); |
|
72 | + } else { |
|
73 | + $this->addHeader( |
|
74 | + 'Content-Type', 'application/xml; charset=utf-8' |
|
75 | + ); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return string |
|
81 | - * @since 8.1.0 |
|
82 | - * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController |
|
83 | - * @suppress PhanDeprecatedClass |
|
84 | - */ |
|
85 | - public function render() { |
|
86 | - $r = new \OC\OCS\Result($this->data, $this->statuscode, $this->message); |
|
87 | - $r->setTotalItems($this->itemscount); |
|
88 | - $r->setItemsPerPage($this->itemsperpage); |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + * @since 8.1.0 |
|
82 | + * @deprecated 9.2.0 To implement an OCS endpoint extend the OCSController |
|
83 | + * @suppress PhanDeprecatedClass |
|
84 | + */ |
|
85 | + public function render() { |
|
86 | + $r = new \OC\OCS\Result($this->data, $this->statuscode, $this->message); |
|
87 | + $r->setTotalItems($this->itemscount); |
|
88 | + $r->setItemsPerPage($this->itemsperpage); |
|
89 | 89 | |
90 | - return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData()); |
|
91 | - } |
|
90 | + return \OC_API::renderResult($this->format, $r->getMeta(), $r->getData()); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | 94 | } |
@@ -36,27 +36,27 @@ |
||
36 | 36 | */ |
37 | 37 | class RedirectResponse extends Response { |
38 | 38 | |
39 | - private $redirectURL; |
|
40 | - |
|
41 | - /** |
|
42 | - * Creates a response that redirects to a url |
|
43 | - * @param string $redirectURL the url to redirect to |
|
44 | - * @since 7.0.0 |
|
45 | - */ |
|
46 | - public function __construct($redirectURL) { |
|
47 | - $this->redirectURL = $redirectURL; |
|
48 | - $this->setStatus(Http::STATUS_SEE_OTHER); |
|
49 | - $this->addHeader('Location', $redirectURL); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @return string the url to redirect |
|
55 | - * @since 7.0.0 |
|
56 | - */ |
|
57 | - public function getRedirectURL() { |
|
58 | - return $this->redirectURL; |
|
59 | - } |
|
39 | + private $redirectURL; |
|
40 | + |
|
41 | + /** |
|
42 | + * Creates a response that redirects to a url |
|
43 | + * @param string $redirectURL the url to redirect to |
|
44 | + * @since 7.0.0 |
|
45 | + */ |
|
46 | + public function __construct($redirectURL) { |
|
47 | + $this->redirectURL = $redirectURL; |
|
48 | + $this->setStatus(Http::STATUS_SEE_OTHER); |
|
49 | + $this->addHeader('Location', $redirectURL); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @return string the url to redirect |
|
55 | + * @since 7.0.0 |
|
56 | + */ |
|
57 | + public function getRedirectURL() { |
|
58 | + return $this->redirectURL; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | 62 | } |
@@ -39,63 +39,63 @@ |
||
39 | 39 | */ |
40 | 40 | class JSONResponse extends Response { |
41 | 41 | |
42 | - /** |
|
43 | - * response data |
|
44 | - * @var array|object |
|
45 | - */ |
|
46 | - protected $data; |
|
42 | + /** |
|
43 | + * response data |
|
44 | + * @var array|object |
|
45 | + */ |
|
46 | + protected $data; |
|
47 | 47 | |
48 | 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 | - $this->data = $data; |
|
57 | - $this->setStatus($statusCode); |
|
58 | - $this->addHeader('Content-Type', 'application/json; charset=utf-8'); |
|
59 | - } |
|
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 | + $this->data = $data; |
|
57 | + $this->setStatus($statusCode); |
|
58 | + $this->addHeader('Content-Type', 'application/json; charset=utf-8'); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Returns the rendered json |
|
64 | - * @return string the rendered json |
|
65 | - * @since 6.0.0 |
|
66 | - * @throws \Exception If data could not get encoded |
|
67 | - */ |
|
68 | - public function render() { |
|
69 | - $response = json_encode($this->data, JSON_HEX_TAG); |
|
70 | - if($response === false) { |
|
71 | - throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
72 | - 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
|
73 | - } |
|
62 | + /** |
|
63 | + * Returns the rendered json |
|
64 | + * @return string the rendered json |
|
65 | + * @since 6.0.0 |
|
66 | + * @throws \Exception If data could not get encoded |
|
67 | + */ |
|
68 | + public function render() { |
|
69 | + $response = json_encode($this->data, JSON_HEX_TAG); |
|
70 | + if($response === false) { |
|
71 | + throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
72 | + 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
|
73 | + } |
|
74 | 74 | |
75 | - return $response; |
|
76 | - } |
|
75 | + return $response; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Sets values in the data json array |
|
80 | - * @param array|object $data an array or object which will be transformed |
|
81 | - * to JSON |
|
82 | - * @return JSONResponse Reference to this object |
|
83 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
84 | - */ |
|
85 | - public function setData($data){ |
|
86 | - $this->data = $data; |
|
78 | + /** |
|
79 | + * Sets values in the data json array |
|
80 | + * @param array|object $data an array or object which will be transformed |
|
81 | + * to JSON |
|
82 | + * @return JSONResponse Reference to this object |
|
83 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
84 | + */ |
|
85 | + public function setData($data){ |
|
86 | + $this->data = $data; |
|
87 | 87 | |
88 | - return $this; |
|
89 | - } |
|
88 | + return $this; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Used to get the set parameters |
|
94 | - * @return array the data |
|
95 | - * @since 6.0.0 |
|
96 | - */ |
|
97 | - public function getData(){ |
|
98 | - return $this->data; |
|
99 | - } |
|
92 | + /** |
|
93 | + * Used to get the set parameters |
|
94 | + * @return array the data |
|
95 | + * @since 6.0.0 |
|
96 | + */ |
|
97 | + public function getData(){ |
|
98 | + return $this->data; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -52,7 +52,7 @@ discard block |
||
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 | $this->data = $data; |
57 | 57 | $this->setStatus($statusCode); |
58 | 58 | $this->addHeader('Content-Type', 'application/json; charset=utf-8'); |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function render() { |
69 | 69 | $response = json_encode($this->data, JSON_HEX_TAG); |
70 | - if($response === false) { |
|
71 | - throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
70 | + if ($response === false) { |
|
71 | + throw new \Exception(sprintf('Could not json_encode due to invalid '. |
|
72 | 72 | 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
73 | 73 | } |
74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @return JSONResponse Reference to this object |
83 | 83 | * @since 6.0.0 - return value was added in 7.0.0 |
84 | 84 | */ |
85 | - public function setData($data){ |
|
85 | + public function setData($data) { |
|
86 | 86 | $this->data = $data; |
87 | 87 | |
88 | 88 | return $this; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return array the data |
95 | 95 | * @since 6.0.0 |
96 | 96 | */ |
97 | - public function getData(){ |
|
97 | + public function getData() { |
|
98 | 98 | return $this->data; |
99 | 99 | } |
100 | 100 |
@@ -37,48 +37,48 @@ |
||
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 | - $this->data = $data; |
|
56 | - $this->setStatus($statusCode); |
|
57 | - $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
58 | - } |
|
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 | + $this->data = $data; |
|
56 | + $this->setStatus($statusCode); |
|
57 | + $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Sets values in the data json array |
|
63 | - * @param array|object $data an array or object which will be transformed |
|
64 | - * @return DataResponse Reference to this object |
|
65 | - * @since 8.0.0 |
|
66 | - */ |
|
67 | - public function setData($data){ |
|
68 | - $this->data = $data; |
|
61 | + /** |
|
62 | + * Sets values in the data json array |
|
63 | + * @param array|object $data an array or object which will be transformed |
|
64 | + * @return DataResponse Reference to this object |
|
65 | + * @since 8.0.0 |
|
66 | + */ |
|
67 | + public function setData($data){ |
|
68 | + $this->data = $data; |
|
69 | 69 | |
70 | - return $this; |
|
71 | - } |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Used to get the set parameters |
|
76 | - * @return array the data |
|
77 | - * @since 8.0.0 |
|
78 | - */ |
|
79 | - public function getData(){ |
|
80 | - return $this->data; |
|
81 | - } |
|
74 | + /** |
|
75 | + * Used to get the set parameters |
|
76 | + * @return array the data |
|
77 | + * @since 8.0.0 |
|
78 | + */ |
|
79 | + public function getData(){ |
|
80 | + return $this->data; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | 84 | } |
@@ -50,8 +50,8 @@ discard block |
||
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 | $this->data = $data; |
56 | 56 | $this->setStatus($statusCode); |
57 | 57 | $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return DataResponse Reference to this object |
65 | 65 | * @since 8.0.0 |
66 | 66 | */ |
67 | - public function setData($data){ |
|
67 | + public function setData($data) { |
|
68 | 68 | $this->data = $data; |
69 | 69 | |
70 | 70 | return $this; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return array the data |
77 | 77 | * @since 8.0.0 |
78 | 78 | */ |
79 | - public function getData(){ |
|
79 | + public function getData() { |
|
80 | 80 | return $this->data; |
81 | 81 | } |
82 | 82 |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function cacheFor($cacheSeconds) { |
93 | 93 | |
94 | - if($cacheSeconds > 0) { |
|
95 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
94 | + if ($cacheSeconds > 0) { |
|
95 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
96 | 96 | } else { |
97 | 97 | $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
98 | 98 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @since 8.0.0 |
147 | 147 | */ |
148 | 148 | public function invalidateCookies(array $cookieNames) { |
149 | - foreach($cookieNames as $cookieName) { |
|
149 | + foreach ($cookieNames as $cookieName) { |
|
150 | 150 | $this->invalidateCookie($cookieName); |
151 | 151 | } |
152 | 152 | return $this; |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @since 6.0.0 - return value was added in 7.0.0 |
171 | 171 | */ |
172 | 172 | public function addHeader($name, $value) { |
173 | - $name = trim($name); // always remove leading and trailing whitespace |
|
173 | + $name = trim($name); // always remove leading and trailing whitespace |
|
174 | 174 | // to be able to reliably check for security |
175 | 175 | // headers |
176 | 176 | |
177 | - if(is_null($value)) { |
|
177 | + if (is_null($value)) { |
|
178 | 178 | unset($this->headers[$name]); |
179 | 179 | } else { |
180 | 180 | $this->headers[$name] = $value; |
@@ -205,19 +205,19 @@ discard block |
||
205 | 205 | public function getHeaders() { |
206 | 206 | $mergeWith = []; |
207 | 207 | |
208 | - if($this->lastModified) { |
|
208 | + if ($this->lastModified) { |
|
209 | 209 | $mergeWith['Last-Modified'] = |
210 | 210 | $this->lastModified->format(\DateTime::RFC2822); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Build Content-Security-Policy and use default if none has been specified |
214 | - if(is_null($this->contentSecurityPolicy)) { |
|
214 | + if (is_null($this->contentSecurityPolicy)) { |
|
215 | 215 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
216 | 216 | } |
217 | 217 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
218 | 218 | |
219 | - if($this->ETag) { |
|
220 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
219 | + if ($this->ETag) { |
|
220 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return array_merge($mergeWith, $this->headers); |
@@ -261,7 +261,7 @@ |
||
261 | 261 | |
262 | 262 | /** |
263 | 263 | * Get the currently used Content-Security-Policy |
264 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
264 | + * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | 265 | * none specified. |
266 | 266 | * @since 8.1.0 |
267 | 267 | */ |
@@ -42,318 +42,318 @@ |
||
42 | 42 | */ |
43 | 43 | class Response { |
44 | 44 | |
45 | - /** |
|
46 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - private $headers = array( |
|
50 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | - ); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Cookies that will be need to be constructed as header |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - private $cookies = array(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * HTTP status code - defaults to STATUS OK |
|
63 | - * @var int |
|
64 | - */ |
|
65 | - private $status = Http::STATUS_OK; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Last modified date |
|
70 | - * @var \DateTime |
|
71 | - */ |
|
72 | - private $lastModified; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * ETag |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - private $ETag; |
|
80 | - |
|
81 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | - private $contentSecurityPolicy = null; |
|
83 | - |
|
84 | - /** @var bool */ |
|
85 | - private $throttled = false; |
|
86 | - /** @var array */ |
|
87 | - private $throttleMetadata = []; |
|
88 | - |
|
89 | - /** |
|
90 | - * Caches the response |
|
91 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
92 | - * if 0 then caching will be disabled |
|
93 | - * @return $this |
|
94 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
95 | - */ |
|
96 | - public function cacheFor($cacheSeconds) { |
|
97 | - |
|
98 | - if($cacheSeconds > 0) { |
|
99 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
100 | - } else { |
|
101 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
102 | - } |
|
103 | - |
|
104 | - return $this; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Adds a new cookie to the response |
|
109 | - * @param string $name The name of the cookie |
|
110 | - * @param string $value The value of the cookie |
|
111 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
112 | - * to null cookie will be considered as session |
|
113 | - * cookie. |
|
114 | - * @return $this |
|
115 | - * @since 8.0.0 |
|
116 | - */ |
|
117 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
118 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Set the specified cookies |
|
125 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
126 | - * @return $this |
|
127 | - * @since 8.0.0 |
|
128 | - */ |
|
129 | - public function setCookies(array $cookies) { |
|
130 | - $this->cookies = $cookies; |
|
131 | - return $this; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Invalidates the specified cookie |
|
137 | - * @param string $name |
|
138 | - * @return $this |
|
139 | - * @since 8.0.0 |
|
140 | - */ |
|
141 | - public function invalidateCookie($name) { |
|
142 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
143 | - return $this; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Invalidates the specified cookies |
|
148 | - * @param array $cookieNames array('foo', 'bar') |
|
149 | - * @return $this |
|
150 | - * @since 8.0.0 |
|
151 | - */ |
|
152 | - public function invalidateCookies(array $cookieNames) { |
|
153 | - foreach($cookieNames as $cookieName) { |
|
154 | - $this->invalidateCookie($cookieName); |
|
155 | - } |
|
156 | - return $this; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns the cookies |
|
161 | - * @return array |
|
162 | - * @since 8.0.0 |
|
163 | - */ |
|
164 | - public function getCookies() { |
|
165 | - return $this->cookies; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Adds a new header to the response that will be called before the render |
|
170 | - * function |
|
171 | - * @param string $name The name of the HTTP header |
|
172 | - * @param string $value The value, null will delete it |
|
173 | - * @return $this |
|
174 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
175 | - */ |
|
176 | - public function addHeader($name, $value) { |
|
177 | - $name = trim($name); // always remove leading and trailing whitespace |
|
178 | - // to be able to reliably check for security |
|
179 | - // headers |
|
180 | - |
|
181 | - if(is_null($value)) { |
|
182 | - unset($this->headers[$name]); |
|
183 | - } else { |
|
184 | - $this->headers[$name] = $value; |
|
185 | - } |
|
186 | - |
|
187 | - return $this; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Set the headers |
|
193 | - * @param array $headers value header pairs |
|
194 | - * @return $this |
|
195 | - * @since 8.0.0 |
|
196 | - */ |
|
197 | - public function setHeaders(array $headers) { |
|
198 | - $this->headers = $headers; |
|
199 | - |
|
200 | - return $this; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the set headers |
|
206 | - * @return array the headers |
|
207 | - * @since 6.0.0 |
|
208 | - */ |
|
209 | - public function getHeaders() { |
|
210 | - $mergeWith = []; |
|
211 | - |
|
212 | - if($this->lastModified) { |
|
213 | - $mergeWith['Last-Modified'] = |
|
214 | - $this->lastModified->format(\DateTime::RFC2822); |
|
215 | - } |
|
216 | - |
|
217 | - // Build Content-Security-Policy and use default if none has been specified |
|
218 | - if(is_null($this->contentSecurityPolicy)) { |
|
219 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
220 | - } |
|
221 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
222 | - |
|
223 | - if($this->ETag) { |
|
224 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
225 | - } |
|
226 | - |
|
227 | - return array_merge($mergeWith, $this->headers); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * By default renders no output |
|
233 | - * @return string|null |
|
234 | - * @since 6.0.0 |
|
235 | - */ |
|
236 | - public function render() { |
|
237 | - return null; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Set response status |
|
243 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
244 | - * @return Response Reference to this object |
|
245 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
246 | - */ |
|
247 | - public function setStatus($status) { |
|
248 | - $this->status = $status; |
|
249 | - |
|
250 | - return $this; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Set a Content-Security-Policy |
|
255 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
256 | - * @return $this |
|
257 | - * @since 8.1.0 |
|
258 | - */ |
|
259 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
260 | - $this->contentSecurityPolicy = $csp; |
|
261 | - return $this; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Get the currently used Content-Security-Policy |
|
266 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
267 | - * none specified. |
|
268 | - * @since 8.1.0 |
|
269 | - */ |
|
270 | - public function getContentSecurityPolicy() { |
|
271 | - return $this->contentSecurityPolicy; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Get response status |
|
277 | - * @since 6.0.0 |
|
278 | - */ |
|
279 | - public function getStatus() { |
|
280 | - return $this->status; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Get the ETag |
|
286 | - * @return string the etag |
|
287 | - * @since 6.0.0 |
|
288 | - */ |
|
289 | - public function getETag() { |
|
290 | - return $this->ETag; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Get "last modified" date |
|
296 | - * @return \DateTime RFC2822 formatted last modified date |
|
297 | - * @since 6.0.0 |
|
298 | - */ |
|
299 | - public function getLastModified() { |
|
300 | - return $this->lastModified; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Set the ETag |
|
306 | - * @param string $ETag |
|
307 | - * @return Response Reference to this object |
|
308 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
309 | - */ |
|
310 | - public function setETag($ETag) { |
|
311 | - $this->ETag = $ETag; |
|
312 | - |
|
313 | - return $this; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Set "last modified" date |
|
319 | - * @param \DateTime $lastModified |
|
320 | - * @return Response Reference to this object |
|
321 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
322 | - */ |
|
323 | - public function setLastModified($lastModified) { |
|
324 | - $this->lastModified = $lastModified; |
|
325 | - |
|
326 | - return $this; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Marks the response as to throttle. Will be throttled when the |
|
331 | - * @BruteForceProtection annotation is added. |
|
332 | - * |
|
333 | - * @param array $metadata |
|
334 | - * @since 12.0.0 |
|
335 | - */ |
|
336 | - public function throttle(array $metadata = []) { |
|
337 | - $this->throttled = true; |
|
338 | - $this->throttleMetadata = $metadata; |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns the throttle metadata, defaults to empty array |
|
343 | - * |
|
344 | - * @return array |
|
345 | - * @since 13.0.0 |
|
346 | - */ |
|
347 | - public function getThrottleMetadata() { |
|
348 | - return $this->throttleMetadata; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Whether the current response is throttled. |
|
353 | - * |
|
354 | - * @since 12.0.0 |
|
355 | - */ |
|
356 | - public function isThrottled() { |
|
357 | - return $this->throttled; |
|
358 | - } |
|
45 | + /** |
|
46 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + private $headers = array( |
|
50 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | + ); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Cookies that will be need to be constructed as header |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + private $cookies = array(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * HTTP status code - defaults to STATUS OK |
|
63 | + * @var int |
|
64 | + */ |
|
65 | + private $status = Http::STATUS_OK; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Last modified date |
|
70 | + * @var \DateTime |
|
71 | + */ |
|
72 | + private $lastModified; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * ETag |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + private $ETag; |
|
80 | + |
|
81 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | + private $contentSecurityPolicy = null; |
|
83 | + |
|
84 | + /** @var bool */ |
|
85 | + private $throttled = false; |
|
86 | + /** @var array */ |
|
87 | + private $throttleMetadata = []; |
|
88 | + |
|
89 | + /** |
|
90 | + * Caches the response |
|
91 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
92 | + * if 0 then caching will be disabled |
|
93 | + * @return $this |
|
94 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
95 | + */ |
|
96 | + public function cacheFor($cacheSeconds) { |
|
97 | + |
|
98 | + if($cacheSeconds > 0) { |
|
99 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
100 | + } else { |
|
101 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
102 | + } |
|
103 | + |
|
104 | + return $this; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Adds a new cookie to the response |
|
109 | + * @param string $name The name of the cookie |
|
110 | + * @param string $value The value of the cookie |
|
111 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
112 | + * to null cookie will be considered as session |
|
113 | + * cookie. |
|
114 | + * @return $this |
|
115 | + * @since 8.0.0 |
|
116 | + */ |
|
117 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
118 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Set the specified cookies |
|
125 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
126 | + * @return $this |
|
127 | + * @since 8.0.0 |
|
128 | + */ |
|
129 | + public function setCookies(array $cookies) { |
|
130 | + $this->cookies = $cookies; |
|
131 | + return $this; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Invalidates the specified cookie |
|
137 | + * @param string $name |
|
138 | + * @return $this |
|
139 | + * @since 8.0.0 |
|
140 | + */ |
|
141 | + public function invalidateCookie($name) { |
|
142 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
143 | + return $this; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Invalidates the specified cookies |
|
148 | + * @param array $cookieNames array('foo', 'bar') |
|
149 | + * @return $this |
|
150 | + * @since 8.0.0 |
|
151 | + */ |
|
152 | + public function invalidateCookies(array $cookieNames) { |
|
153 | + foreach($cookieNames as $cookieName) { |
|
154 | + $this->invalidateCookie($cookieName); |
|
155 | + } |
|
156 | + return $this; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns the cookies |
|
161 | + * @return array |
|
162 | + * @since 8.0.0 |
|
163 | + */ |
|
164 | + public function getCookies() { |
|
165 | + return $this->cookies; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Adds a new header to the response that will be called before the render |
|
170 | + * function |
|
171 | + * @param string $name The name of the HTTP header |
|
172 | + * @param string $value The value, null will delete it |
|
173 | + * @return $this |
|
174 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
175 | + */ |
|
176 | + public function addHeader($name, $value) { |
|
177 | + $name = trim($name); // always remove leading and trailing whitespace |
|
178 | + // to be able to reliably check for security |
|
179 | + // headers |
|
180 | + |
|
181 | + if(is_null($value)) { |
|
182 | + unset($this->headers[$name]); |
|
183 | + } else { |
|
184 | + $this->headers[$name] = $value; |
|
185 | + } |
|
186 | + |
|
187 | + return $this; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Set the headers |
|
193 | + * @param array $headers value header pairs |
|
194 | + * @return $this |
|
195 | + * @since 8.0.0 |
|
196 | + */ |
|
197 | + public function setHeaders(array $headers) { |
|
198 | + $this->headers = $headers; |
|
199 | + |
|
200 | + return $this; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the set headers |
|
206 | + * @return array the headers |
|
207 | + * @since 6.0.0 |
|
208 | + */ |
|
209 | + public function getHeaders() { |
|
210 | + $mergeWith = []; |
|
211 | + |
|
212 | + if($this->lastModified) { |
|
213 | + $mergeWith['Last-Modified'] = |
|
214 | + $this->lastModified->format(\DateTime::RFC2822); |
|
215 | + } |
|
216 | + |
|
217 | + // Build Content-Security-Policy and use default if none has been specified |
|
218 | + if(is_null($this->contentSecurityPolicy)) { |
|
219 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
220 | + } |
|
221 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
222 | + |
|
223 | + if($this->ETag) { |
|
224 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
225 | + } |
|
226 | + |
|
227 | + return array_merge($mergeWith, $this->headers); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * By default renders no output |
|
233 | + * @return string|null |
|
234 | + * @since 6.0.0 |
|
235 | + */ |
|
236 | + public function render() { |
|
237 | + return null; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Set response status |
|
243 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
244 | + * @return Response Reference to this object |
|
245 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
246 | + */ |
|
247 | + public function setStatus($status) { |
|
248 | + $this->status = $status; |
|
249 | + |
|
250 | + return $this; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Set a Content-Security-Policy |
|
255 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
256 | + * @return $this |
|
257 | + * @since 8.1.0 |
|
258 | + */ |
|
259 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
260 | + $this->contentSecurityPolicy = $csp; |
|
261 | + return $this; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Get the currently used Content-Security-Policy |
|
266 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
267 | + * none specified. |
|
268 | + * @since 8.1.0 |
|
269 | + */ |
|
270 | + public function getContentSecurityPolicy() { |
|
271 | + return $this->contentSecurityPolicy; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Get response status |
|
277 | + * @since 6.0.0 |
|
278 | + */ |
|
279 | + public function getStatus() { |
|
280 | + return $this->status; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Get the ETag |
|
286 | + * @return string the etag |
|
287 | + * @since 6.0.0 |
|
288 | + */ |
|
289 | + public function getETag() { |
|
290 | + return $this->ETag; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Get "last modified" date |
|
296 | + * @return \DateTime RFC2822 formatted last modified date |
|
297 | + * @since 6.0.0 |
|
298 | + */ |
|
299 | + public function getLastModified() { |
|
300 | + return $this->lastModified; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Set the ETag |
|
306 | + * @param string $ETag |
|
307 | + * @return Response Reference to this object |
|
308 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
309 | + */ |
|
310 | + public function setETag($ETag) { |
|
311 | + $this->ETag = $ETag; |
|
312 | + |
|
313 | + return $this; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Set "last modified" date |
|
319 | + * @param \DateTime $lastModified |
|
320 | + * @return Response Reference to this object |
|
321 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
322 | + */ |
|
323 | + public function setLastModified($lastModified) { |
|
324 | + $this->lastModified = $lastModified; |
|
325 | + |
|
326 | + return $this; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Marks the response as to throttle. Will be throttled when the |
|
331 | + * @BruteForceProtection annotation is added. |
|
332 | + * |
|
333 | + * @param array $metadata |
|
334 | + * @since 12.0.0 |
|
335 | + */ |
|
336 | + public function throttle(array $metadata = []) { |
|
337 | + $this->throttled = true; |
|
338 | + $this->throttleMetadata = $metadata; |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns the throttle metadata, defaults to empty array |
|
343 | + * |
|
344 | + * @return array |
|
345 | + * @since 13.0.0 |
|
346 | + */ |
|
347 | + public function getThrottleMetadata() { |
|
348 | + return $this->throttleMetadata; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Whether the current response is throttled. |
|
353 | + * |
|
354 | + * @since 12.0.0 |
|
355 | + */ |
|
356 | + public function isThrottled() { |
|
357 | + return $this->throttled; |
|
358 | + } |
|
359 | 359 | } |