@@ -44,116 +44,116 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | abstract class Controller { |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * app name |
|
| 49 | - * @var string |
|
| 50 | - * @since 7.0.0 |
|
| 51 | - */ |
|
| 52 | - protected $appName; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * current request |
|
| 56 | - * @var \OCP\IRequest |
|
| 57 | - * @since 6.0.0 |
|
| 58 | - */ |
|
| 59 | - protected $request; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var array |
|
| 63 | - * @since 7.0.0 |
|
| 64 | - */ |
|
| 65 | - private $responders; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * constructor of the controller |
|
| 69 | - * @param string $appName the name of the app |
|
| 70 | - * @param IRequest $request an instance of the request |
|
| 71 | - * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 72 | - */ |
|
| 73 | - public function __construct($appName, |
|
| 74 | - IRequest $request) { |
|
| 75 | - $this->appName = $appName; |
|
| 76 | - $this->request = $request; |
|
| 77 | - |
|
| 78 | - // default responders |
|
| 79 | - $this->responders = array( |
|
| 80 | - 'json' => function ($data) { |
|
| 81 | - if ($data instanceof DataResponse) { |
|
| 82 | - $response = new JSONResponse( |
|
| 83 | - $data->getData(), |
|
| 84 | - $data->getStatus() |
|
| 85 | - ); |
|
| 86 | - $dataHeaders = $data->getHeaders(); |
|
| 87 | - $headers = $response->getHeaders(); |
|
| 88 | - // do not overwrite Content-Type if it already exists |
|
| 89 | - if (isset($dataHeaders['Content-Type'])) { |
|
| 90 | - unset($headers['Content-Type']); |
|
| 91 | - } |
|
| 92 | - $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 93 | - return $response; |
|
| 94 | - } |
|
| 95 | - return new JSONResponse($data); |
|
| 96 | - } |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Parses an HTTP accept header and returns the supported responder type |
|
| 103 | - * @param string $acceptHeader |
|
| 104 | - * @param string $default |
|
| 105 | - * @return string the responder type |
|
| 106 | - * @since 7.0.0 |
|
| 107 | - * @since 9.1.0 Added default parameter |
|
| 108 | - */ |
|
| 109 | - public function getResponderByHTTPHeader($acceptHeader, $default='json') { |
|
| 110 | - $headers = explode(',', $acceptHeader); |
|
| 111 | - |
|
| 112 | - // return the first matching responder |
|
| 113 | - foreach ($headers as $header) { |
|
| 114 | - $header = strtolower(trim($header)); |
|
| 115 | - |
|
| 116 | - $responder = str_replace('application/', '', $header); |
|
| 117 | - |
|
| 118 | - if (array_key_exists($responder, $this->responders)) { |
|
| 119 | - return $responder; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // no matching header return default |
|
| 124 | - return $default; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Registers a formatter for a type |
|
| 130 | - * @param string $format |
|
| 131 | - * @param \Closure $responder |
|
| 132 | - * @since 7.0.0 |
|
| 133 | - */ |
|
| 134 | - protected function registerResponder($format, \Closure $responder) { |
|
| 135 | - $this->responders[$format] = $responder; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Serializes and formats a response |
|
| 141 | - * @param mixed $response the value that was returned from a controller and |
|
| 142 | - * is not a Response instance |
|
| 143 | - * @param string $format the format for which a formatter has been registered |
|
| 144 | - * @throws \DomainException if format does not match a registered formatter |
|
| 145 | - * @return Response |
|
| 146 | - * @since 7.0.0 |
|
| 147 | - */ |
|
| 148 | - public function buildResponse($response, $format='json') { |
|
| 149 | - if(array_key_exists($format, $this->responders)) { |
|
| 150 | - |
|
| 151 | - $responder = $this->responders[$format]; |
|
| 152 | - |
|
| 153 | - return $responder($response); |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - throw new \DomainException('No responder registered for format '. |
|
| 157 | - $format . '!'); |
|
| 158 | - } |
|
| 47 | + /** |
|
| 48 | + * app name |
|
| 49 | + * @var string |
|
| 50 | + * @since 7.0.0 |
|
| 51 | + */ |
|
| 52 | + protected $appName; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * current request |
|
| 56 | + * @var \OCP\IRequest |
|
| 57 | + * @since 6.0.0 |
|
| 58 | + */ |
|
| 59 | + protected $request; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var array |
|
| 63 | + * @since 7.0.0 |
|
| 64 | + */ |
|
| 65 | + private $responders; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * constructor of the controller |
|
| 69 | + * @param string $appName the name of the app |
|
| 70 | + * @param IRequest $request an instance of the request |
|
| 71 | + * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 72 | + */ |
|
| 73 | + public function __construct($appName, |
|
| 74 | + IRequest $request) { |
|
| 75 | + $this->appName = $appName; |
|
| 76 | + $this->request = $request; |
|
| 77 | + |
|
| 78 | + // default responders |
|
| 79 | + $this->responders = array( |
|
| 80 | + 'json' => function ($data) { |
|
| 81 | + if ($data instanceof DataResponse) { |
|
| 82 | + $response = new JSONResponse( |
|
| 83 | + $data->getData(), |
|
| 84 | + $data->getStatus() |
|
| 85 | + ); |
|
| 86 | + $dataHeaders = $data->getHeaders(); |
|
| 87 | + $headers = $response->getHeaders(); |
|
| 88 | + // do not overwrite Content-Type if it already exists |
|
| 89 | + if (isset($dataHeaders['Content-Type'])) { |
|
| 90 | + unset($headers['Content-Type']); |
|
| 91 | + } |
|
| 92 | + $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 93 | + return $response; |
|
| 94 | + } |
|
| 95 | + return new JSONResponse($data); |
|
| 96 | + } |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Parses an HTTP accept header and returns the supported responder type |
|
| 103 | + * @param string $acceptHeader |
|
| 104 | + * @param string $default |
|
| 105 | + * @return string the responder type |
|
| 106 | + * @since 7.0.0 |
|
| 107 | + * @since 9.1.0 Added default parameter |
|
| 108 | + */ |
|
| 109 | + public function getResponderByHTTPHeader($acceptHeader, $default='json') { |
|
| 110 | + $headers = explode(',', $acceptHeader); |
|
| 111 | + |
|
| 112 | + // return the first matching responder |
|
| 113 | + foreach ($headers as $header) { |
|
| 114 | + $header = strtolower(trim($header)); |
|
| 115 | + |
|
| 116 | + $responder = str_replace('application/', '', $header); |
|
| 117 | + |
|
| 118 | + if (array_key_exists($responder, $this->responders)) { |
|
| 119 | + return $responder; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // no matching header return default |
|
| 124 | + return $default; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Registers a formatter for a type |
|
| 130 | + * @param string $format |
|
| 131 | + * @param \Closure $responder |
|
| 132 | + * @since 7.0.0 |
|
| 133 | + */ |
|
| 134 | + protected function registerResponder($format, \Closure $responder) { |
|
| 135 | + $this->responders[$format] = $responder; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Serializes and formats a response |
|
| 141 | + * @param mixed $response the value that was returned from a controller and |
|
| 142 | + * is not a Response instance |
|
| 143 | + * @param string $format the format for which a formatter has been registered |
|
| 144 | + * @throws \DomainException if format does not match a registered formatter |
|
| 145 | + * @return Response |
|
| 146 | + * @since 7.0.0 |
|
| 147 | + */ |
|
| 148 | + public function buildResponse($response, $format='json') { |
|
| 149 | + if(array_key_exists($format, $this->responders)) { |
|
| 150 | + |
|
| 151 | + $responder = $this->responders[$format]; |
|
| 152 | + |
|
| 153 | + return $responder($response); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + throw new \DomainException('No responder registered for format '. |
|
| 157 | + $format . '!'); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -24,155 +24,155 @@ |
||
| 24 | 24 | use OC\Files\Storage\Common; |
| 25 | 25 | |
| 26 | 26 | class NullStorage extends Common { |
| 27 | - public function __construct($parameters) { |
|
| 28 | - parent::__construct($parameters); |
|
| 29 | - } |
|
| 27 | + public function __construct($parameters) { |
|
| 28 | + parent::__construct($parameters); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function getId() { |
|
| 32 | - return 'null'; |
|
| 33 | - } |
|
| 31 | + public function getId() { |
|
| 32 | + return 'null'; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function mkdir($path) { |
|
| 36 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 37 | - } |
|
| 35 | + public function mkdir($path) { |
|
| 36 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function rmdir($path) { |
|
| 40 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 41 | - } |
|
| 39 | + public function rmdir($path) { |
|
| 40 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function opendir($path) { |
|
| 44 | - return new IteratorDirectory([]); |
|
| 45 | - } |
|
| 43 | + public function opendir($path) { |
|
| 44 | + return new IteratorDirectory([]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function is_dir($path) { |
|
| 48 | - return $path === ''; |
|
| 49 | - } |
|
| 47 | + public function is_dir($path) { |
|
| 48 | + return $path === ''; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function is_file($path) { |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 51 | + public function is_file($path) { |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function stat($path) { |
|
| 56 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 57 | - } |
|
| 55 | + public function stat($path) { |
|
| 56 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function filetype($path) { |
|
| 60 | - return ($path === '') ? 'dir' : false; |
|
| 61 | - } |
|
| 59 | + public function filetype($path) { |
|
| 60 | + return ($path === '') ? 'dir' : false; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function filesize($path) { |
|
| 64 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | - } |
|
| 63 | + public function filesize($path) { |
|
| 64 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function isCreatable($path) { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 67 | + public function isCreatable($path) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function isReadable($path) { |
|
| 72 | - return $path === ''; |
|
| 73 | - } |
|
| 71 | + public function isReadable($path) { |
|
| 72 | + return $path === ''; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function isUpdatable($path) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 75 | + public function isUpdatable($path) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function isDeletable($path) { |
|
| 80 | - return false; |
|
| 81 | - } |
|
| 79 | + public function isDeletable($path) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - public function isSharable($path) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 83 | + public function isSharable($path) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - public function getPermissions($path) { |
|
| 88 | - return null; |
|
| 89 | - } |
|
| 87 | + public function getPermissions($path) { |
|
| 88 | + return null; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - public function file_exists($path) { |
|
| 92 | - return $path === ''; |
|
| 93 | - } |
|
| 91 | + public function file_exists($path) { |
|
| 92 | + return $path === ''; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - public function filemtime($path) { |
|
| 96 | - return ($path === '') ? time() : false; |
|
| 97 | - } |
|
| 95 | + public function filemtime($path) { |
|
| 96 | + return ($path === '') ? time() : false; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function file_get_contents($path) { |
|
| 100 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 101 | - } |
|
| 99 | + public function file_get_contents($path) { |
|
| 100 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - public function file_put_contents($path, $data) { |
|
| 104 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 105 | - } |
|
| 103 | + public function file_put_contents($path, $data) { |
|
| 104 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function unlink($path) { |
|
| 108 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 109 | - } |
|
| 107 | + public function unlink($path) { |
|
| 108 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function rename($path1, $path2) { |
|
| 112 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 113 | - } |
|
| 111 | + public function rename($path1, $path2) { |
|
| 112 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - public function copy($path1, $path2) { |
|
| 116 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 117 | - } |
|
| 115 | + public function copy($path1, $path2) { |
|
| 116 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - public function fopen($path, $mode) { |
|
| 120 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 121 | - } |
|
| 119 | + public function fopen($path, $mode) { |
|
| 120 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - public function getMimeType($path) { |
|
| 124 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 125 | - } |
|
| 123 | + public function getMimeType($path) { |
|
| 124 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - public function hash($type, $path, $raw = false) { |
|
| 128 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 129 | - } |
|
| 127 | + public function hash($type, $path, $raw = false) { |
|
| 128 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - public function free_space($path) { |
|
| 132 | - return FileInfo::SPACE_UNKNOWN; |
|
| 133 | - } |
|
| 131 | + public function free_space($path) { |
|
| 132 | + return FileInfo::SPACE_UNKNOWN; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - public function touch($path, $mtime = null) { |
|
| 136 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 137 | - } |
|
| 135 | + public function touch($path, $mtime = null) { |
|
| 136 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - public function getLocalFile($path) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 139 | + public function getLocalFile($path) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - public function hasUpdated($path, $time) { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 143 | + public function hasUpdated($path, $time) { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - public function getETag($path) { |
|
| 148 | - return ''; |
|
| 149 | - } |
|
| 147 | + public function getETag($path) { |
|
| 148 | + return ''; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - public function isLocal() { |
|
| 152 | - return false; |
|
| 153 | - } |
|
| 151 | + public function isLocal() { |
|
| 152 | + return false; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - public function getDirectDownload($path) { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 155 | + public function getDirectDownload($path) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
| 160 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 161 | - } |
|
| 159 | + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
| 160 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 164 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 165 | - } |
|
| 163 | + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
| 164 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - public function test() { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 167 | + public function test() { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - public function getOwner($path) { |
|
| 172 | - return null; |
|
| 173 | - } |
|
| 171 | + public function getOwner($path) { |
|
| 172 | + return null; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - public function getCache($path = '', $storage = null) { |
|
| 176 | - return new NullCache(); |
|
| 177 | - } |
|
| 175 | + public function getCache($path = '', $storage = null) { |
|
| 176 | + return new NullCache(); |
|
| 177 | + } |
|
| 178 | 178 | } |