@@ -34,7 +34,7 @@ |
||
| 34 | 34 | * @package OC\AppFramework\Middleware\Security\Exceptions |
| 35 | 35 | */ |
| 36 | 36 | class NotLoggedInException extends SecurityException { |
| 37 | - public function __construct() { |
|
| 38 | - parent::__construct('Current user is not logged in', Http::STATUS_UNAUTHORIZED); |
|
| 39 | - } |
|
| 37 | + public function __construct() { |
|
| 38 | + parent::__construct('Current user is not logged in', Http::STATUS_UNAUTHORIZED); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -143,7 +143,7 @@ |
||
| 143 | 143 | $format = $this->request->getParam('format'); |
| 144 | 144 | |
| 145 | 145 | // if none is given try the first Accept header |
| 146 | - if($format === null) { |
|
| 146 | + if ($format === null) { |
|
| 147 | 147 | $headers = $this->request->getHeader('Accept'); |
| 148 | 148 | $format = $controller->getResponderByHTTPHeader($headers, 'xml'); |
| 149 | 149 | } |
@@ -39,116 +39,116 @@ |
||
| 39 | 39 | |
| 40 | 40 | class OCSMiddleware extends Middleware { |
| 41 | 41 | |
| 42 | - /** @var IRequest */ |
|
| 43 | - private $request; |
|
| 44 | - |
|
| 45 | - /** @var int */ |
|
| 46 | - private $ocsVersion; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param IRequest $request |
|
| 50 | - */ |
|
| 51 | - public function __construct(IRequest $request) { |
|
| 52 | - $this->request = $request; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param Controller $controller |
|
| 57 | - * @param string $methodName |
|
| 58 | - */ |
|
| 59 | - public function beforeController($controller, $methodName) { |
|
| 60 | - if ($controller instanceof OCSController) { |
|
| 61 | - if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { |
|
| 62 | - $this->ocsVersion = 2; |
|
| 63 | - } else { |
|
| 64 | - $this->ocsVersion = 1; |
|
| 65 | - } |
|
| 66 | - $controller->setOCSVersion($this->ocsVersion); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param Controller $controller |
|
| 72 | - * @param string $methodName |
|
| 73 | - * @param \Exception $exception |
|
| 74 | - * @throws \Exception |
|
| 75 | - * @return BaseResponse |
|
| 76 | - */ |
|
| 77 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 78 | - if ($controller instanceof OCSController && $exception instanceof OCSException) { |
|
| 79 | - $code = $exception->getCode(); |
|
| 80 | - if ($code === 0) { |
|
| 81 | - $code = API::RESPOND_UNKNOWN_ERROR; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $this->buildNewResponse($controller, $code, $exception->getMessage()); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - throw $exception; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param Controller $controller |
|
| 92 | - * @param string $methodName |
|
| 93 | - * @param Response $response |
|
| 94 | - * @return \OCP\AppFramework\Http\Response |
|
| 95 | - */ |
|
| 96 | - public function afterController($controller, $methodName, Response $response) { |
|
| 97 | - /* |
|
| 42 | + /** @var IRequest */ |
|
| 43 | + private $request; |
|
| 44 | + |
|
| 45 | + /** @var int */ |
|
| 46 | + private $ocsVersion; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param IRequest $request |
|
| 50 | + */ |
|
| 51 | + public function __construct(IRequest $request) { |
|
| 52 | + $this->request = $request; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param Controller $controller |
|
| 57 | + * @param string $methodName |
|
| 58 | + */ |
|
| 59 | + public function beforeController($controller, $methodName) { |
|
| 60 | + if ($controller instanceof OCSController) { |
|
| 61 | + if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { |
|
| 62 | + $this->ocsVersion = 2; |
|
| 63 | + } else { |
|
| 64 | + $this->ocsVersion = 1; |
|
| 65 | + } |
|
| 66 | + $controller->setOCSVersion($this->ocsVersion); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param Controller $controller |
|
| 72 | + * @param string $methodName |
|
| 73 | + * @param \Exception $exception |
|
| 74 | + * @throws \Exception |
|
| 75 | + * @return BaseResponse |
|
| 76 | + */ |
|
| 77 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 78 | + if ($controller instanceof OCSController && $exception instanceof OCSException) { |
|
| 79 | + $code = $exception->getCode(); |
|
| 80 | + if ($code === 0) { |
|
| 81 | + $code = API::RESPOND_UNKNOWN_ERROR; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $this->buildNewResponse($controller, $code, $exception->getMessage()); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + throw $exception; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param Controller $controller |
|
| 92 | + * @param string $methodName |
|
| 93 | + * @param Response $response |
|
| 94 | + * @return \OCP\AppFramework\Http\Response |
|
| 95 | + */ |
|
| 96 | + public function afterController($controller, $methodName, Response $response) { |
|
| 97 | + /* |
|
| 98 | 98 | * If a different middleware has detected that a request unauthorized or forbidden |
| 99 | 99 | * we need to catch the response and convert it to a proper OCS response. |
| 100 | 100 | */ |
| 101 | - if ($controller instanceof OCSController && !($response instanceof BaseResponse)) { |
|
| 102 | - if ($response->getStatus() === Http::STATUS_UNAUTHORIZED || |
|
| 103 | - $response->getStatus() === Http::STATUS_FORBIDDEN) { |
|
| 104 | - |
|
| 105 | - $message = ''; |
|
| 106 | - if ($response instanceof JSONResponse) { |
|
| 107 | - /** @var DataResponse $response */ |
|
| 108 | - $message = $response->getData()['message']; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $this->buildNewResponse($controller, API::RESPOND_UNAUTHORISED, $message); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $response; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param Controller $controller |
|
| 120 | - * @param int $code |
|
| 121 | - * @param string $message |
|
| 122 | - * @return V1Response|V2Response |
|
| 123 | - */ |
|
| 124 | - private function buildNewResponse(Controller $controller, $code, $message) { |
|
| 125 | - $format = $this->getFormat($controller); |
|
| 126 | - |
|
| 127 | - $data = new DataResponse(); |
|
| 128 | - $data->setStatus($code); |
|
| 129 | - if ($this->ocsVersion === 1) { |
|
| 130 | - $response = new V1Response($data, $format, $message); |
|
| 131 | - } else { |
|
| 132 | - $response = new V2Response($data, $format, $message); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $response; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param Controller $controller |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - private function getFormat(Controller $controller) { |
|
| 143 | - // get format from the url format or request format parameter |
|
| 144 | - $format = $this->request->getParam('format'); |
|
| 145 | - |
|
| 146 | - // if none is given try the first Accept header |
|
| 147 | - if($format === null) { |
|
| 148 | - $headers = $this->request->getHeader('Accept'); |
|
| 149 | - $format = $controller->getResponderByHTTPHeader($headers, 'xml'); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $format; |
|
| 153 | - } |
|
| 101 | + if ($controller instanceof OCSController && !($response instanceof BaseResponse)) { |
|
| 102 | + if ($response->getStatus() === Http::STATUS_UNAUTHORIZED || |
|
| 103 | + $response->getStatus() === Http::STATUS_FORBIDDEN) { |
|
| 104 | + |
|
| 105 | + $message = ''; |
|
| 106 | + if ($response instanceof JSONResponse) { |
|
| 107 | + /** @var DataResponse $response */ |
|
| 108 | + $message = $response->getData()['message']; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $this->buildNewResponse($controller, API::RESPOND_UNAUTHORISED, $message); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return $response; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param Controller $controller |
|
| 120 | + * @param int $code |
|
| 121 | + * @param string $message |
|
| 122 | + * @return V1Response|V2Response |
|
| 123 | + */ |
|
| 124 | + private function buildNewResponse(Controller $controller, $code, $message) { |
|
| 125 | + $format = $this->getFormat($controller); |
|
| 126 | + |
|
| 127 | + $data = new DataResponse(); |
|
| 128 | + $data->setStatus($code); |
|
| 129 | + if ($this->ocsVersion === 1) { |
|
| 130 | + $response = new V1Response($data, $format, $message); |
|
| 131 | + } else { |
|
| 132 | + $response = new V2Response($data, $format, $message); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $response; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param Controller $controller |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + private function getFormat(Controller $controller) { |
|
| 143 | + // get format from the url format or request format parameter |
|
| 144 | + $format = $this->request->getParam('format'); |
|
| 145 | + |
|
| 146 | + // if none is given try the first Accept header |
|
| 147 | + if($format === null) { |
|
| 148 | + $headers = $this->request->getHeader('Accept'); |
|
| 149 | + $format = $controller->getResponderByHTTPHeader($headers, 'xml'); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $format; |
|
| 153 | + } |
|
| 154 | 154 | } |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | * @param Response $response |
| 72 | 72 | * @return Response |
| 73 | 73 | */ |
| 74 | - public function afterController($controller, $methodName, Response $response){ |
|
| 74 | + public function afterController($controller, $methodName, Response $response) { |
|
| 75 | 75 | $useSession = $this->reflector->hasAnnotation('UseSession'); |
| 76 | 76 | if ($useSession) { |
| 77 | 77 | $this->session->close(); |
@@ -32,52 +32,52 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SessionMiddleware extends Middleware { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var IRequest |
|
| 37 | - */ |
|
| 38 | - private $request; |
|
| 35 | + /** |
|
| 36 | + * @var IRequest |
|
| 37 | + */ |
|
| 38 | + private $request; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var ControllerMethodReflector |
|
| 42 | - */ |
|
| 43 | - private $reflector; |
|
| 40 | + /** |
|
| 41 | + * @var ControllerMethodReflector |
|
| 42 | + */ |
|
| 43 | + private $reflector; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param IRequest $request |
|
| 47 | - * @param ControllerMethodReflector $reflector |
|
| 48 | - */ |
|
| 49 | - public function __construct(IRequest $request, |
|
| 50 | - ControllerMethodReflector $reflector, |
|
| 51 | - ISession $session |
|
| 45 | + /** |
|
| 46 | + * @param IRequest $request |
|
| 47 | + * @param ControllerMethodReflector $reflector |
|
| 48 | + */ |
|
| 49 | + public function __construct(IRequest $request, |
|
| 50 | + ControllerMethodReflector $reflector, |
|
| 51 | + ISession $session |
|
| 52 | 52 | ) { |
| 53 | - $this->request = $request; |
|
| 54 | - $this->reflector = $reflector; |
|
| 55 | - $this->session = $session; |
|
| 56 | - } |
|
| 53 | + $this->request = $request; |
|
| 54 | + $this->reflector = $reflector; |
|
| 55 | + $this->session = $session; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param Controller $controller |
|
| 60 | - * @param string $methodName |
|
| 61 | - */ |
|
| 62 | - public function beforeController($controller, $methodName) { |
|
| 63 | - $useSession = $this->reflector->hasAnnotation('UseSession'); |
|
| 64 | - if (!$useSession) { |
|
| 65 | - $this->session->close(); |
|
| 66 | - } |
|
| 67 | - } |
|
| 58 | + /** |
|
| 59 | + * @param Controller $controller |
|
| 60 | + * @param string $methodName |
|
| 61 | + */ |
|
| 62 | + public function beforeController($controller, $methodName) { |
|
| 63 | + $useSession = $this->reflector->hasAnnotation('UseSession'); |
|
| 64 | + if (!$useSession) { |
|
| 65 | + $this->session->close(); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param Controller $controller |
|
| 71 | - * @param string $methodName |
|
| 72 | - * @param Response $response |
|
| 73 | - * @return Response |
|
| 74 | - */ |
|
| 75 | - public function afterController($controller, $methodName, Response $response){ |
|
| 76 | - $useSession = $this->reflector->hasAnnotation('UseSession'); |
|
| 77 | - if ($useSession) { |
|
| 78 | - $this->session->close(); |
|
| 79 | - } |
|
| 80 | - return $response; |
|
| 81 | - } |
|
| 69 | + /** |
|
| 70 | + * @param Controller $controller |
|
| 71 | + * @param string $methodName |
|
| 72 | + * @param Response $response |
|
| 73 | + * @return Response |
|
| 74 | + */ |
|
| 75 | + public function afterController($controller, $methodName, Response $response){ |
|
| 76 | + $useSession = $this->reflector->hasAnnotation('UseSession'); |
|
| 77 | + if ($useSession) { |
|
| 78 | + $this->session->close(); |
|
| 79 | + } |
|
| 80 | + return $response; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | } |
@@ -37,128 +37,128 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class MiddlewareDispatcher { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var array array containing all the middlewares |
|
| 42 | - */ |
|
| 43 | - private $middlewares; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var int counter which tells us what middlware was executed once an |
|
| 47 | - * exception occurs |
|
| 48 | - */ |
|
| 49 | - private $middlewareCounter; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Constructor |
|
| 54 | - */ |
|
| 55 | - public function __construct(){ |
|
| 56 | - $this->middlewares = array(); |
|
| 57 | - $this->middlewareCounter = 0; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Adds a new middleware |
|
| 63 | - * @param Middleware $middleWare the middleware which will be added |
|
| 64 | - */ |
|
| 65 | - public function registerMiddleware(Middleware $middleWare){ |
|
| 66 | - array_push($this->middlewares, $middleWare); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * returns an array with all middleware elements |
|
| 72 | - * @return array the middlewares |
|
| 73 | - */ |
|
| 74 | - public function getMiddlewares(){ |
|
| 75 | - return $this->middlewares; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This is being run in normal order before the controller is being |
|
| 81 | - * called which allows several modifications and checks |
|
| 82 | - * |
|
| 83 | - * @param Controller $controller the controller that is being called |
|
| 84 | - * @param string $methodName the name of the method that will be called on |
|
| 85 | - * the controller |
|
| 86 | - */ |
|
| 87 | - public function beforeController(Controller $controller, $methodName){ |
|
| 88 | - // we need to count so that we know which middlewares we have to ask in |
|
| 89 | - // case there is an exception |
|
| 90 | - $middlewareCount = count($this->middlewares); |
|
| 91 | - for($i = 0; $i < $middlewareCount; $i++){ |
|
| 92 | - $this->middlewareCounter++; |
|
| 93 | - $middleware = $this->middlewares[$i]; |
|
| 94 | - $middleware->beforeController($controller, $methodName); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * This is being run when either the beforeController method or the |
|
| 101 | - * controller method itself is throwing an exception. The middleware is asked |
|
| 102 | - * in reverse order to handle the exception and to return a response. |
|
| 103 | - * If the response is null, it is assumed that the exception could not be |
|
| 104 | - * handled and the error will be thrown again |
|
| 105 | - * |
|
| 106 | - * @param Controller $controller the controller that is being called |
|
| 107 | - * @param string $methodName the name of the method that will be called on |
|
| 108 | - * the controller |
|
| 109 | - * @param \Exception $exception the thrown exception |
|
| 110 | - * @return Response a Response object if the middleware can handle the |
|
| 111 | - * exception |
|
| 112 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 113 | - */ |
|
| 114 | - public function afterException(Controller $controller, $methodName, \Exception $exception){ |
|
| 115 | - for($i=$this->middlewareCounter-1; $i>=0; $i--){ |
|
| 116 | - $middleware = $this->middlewares[$i]; |
|
| 117 | - try { |
|
| 118 | - return $middleware->afterException($controller, $methodName, $exception); |
|
| 119 | - } catch(\Exception $exception){ |
|
| 120 | - continue; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - throw $exception; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * This is being run after a successful controllermethod call and allows |
|
| 129 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
| 130 | - * |
|
| 131 | - * @param Controller $controller the controller that is being called |
|
| 132 | - * @param string $methodName the name of the method that will be called on |
|
| 133 | - * the controller |
|
| 134 | - * @param Response $response the generated response from the controller |
|
| 135 | - * @return Response a Response object |
|
| 136 | - */ |
|
| 137 | - public function afterController(Controller $controller, $methodName, Response $response){ |
|
| 138 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 139 | - $middleware = $this->middlewares[$i]; |
|
| 140 | - $response = $middleware->afterController($controller, $methodName, $response); |
|
| 141 | - } |
|
| 142 | - return $response; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * This is being run after the response object has been rendered and |
|
| 148 | - * allows the manipulation of the output. The middleware is run in reverse order |
|
| 149 | - * |
|
| 150 | - * @param Controller $controller the controller that is being called |
|
| 151 | - * @param string $methodName the name of the method that will be called on |
|
| 152 | - * the controller |
|
| 153 | - * @param string $output the generated output from a response |
|
| 154 | - * @return string the output that should be printed |
|
| 155 | - */ |
|
| 156 | - public function beforeOutput(Controller $controller, $methodName, $output){ |
|
| 157 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 158 | - $middleware = $this->middlewares[$i]; |
|
| 159 | - $output = $middleware->beforeOutput($controller, $methodName, $output); |
|
| 160 | - } |
|
| 161 | - return $output; |
|
| 162 | - } |
|
| 40 | + /** |
|
| 41 | + * @var array array containing all the middlewares |
|
| 42 | + */ |
|
| 43 | + private $middlewares; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var int counter which tells us what middlware was executed once an |
|
| 47 | + * exception occurs |
|
| 48 | + */ |
|
| 49 | + private $middlewareCounter; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Constructor |
|
| 54 | + */ |
|
| 55 | + public function __construct(){ |
|
| 56 | + $this->middlewares = array(); |
|
| 57 | + $this->middlewareCounter = 0; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Adds a new middleware |
|
| 63 | + * @param Middleware $middleWare the middleware which will be added |
|
| 64 | + */ |
|
| 65 | + public function registerMiddleware(Middleware $middleWare){ |
|
| 66 | + array_push($this->middlewares, $middleWare); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * returns an array with all middleware elements |
|
| 72 | + * @return array the middlewares |
|
| 73 | + */ |
|
| 74 | + public function getMiddlewares(){ |
|
| 75 | + return $this->middlewares; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This is being run in normal order before the controller is being |
|
| 81 | + * called which allows several modifications and checks |
|
| 82 | + * |
|
| 83 | + * @param Controller $controller the controller that is being called |
|
| 84 | + * @param string $methodName the name of the method that will be called on |
|
| 85 | + * the controller |
|
| 86 | + */ |
|
| 87 | + public function beforeController(Controller $controller, $methodName){ |
|
| 88 | + // we need to count so that we know which middlewares we have to ask in |
|
| 89 | + // case there is an exception |
|
| 90 | + $middlewareCount = count($this->middlewares); |
|
| 91 | + for($i = 0; $i < $middlewareCount; $i++){ |
|
| 92 | + $this->middlewareCounter++; |
|
| 93 | + $middleware = $this->middlewares[$i]; |
|
| 94 | + $middleware->beforeController($controller, $methodName); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * This is being run when either the beforeController method or the |
|
| 101 | + * controller method itself is throwing an exception. The middleware is asked |
|
| 102 | + * in reverse order to handle the exception and to return a response. |
|
| 103 | + * If the response is null, it is assumed that the exception could not be |
|
| 104 | + * handled and the error will be thrown again |
|
| 105 | + * |
|
| 106 | + * @param Controller $controller the controller that is being called |
|
| 107 | + * @param string $methodName the name of the method that will be called on |
|
| 108 | + * the controller |
|
| 109 | + * @param \Exception $exception the thrown exception |
|
| 110 | + * @return Response a Response object if the middleware can handle the |
|
| 111 | + * exception |
|
| 112 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 113 | + */ |
|
| 114 | + public function afterException(Controller $controller, $methodName, \Exception $exception){ |
|
| 115 | + for($i=$this->middlewareCounter-1; $i>=0; $i--){ |
|
| 116 | + $middleware = $this->middlewares[$i]; |
|
| 117 | + try { |
|
| 118 | + return $middleware->afterException($controller, $methodName, $exception); |
|
| 119 | + } catch(\Exception $exception){ |
|
| 120 | + continue; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + throw $exception; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * This is being run after a successful controllermethod call and allows |
|
| 129 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
| 130 | + * |
|
| 131 | + * @param Controller $controller the controller that is being called |
|
| 132 | + * @param string $methodName the name of the method that will be called on |
|
| 133 | + * the controller |
|
| 134 | + * @param Response $response the generated response from the controller |
|
| 135 | + * @return Response a Response object |
|
| 136 | + */ |
|
| 137 | + public function afterController(Controller $controller, $methodName, Response $response){ |
|
| 138 | + for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 139 | + $middleware = $this->middlewares[$i]; |
|
| 140 | + $response = $middleware->afterController($controller, $methodName, $response); |
|
| 141 | + } |
|
| 142 | + return $response; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * This is being run after the response object has been rendered and |
|
| 148 | + * allows the manipulation of the output. The middleware is run in reverse order |
|
| 149 | + * |
|
| 150 | + * @param Controller $controller the controller that is being called |
|
| 151 | + * @param string $methodName the name of the method that will be called on |
|
| 152 | + * the controller |
|
| 153 | + * @param string $output the generated output from a response |
|
| 154 | + * @return string the output that should be printed |
|
| 155 | + */ |
|
| 156 | + public function beforeOutput(Controller $controller, $methodName, $output){ |
|
| 157 | + for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 158 | + $middleware = $this->middlewares[$i]; |
|
| 159 | + $output = $middleware->beforeOutput($controller, $methodName, $output); |
|
| 160 | + } |
|
| 161 | + return $output; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | 164 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * Constructor |
| 54 | 54 | */ |
| 55 | - public function __construct(){ |
|
| 55 | + public function __construct() { |
|
| 56 | 56 | $this->middlewares = array(); |
| 57 | 57 | $this->middlewareCounter = 0; |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * Adds a new middleware |
| 63 | 63 | * @param Middleware $middleWare the middleware which will be added |
| 64 | 64 | */ |
| 65 | - public function registerMiddleware(Middleware $middleWare){ |
|
| 65 | + public function registerMiddleware(Middleware $middleWare) { |
|
| 66 | 66 | array_push($this->middlewares, $middleWare); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * returns an array with all middleware elements |
| 72 | 72 | * @return array the middlewares |
| 73 | 73 | */ |
| 74 | - public function getMiddlewares(){ |
|
| 74 | + public function getMiddlewares() { |
|
| 75 | 75 | return $this->middlewares; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | * @param string $methodName the name of the method that will be called on |
| 85 | 85 | * the controller |
| 86 | 86 | */ |
| 87 | - public function beforeController(Controller $controller, $methodName){ |
|
| 87 | + public function beforeController(Controller $controller, $methodName) { |
|
| 88 | 88 | // we need to count so that we know which middlewares we have to ask in |
| 89 | 89 | // case there is an exception |
| 90 | 90 | $middlewareCount = count($this->middlewares); |
| 91 | - for($i = 0; $i < $middlewareCount; $i++){ |
|
| 91 | + for ($i = 0; $i < $middlewareCount; $i++) { |
|
| 92 | 92 | $this->middlewareCounter++; |
| 93 | 93 | $middleware = $this->middlewares[$i]; |
| 94 | 94 | $middleware->beforeController($controller, $methodName); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | * exception |
| 112 | 112 | * @throws \Exception the passed in exception if it can't handle it |
| 113 | 113 | */ |
| 114 | - public function afterException(Controller $controller, $methodName, \Exception $exception){ |
|
| 115 | - for($i=$this->middlewareCounter-1; $i>=0; $i--){ |
|
| 114 | + public function afterException(Controller $controller, $methodName, \Exception $exception) { |
|
| 115 | + for ($i = $this->middlewareCounter - 1; $i >= 0; $i--) { |
|
| 116 | 116 | $middleware = $this->middlewares[$i]; |
| 117 | 117 | try { |
| 118 | 118 | return $middleware->afterException($controller, $methodName, $exception); |
| 119 | - } catch(\Exception $exception){ |
|
| 119 | + } catch (\Exception $exception) { |
|
| 120 | 120 | continue; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | * @param Response $response the generated response from the controller |
| 135 | 135 | * @return Response a Response object |
| 136 | 136 | */ |
| 137 | - public function afterController(Controller $controller, $methodName, Response $response){ |
|
| 138 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 137 | + public function afterController(Controller $controller, $methodName, Response $response) { |
|
| 138 | + for ($i = count($this->middlewares) - 1; $i >= 0; $i--) { |
|
| 139 | 139 | $middleware = $this->middlewares[$i]; |
| 140 | 140 | $response = $middleware->afterController($controller, $methodName, $response); |
| 141 | 141 | } |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * @param string $output the generated output from a response |
| 154 | 154 | * @return string the output that should be printed |
| 155 | 155 | */ |
| 156 | - public function beforeOutput(Controller $controller, $methodName, $output){ |
|
| 157 | - for($i=count($this->middlewares)-1; $i>=0; $i--){ |
|
| 156 | + public function beforeOutput(Controller $controller, $methodName, $output) { |
|
| 157 | + for ($i = count($this->middlewares) - 1; $i >= 0; $i--) { |
|
| 158 | 158 | $middleware = $this->middlewares[$i]; |
| 159 | 159 | $output = $middleware->beforeOutput($controller, $methodName, $output); |
| 160 | 160 | } |
@@ -27,50 +27,50 @@ |
||
| 27 | 27 | |
| 28 | 28 | class V2Response extends BaseResponse { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The V2 endpoint just passes on status codes. |
|
| 32 | - * Of course we have to map the OCS specific codes to proper HTTP status codes |
|
| 33 | - * |
|
| 34 | - * @return int |
|
| 35 | - */ |
|
| 36 | - public function getStatus() { |
|
| 30 | + /** |
|
| 31 | + * The V2 endpoint just passes on status codes. |
|
| 32 | + * Of course we have to map the OCS specific codes to proper HTTP status codes |
|
| 33 | + * |
|
| 34 | + * @return int |
|
| 35 | + */ |
|
| 36 | + public function getStatus() { |
|
| 37 | 37 | |
| 38 | - $status = parent::getStatus(); |
|
| 39 | - if ($status === API::RESPOND_UNAUTHORISED) { |
|
| 40 | - return Http::STATUS_UNAUTHORIZED; |
|
| 41 | - } else if ($status === API::RESPOND_NOT_FOUND) { |
|
| 42 | - return Http::STATUS_NOT_FOUND; |
|
| 43 | - } else if ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) { |
|
| 44 | - return Http::STATUS_INTERNAL_SERVER_ERROR; |
|
| 45 | - } else if ($status < 200 || $status > 600) { |
|
| 46 | - return Http::STATUS_BAD_REQUEST; |
|
| 47 | - } |
|
| 38 | + $status = parent::getStatus(); |
|
| 39 | + if ($status === API::RESPOND_UNAUTHORISED) { |
|
| 40 | + return Http::STATUS_UNAUTHORIZED; |
|
| 41 | + } else if ($status === API::RESPOND_NOT_FOUND) { |
|
| 42 | + return Http::STATUS_NOT_FOUND; |
|
| 43 | + } else if ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) { |
|
| 44 | + return Http::STATUS_INTERNAL_SERVER_ERROR; |
|
| 45 | + } else if ($status < 200 || $status > 600) { |
|
| 46 | + return Http::STATUS_BAD_REQUEST; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $status; |
|
| 50 | - } |
|
| 49 | + return $status; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Construct the meta part of the response |
|
| 54 | - * And then late the base class render |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function render() { |
|
| 59 | - $status = parent::getStatus(); |
|
| 52 | + /** |
|
| 53 | + * Construct the meta part of the response |
|
| 54 | + * And then late the base class render |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function render() { |
|
| 59 | + $status = parent::getStatus(); |
|
| 60 | 60 | |
| 61 | - $meta = [ |
|
| 62 | - 'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure', |
|
| 63 | - 'statuscode' => $this->getOCSStatus(), |
|
| 64 | - 'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage, |
|
| 65 | - ]; |
|
| 61 | + $meta = [ |
|
| 62 | + 'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure', |
|
| 63 | + 'statuscode' => $this->getOCSStatus(), |
|
| 64 | + 'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage, |
|
| 65 | + ]; |
|
| 66 | 66 | |
| 67 | - if ($this->itemsCount !== null) { |
|
| 68 | - $meta['totalitems'] = $this->itemsCount; |
|
| 69 | - } |
|
| 70 | - if ($this->itemsPerPage !== null) { |
|
| 71 | - $meta['itemsperpage'] = $this->itemsPerPage; |
|
| 72 | - } |
|
| 67 | + if ($this->itemsCount !== null) { |
|
| 68 | + $meta['totalitems'] = $this->itemsCount; |
|
| 69 | + } |
|
| 70 | + if ($this->itemsPerPage !== null) { |
|
| 71 | + $meta['itemsperpage'] = $this->itemsPerPage; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $this->renderResult($meta); |
|
| 75 | - } |
|
| 74 | + return $this->renderResult($meta); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function getStatus() { |
| 37 | 37 | |
| 38 | - $status = parent::getStatus(); |
|
| 38 | + $status = parent::getStatus(); |
|
| 39 | 39 | if ($status === API::RESPOND_UNAUTHORISED) { |
| 40 | 40 | return Http::STATUS_UNAUTHORIZED; |
| 41 | 41 | } else if ($status === API::RESPOND_NOT_FOUND) { |
@@ -27,52 +27,52 @@ |
||
| 27 | 27 | |
| 28 | 28 | class V1Response extends BaseResponse { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The V1 endpoint has very limited http status codes basically everything |
|
| 32 | - * is status 200 except 401 |
|
| 33 | - * |
|
| 34 | - * @return int |
|
| 35 | - */ |
|
| 36 | - public function getStatus() { |
|
| 37 | - $status = parent::getStatus(); |
|
| 38 | - if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
|
| 39 | - return Http::STATUS_UNAUTHORIZED; |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * The V1 endpoint has very limited http status codes basically everything |
|
| 32 | + * is status 200 except 401 |
|
| 33 | + * |
|
| 34 | + * @return int |
|
| 35 | + */ |
|
| 36 | + public function getStatus() { |
|
| 37 | + $status = parent::getStatus(); |
|
| 38 | + if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
|
| 39 | + return Http::STATUS_UNAUTHORIZED; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return Http::STATUS_OK; |
|
| 43 | - } |
|
| 42 | + return Http::STATUS_OK; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * In v1 all OK is 100 |
|
| 47 | - * |
|
| 48 | - * @return int |
|
| 49 | - */ |
|
| 50 | - public function getOCSStatus() { |
|
| 51 | - $status = parent::getOCSStatus(); |
|
| 45 | + /** |
|
| 46 | + * In v1 all OK is 100 |
|
| 47 | + * |
|
| 48 | + * @return int |
|
| 49 | + */ |
|
| 50 | + public function getOCSStatus() { |
|
| 51 | + $status = parent::getOCSStatus(); |
|
| 52 | 52 | |
| 53 | - if ($status === Http::STATUS_OK) { |
|
| 54 | - return 100; |
|
| 55 | - } |
|
| 53 | + if ($status === Http::STATUS_OK) { |
|
| 54 | + return 100; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $status; |
|
| 58 | - } |
|
| 57 | + return $status; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Construct the meta part of the response |
|
| 62 | - * And then late the base class render |
|
| 63 | - * |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function render() { |
|
| 67 | - $meta = [ |
|
| 68 | - 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
| 69 | - 'statuscode' => $this->getOCSStatus(), |
|
| 70 | - 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
| 71 | - ]; |
|
| 60 | + /** |
|
| 61 | + * Construct the meta part of the response |
|
| 62 | + * And then late the base class render |
|
| 63 | + * |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function render() { |
|
| 67 | + $meta = [ |
|
| 68 | + 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', |
|
| 69 | + 'statuscode' => $this->getOCSStatus(), |
|
| 70 | + 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
|
| 71 | + ]; |
|
| 72 | 72 | |
| 73 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
| 74 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
| 73 | + $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
| 74 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
| 75 | 75 | |
| 76 | - return $this->renderResult($meta); |
|
| 77 | - } |
|
| 76 | + return $this->renderResult($meta); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return int |
| 35 | 35 | */ |
| 36 | 36 | public function getStatus() { |
| 37 | - $status = parent::getStatus(); |
|
| 37 | + $status = parent::getStatus(); |
|
| 38 | 38 | if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { |
| 39 | 39 | return Http::STATUS_UNAUTHORIZED; |
| 40 | 40 | } |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, |
| 71 | 71 | ]; |
| 72 | 72 | |
| 73 | - $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; |
|
| 74 | - $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; |
|
| 73 | + $meta['totalitems'] = $this->itemsCount !== null ? (string) $this->itemsCount : ''; |
|
| 74 | + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string) $this->itemsPerPage : ''; |
|
| 75 | 75 | |
| 76 | 76 | return $this->renderResult($meta); |
| 77 | 77 | } |
@@ -36,242 +36,242 @@ |
||
| 36 | 36 | * @package OC\AppFramework\routing |
| 37 | 37 | */ |
| 38 | 38 | class RouteConfig { |
| 39 | - /** @var DIContainer */ |
|
| 40 | - private $container; |
|
| 41 | - |
|
| 42 | - /** @var IRouter */ |
|
| 43 | - private $router; |
|
| 44 | - |
|
| 45 | - /** @var array */ |
|
| 46 | - private $routes; |
|
| 47 | - |
|
| 48 | - /** @var string */ |
|
| 49 | - private $appName; |
|
| 50 | - |
|
| 51 | - /** @var string[] */ |
|
| 52 | - private $controllerNameCache = []; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
| 56 | - * @param \OCP\Route\IRouter $router |
|
| 57 | - * @param array $routes |
|
| 58 | - * @internal param $appName |
|
| 59 | - */ |
|
| 60 | - public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
| 61 | - $this->routes = $routes; |
|
| 62 | - $this->container = $container; |
|
| 63 | - $this->router = $router; |
|
| 64 | - $this->appName = $container['AppName']; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * The routes and resource will be registered to the \OCP\Route\IRouter |
|
| 69 | - */ |
|
| 70 | - public function register() { |
|
| 71 | - |
|
| 72 | - // parse simple |
|
| 73 | - $this->processSimpleRoutes($this->routes); |
|
| 74 | - |
|
| 75 | - // parse resources |
|
| 76 | - $this->processResources($this->routes); |
|
| 77 | - |
|
| 78 | - /* |
|
| 39 | + /** @var DIContainer */ |
|
| 40 | + private $container; |
|
| 41 | + |
|
| 42 | + /** @var IRouter */ |
|
| 43 | + private $router; |
|
| 44 | + |
|
| 45 | + /** @var array */ |
|
| 46 | + private $routes; |
|
| 47 | + |
|
| 48 | + /** @var string */ |
|
| 49 | + private $appName; |
|
| 50 | + |
|
| 51 | + /** @var string[] */ |
|
| 52 | + private $controllerNameCache = []; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param \OC\AppFramework\DependencyInjection\DIContainer $container |
|
| 56 | + * @param \OCP\Route\IRouter $router |
|
| 57 | + * @param array $routes |
|
| 58 | + * @internal param $appName |
|
| 59 | + */ |
|
| 60 | + public function __construct(DIContainer $container, IRouter $router, $routes) { |
|
| 61 | + $this->routes = $routes; |
|
| 62 | + $this->container = $container; |
|
| 63 | + $this->router = $router; |
|
| 64 | + $this->appName = $container['AppName']; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * The routes and resource will be registered to the \OCP\Route\IRouter |
|
| 69 | + */ |
|
| 70 | + public function register() { |
|
| 71 | + |
|
| 72 | + // parse simple |
|
| 73 | + $this->processSimpleRoutes($this->routes); |
|
| 74 | + |
|
| 75 | + // parse resources |
|
| 76 | + $this->processResources($this->routes); |
|
| 77 | + |
|
| 78 | + /* |
|
| 79 | 79 | * OCS routes go into a different collection |
| 80 | 80 | */ |
| 81 | - $oldCollection = $this->router->getCurrentCollection(); |
|
| 82 | - $this->router->useCollection($oldCollection.'.ocs'); |
|
| 83 | - |
|
| 84 | - // parse ocs simple routes |
|
| 85 | - $this->processOCS($this->routes); |
|
| 86 | - |
|
| 87 | - $this->router->useCollection($oldCollection); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - private function processOCS(array $routes) { |
|
| 91 | - $ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; |
|
| 92 | - foreach ($ocsRoutes as $ocsRoute) { |
|
| 93 | - $name = $ocsRoute['name']; |
|
| 94 | - $postfix = ''; |
|
| 95 | - |
|
| 96 | - if (isset($ocsRoute['postfix'])) { |
|
| 97 | - $postfix = $ocsRoute['postfix']; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - if (isset($ocsRoute['root'])) { |
|
| 101 | - $root = $ocsRoute['root']; |
|
| 102 | - } else { |
|
| 103 | - $root = '/apps/'.$this->appName; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $url = $root . $ocsRoute['url']; |
|
| 107 | - $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
|
| 108 | - |
|
| 109 | - $split = explode('#', $name, 2); |
|
| 110 | - if (count($split) != 2) { |
|
| 111 | - throw new \UnexpectedValueException('Invalid route name'); |
|
| 112 | - } |
|
| 113 | - $controller = $split[0]; |
|
| 114 | - $action = $split[1]; |
|
| 115 | - |
|
| 116 | - $controllerName = $this->buildControllerName($controller); |
|
| 117 | - $actionName = $this->buildActionName($action); |
|
| 118 | - |
|
| 119 | - // register the route |
|
| 120 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
| 121 | - |
|
| 122 | - $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 123 | - ->method($verb) |
|
| 124 | - ->action($handler); |
|
| 125 | - |
|
| 126 | - // optionally register requirements for route. This is used to |
|
| 127 | - // tell the route parser how url parameters should be matched |
|
| 128 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
| 129 | - $router->requirements($ocsRoute['requirements']); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // optionally register defaults for route. This is used to |
|
| 133 | - // tell the route parser how url parameters should be default valued |
|
| 134 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
| 135 | - $router->defaults($ocsRoute['defaults']); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Creates one route base on the give configuration |
|
| 142 | - * @param array $routes |
|
| 143 | - * @throws \UnexpectedValueException |
|
| 144 | - */ |
|
| 145 | - private function processSimpleRoutes($routes) |
|
| 146 | - { |
|
| 147 | - $simpleRoutes = isset($routes['routes']) ? $routes['routes'] : array(); |
|
| 148 | - foreach ($simpleRoutes as $simpleRoute) { |
|
| 149 | - $name = $simpleRoute['name']; |
|
| 150 | - $postfix = ''; |
|
| 151 | - |
|
| 152 | - if (isset($simpleRoute['postfix'])) { |
|
| 153 | - $postfix = $simpleRoute['postfix']; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $url = $simpleRoute['url']; |
|
| 157 | - $verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET'; |
|
| 158 | - |
|
| 159 | - $split = explode('#', $name, 2); |
|
| 160 | - if (count($split) != 2) { |
|
| 161 | - throw new \UnexpectedValueException('Invalid route name'); |
|
| 162 | - } |
|
| 163 | - $controller = $split[0]; |
|
| 164 | - $action = $split[1]; |
|
| 165 | - |
|
| 166 | - $controllerName = $this->buildControllerName($controller); |
|
| 167 | - $actionName = $this->buildActionName($action); |
|
| 168 | - |
|
| 169 | - // register the route |
|
| 170 | - $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
| 171 | - $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 172 | - ->method($verb) |
|
| 173 | - ->action($handler); |
|
| 174 | - |
|
| 175 | - // optionally register requirements for route. This is used to |
|
| 176 | - // tell the route parser how url parameters should be matched |
|
| 177 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
| 178 | - $router->requirements($simpleRoute['requirements']); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // optionally register defaults for route. This is used to |
|
| 182 | - // tell the route parser how url parameters should be default valued |
|
| 183 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
| 184 | - $router->defaults($simpleRoute['defaults']); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * For a given name and url restful routes are created: |
|
| 191 | - * - index |
|
| 192 | - * - show |
|
| 193 | - * - new |
|
| 194 | - * - create |
|
| 195 | - * - update |
|
| 196 | - * - destroy |
|
| 197 | - * |
|
| 198 | - * @param array $routes |
|
| 199 | - */ |
|
| 200 | - private function processResources($routes) |
|
| 201 | - { |
|
| 202 | - // declaration of all restful actions |
|
| 203 | - $actions = array( |
|
| 204 | - array('name' => 'index', 'verb' => 'GET', 'on-collection' => true), |
|
| 205 | - array('name' => 'show', 'verb' => 'GET'), |
|
| 206 | - array('name' => 'create', 'verb' => 'POST', 'on-collection' => true), |
|
| 207 | - array('name' => 'update', 'verb' => 'PUT'), |
|
| 208 | - array('name' => 'destroy', 'verb' => 'DELETE'), |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - $resources = isset($routes['resources']) ? $routes['resources'] : array(); |
|
| 212 | - foreach ($resources as $resource => $config) { |
|
| 213 | - |
|
| 214 | - // the url parameter used as id to the resource |
|
| 215 | - foreach($actions as $action) { |
|
| 216 | - $url = $config['url']; |
|
| 217 | - $method = $action['name']; |
|
| 218 | - $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
|
| 219 | - $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
|
| 220 | - if (!$collectionAction) { |
|
| 221 | - $url = $url . '/{id}'; |
|
| 222 | - } |
|
| 223 | - if (isset($action['url-postfix'])) { |
|
| 224 | - $url = $url . '/' . $action['url-postfix']; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $controller = $resource; |
|
| 228 | - |
|
| 229 | - $controllerName = $this->buildControllerName($controller); |
|
| 230 | - $actionName = $this->buildActionName($method); |
|
| 231 | - |
|
| 232 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
| 233 | - |
|
| 234 | - $this->router->create($routeName, $url)->method($verb)->action( |
|
| 235 | - new RouteActionHandler($this->container, $controllerName, $actionName) |
|
| 236 | - ); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Based on a given route name the controller name is generated |
|
| 243 | - * @param string $controller |
|
| 244 | - * @return string |
|
| 245 | - */ |
|
| 246 | - private function buildControllerName($controller) |
|
| 247 | - { |
|
| 248 | - if (!isset($this->controllerNameCache[$controller])) { |
|
| 249 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
| 250 | - } |
|
| 251 | - return $this->controllerNameCache[$controller]; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Based on the action part of the route name the controller method name is generated |
|
| 256 | - * @param string $action |
|
| 257 | - * @return string |
|
| 258 | - */ |
|
| 259 | - private function buildActionName($action) { |
|
| 260 | - return $this->underScoreToCamelCase($action); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Underscored strings are converted to camel case strings |
|
| 265 | - * @param string $str |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - private function underScoreToCamelCase($str) { |
|
| 269 | - $pattern = "/_[a-z]?/"; |
|
| 270 | - return preg_replace_callback( |
|
| 271 | - $pattern, |
|
| 272 | - function ($matches) { |
|
| 273 | - return strtoupper(ltrim($matches[0], "_")); |
|
| 274 | - }, |
|
| 275 | - $str); |
|
| 276 | - } |
|
| 81 | + $oldCollection = $this->router->getCurrentCollection(); |
|
| 82 | + $this->router->useCollection($oldCollection.'.ocs'); |
|
| 83 | + |
|
| 84 | + // parse ocs simple routes |
|
| 85 | + $this->processOCS($this->routes); |
|
| 86 | + |
|
| 87 | + $this->router->useCollection($oldCollection); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + private function processOCS(array $routes) { |
|
| 91 | + $ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; |
|
| 92 | + foreach ($ocsRoutes as $ocsRoute) { |
|
| 93 | + $name = $ocsRoute['name']; |
|
| 94 | + $postfix = ''; |
|
| 95 | + |
|
| 96 | + if (isset($ocsRoute['postfix'])) { |
|
| 97 | + $postfix = $ocsRoute['postfix']; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + if (isset($ocsRoute['root'])) { |
|
| 101 | + $root = $ocsRoute['root']; |
|
| 102 | + } else { |
|
| 103 | + $root = '/apps/'.$this->appName; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $url = $root . $ocsRoute['url']; |
|
| 107 | + $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
|
| 108 | + |
|
| 109 | + $split = explode('#', $name, 2); |
|
| 110 | + if (count($split) != 2) { |
|
| 111 | + throw new \UnexpectedValueException('Invalid route name'); |
|
| 112 | + } |
|
| 113 | + $controller = $split[0]; |
|
| 114 | + $action = $split[1]; |
|
| 115 | + |
|
| 116 | + $controllerName = $this->buildControllerName($controller); |
|
| 117 | + $actionName = $this->buildActionName($action); |
|
| 118 | + |
|
| 119 | + // register the route |
|
| 120 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
| 121 | + |
|
| 122 | + $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 123 | + ->method($verb) |
|
| 124 | + ->action($handler); |
|
| 125 | + |
|
| 126 | + // optionally register requirements for route. This is used to |
|
| 127 | + // tell the route parser how url parameters should be matched |
|
| 128 | + if(array_key_exists('requirements', $ocsRoute)) { |
|
| 129 | + $router->requirements($ocsRoute['requirements']); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // optionally register defaults for route. This is used to |
|
| 133 | + // tell the route parser how url parameters should be default valued |
|
| 134 | + if(array_key_exists('defaults', $ocsRoute)) { |
|
| 135 | + $router->defaults($ocsRoute['defaults']); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Creates one route base on the give configuration |
|
| 142 | + * @param array $routes |
|
| 143 | + * @throws \UnexpectedValueException |
|
| 144 | + */ |
|
| 145 | + private function processSimpleRoutes($routes) |
|
| 146 | + { |
|
| 147 | + $simpleRoutes = isset($routes['routes']) ? $routes['routes'] : array(); |
|
| 148 | + foreach ($simpleRoutes as $simpleRoute) { |
|
| 149 | + $name = $simpleRoute['name']; |
|
| 150 | + $postfix = ''; |
|
| 151 | + |
|
| 152 | + if (isset($simpleRoute['postfix'])) { |
|
| 153 | + $postfix = $simpleRoute['postfix']; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $url = $simpleRoute['url']; |
|
| 157 | + $verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET'; |
|
| 158 | + |
|
| 159 | + $split = explode('#', $name, 2); |
|
| 160 | + if (count($split) != 2) { |
|
| 161 | + throw new \UnexpectedValueException('Invalid route name'); |
|
| 162 | + } |
|
| 163 | + $controller = $split[0]; |
|
| 164 | + $action = $split[1]; |
|
| 165 | + |
|
| 166 | + $controllerName = $this->buildControllerName($controller); |
|
| 167 | + $actionName = $this->buildActionName($action); |
|
| 168 | + |
|
| 169 | + // register the route |
|
| 170 | + $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
|
| 171 | + $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 172 | + ->method($verb) |
|
| 173 | + ->action($handler); |
|
| 174 | + |
|
| 175 | + // optionally register requirements for route. This is used to |
|
| 176 | + // tell the route parser how url parameters should be matched |
|
| 177 | + if(array_key_exists('requirements', $simpleRoute)) { |
|
| 178 | + $router->requirements($simpleRoute['requirements']); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // optionally register defaults for route. This is used to |
|
| 182 | + // tell the route parser how url parameters should be default valued |
|
| 183 | + if(array_key_exists('defaults', $simpleRoute)) { |
|
| 184 | + $router->defaults($simpleRoute['defaults']); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * For a given name and url restful routes are created: |
|
| 191 | + * - index |
|
| 192 | + * - show |
|
| 193 | + * - new |
|
| 194 | + * - create |
|
| 195 | + * - update |
|
| 196 | + * - destroy |
|
| 197 | + * |
|
| 198 | + * @param array $routes |
|
| 199 | + */ |
|
| 200 | + private function processResources($routes) |
|
| 201 | + { |
|
| 202 | + // declaration of all restful actions |
|
| 203 | + $actions = array( |
|
| 204 | + array('name' => 'index', 'verb' => 'GET', 'on-collection' => true), |
|
| 205 | + array('name' => 'show', 'verb' => 'GET'), |
|
| 206 | + array('name' => 'create', 'verb' => 'POST', 'on-collection' => true), |
|
| 207 | + array('name' => 'update', 'verb' => 'PUT'), |
|
| 208 | + array('name' => 'destroy', 'verb' => 'DELETE'), |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + $resources = isset($routes['resources']) ? $routes['resources'] : array(); |
|
| 212 | + foreach ($resources as $resource => $config) { |
|
| 213 | + |
|
| 214 | + // the url parameter used as id to the resource |
|
| 215 | + foreach($actions as $action) { |
|
| 216 | + $url = $config['url']; |
|
| 217 | + $method = $action['name']; |
|
| 218 | + $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
|
| 219 | + $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
|
| 220 | + if (!$collectionAction) { |
|
| 221 | + $url = $url . '/{id}'; |
|
| 222 | + } |
|
| 223 | + if (isset($action['url-postfix'])) { |
|
| 224 | + $url = $url . '/' . $action['url-postfix']; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $controller = $resource; |
|
| 228 | + |
|
| 229 | + $controllerName = $this->buildControllerName($controller); |
|
| 230 | + $actionName = $this->buildActionName($method); |
|
| 231 | + |
|
| 232 | + $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
| 233 | + |
|
| 234 | + $this->router->create($routeName, $url)->method($verb)->action( |
|
| 235 | + new RouteActionHandler($this->container, $controllerName, $actionName) |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Based on a given route name the controller name is generated |
|
| 243 | + * @param string $controller |
|
| 244 | + * @return string |
|
| 245 | + */ |
|
| 246 | + private function buildControllerName($controller) |
|
| 247 | + { |
|
| 248 | + if (!isset($this->controllerNameCache[$controller])) { |
|
| 249 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
| 250 | + } |
|
| 251 | + return $this->controllerNameCache[$controller]; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Based on the action part of the route name the controller method name is generated |
|
| 256 | + * @param string $action |
|
| 257 | + * @return string |
|
| 258 | + */ |
|
| 259 | + private function buildActionName($action) { |
|
| 260 | + return $this->underScoreToCamelCase($action); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Underscored strings are converted to camel case strings |
|
| 265 | + * @param string $str |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + private function underScoreToCamelCase($str) { |
|
| 269 | + $pattern = "/_[a-z]?/"; |
|
| 270 | + return preg_replace_callback( |
|
| 271 | + $pattern, |
|
| 272 | + function ($matches) { |
|
| 273 | + return strtoupper(ltrim($matches[0], "_")); |
|
| 274 | + }, |
|
| 275 | + $str); |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $root = '/apps/'.$this->appName; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $url = $root . $ocsRoute['url']; |
|
| 106 | + $url = $root.$ocsRoute['url']; |
|
| 107 | 107 | $verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
| 108 | 108 | |
| 109 | 109 | $split = explode('#', $name, 2); |
@@ -119,19 +119,19 @@ discard block |
||
| 119 | 119 | // register the route |
| 120 | 120 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
| 121 | 121 | |
| 122 | - $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 122 | + $router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action.$postfix, $url) |
|
| 123 | 123 | ->method($verb) |
| 124 | 124 | ->action($handler); |
| 125 | 125 | |
| 126 | 126 | // optionally register requirements for route. This is used to |
| 127 | 127 | // tell the route parser how url parameters should be matched |
| 128 | - if(array_key_exists('requirements', $ocsRoute)) { |
|
| 128 | + if (array_key_exists('requirements', $ocsRoute)) { |
|
| 129 | 129 | $router->requirements($ocsRoute['requirements']); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // optionally register defaults for route. This is used to |
| 133 | 133 | // tell the route parser how url parameters should be default valued |
| 134 | - if(array_key_exists('defaults', $ocsRoute)) { |
|
| 134 | + if (array_key_exists('defaults', $ocsRoute)) { |
|
| 135 | 135 | $router->defaults($ocsRoute['defaults']); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -168,19 +168,19 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // register the route |
| 170 | 170 | $handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
| 171 | - $router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
|
| 171 | + $router = $this->router->create($this->appName.'.'.$controller.'.'.$action.$postfix, $url) |
|
| 172 | 172 | ->method($verb) |
| 173 | 173 | ->action($handler); |
| 174 | 174 | |
| 175 | 175 | // optionally register requirements for route. This is used to |
| 176 | 176 | // tell the route parser how url parameters should be matched |
| 177 | - if(array_key_exists('requirements', $simpleRoute)) { |
|
| 177 | + if (array_key_exists('requirements', $simpleRoute)) { |
|
| 178 | 178 | $router->requirements($simpleRoute['requirements']); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // optionally register defaults for route. This is used to |
| 182 | 182 | // tell the route parser how url parameters should be default valued |
| 183 | - if(array_key_exists('defaults', $simpleRoute)) { |
|
| 183 | + if (array_key_exists('defaults', $simpleRoute)) { |
|
| 184 | 184 | $router->defaults($simpleRoute['defaults']); |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -212,16 +212,16 @@ discard block |
||
| 212 | 212 | foreach ($resources as $resource => $config) { |
| 213 | 213 | |
| 214 | 214 | // the url parameter used as id to the resource |
| 215 | - foreach($actions as $action) { |
|
| 215 | + foreach ($actions as $action) { |
|
| 216 | 216 | $url = $config['url']; |
| 217 | 217 | $method = $action['name']; |
| 218 | 218 | $verb = isset($action['verb']) ? strtoupper($action['verb']) : 'GET'; |
| 219 | 219 | $collectionAction = isset($action['on-collection']) ? $action['on-collection'] : false; |
| 220 | 220 | if (!$collectionAction) { |
| 221 | - $url = $url . '/{id}'; |
|
| 221 | + $url = $url.'/{id}'; |
|
| 222 | 222 | } |
| 223 | 223 | if (isset($action['url-postfix'])) { |
| 224 | - $url = $url . '/' . $action['url-postfix']; |
|
| 224 | + $url = $url.'/'.$action['url-postfix']; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $controller = $resource; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | $controllerName = $this->buildControllerName($controller); |
| 230 | 230 | $actionName = $this->buildActionName($method); |
| 231 | 231 | |
| 232 | - $routeName = $this->appName . '.' . strtolower($resource) . '.' . strtolower($method); |
|
| 232 | + $routeName = $this->appName.'.'.strtolower($resource).'.'.strtolower($method); |
|
| 233 | 233 | |
| 234 | 234 | $this->router->create($routeName, $url)->method($verb)->action( |
| 235 | 235 | new RouteActionHandler($this->container, $controllerName, $actionName) |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | private function buildControllerName($controller) |
| 247 | 247 | { |
| 248 | 248 | if (!isset($this->controllerNameCache[$controller])) { |
| 249 | - $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)) . 'Controller'; |
|
| 249 | + $this->controllerNameCache[$controller] = $this->underScoreToCamelCase(ucfirst($controller)).'Controller'; |
|
| 250 | 250 | } |
| 251 | 251 | return $this->controllerNameCache[$controller]; |
| 252 | 252 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | $pattern = "/_[a-z]?/"; |
| 270 | 270 | return preg_replace_callback( |
| 271 | 271 | $pattern, |
| 272 | - function ($matches) { |
|
| 272 | + function($matches) { |
|
| 273 | 273 | return strtoupper(ltrim($matches[0], "_")); |
| 274 | 274 | }, |
| 275 | 275 | $str); |
@@ -29,21 +29,21 @@ |
||
| 29 | 29 | use \OC\AppFramework\DependencyInjection\DIContainer; |
| 30 | 30 | |
| 31 | 31 | class RouteActionHandler { |
| 32 | - private $controllerName; |
|
| 33 | - private $actionName; |
|
| 34 | - private $container; |
|
| 32 | + private $controllerName; |
|
| 33 | + private $actionName; |
|
| 34 | + private $container; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $controllerName |
|
| 38 | - * @param string $actionName |
|
| 39 | - */ |
|
| 40 | - public function __construct(DIContainer $container, $controllerName, $actionName) { |
|
| 41 | - $this->controllerName = $controllerName; |
|
| 42 | - $this->actionName = $actionName; |
|
| 43 | - $this->container = $container; |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $controllerName |
|
| 38 | + * @param string $actionName |
|
| 39 | + */ |
|
| 40 | + public function __construct(DIContainer $container, $controllerName, $actionName) { |
|
| 41 | + $this->controllerName = $controllerName; |
|
| 42 | + $this->actionName = $actionName; |
|
| 43 | + $this->container = $container; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function __invoke($params) { |
|
| 47 | - App::main($this->controllerName, $this->actionName, $this->container, $params); |
|
| 48 | - } |
|
| 46 | + public function __invoke($params) { |
|
| 47 | + App::main($this->controllerName, $this->actionName, $this->container, $params); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -33,263 +33,263 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Helper extends \OC\Share\Constants { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Generate a unique target for the item |
|
| 38 | - * @param string $itemType |
|
| 39 | - * @param string $itemSource |
|
| 40 | - * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK |
|
| 41 | - * @param string $shareWith User or group the item is being shared with |
|
| 42 | - * @param string $uidOwner User that is the owner of shared item |
|
| 43 | - * @param string $suggestedTarget The suggested target originating from a reshare (optional) |
|
| 44 | - * @param int $groupParent The id of the parent group share (optional) |
|
| 45 | - * @throws \Exception |
|
| 46 | - * @return string Item target |
|
| 47 | - */ |
|
| 48 | - public static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) { |
|
| 49 | - // FIXME: $uidOwner and $groupParent seems to be unused |
|
| 50 | - $backend = \OC\Share\Share::getBackend($itemType); |
|
| 51 | - if ($shareType === self::SHARE_TYPE_LINK || $shareType === self::SHARE_TYPE_REMOTE) { |
|
| 52 | - if (isset($suggestedTarget)) { |
|
| 53 | - return $suggestedTarget; |
|
| 54 | - } |
|
| 55 | - return $backend->generateTarget($itemSource, false); |
|
| 56 | - } else { |
|
| 57 | - if ($shareType == self::SHARE_TYPE_USER) { |
|
| 58 | - // Share with is a user, so set share type to user and groups |
|
| 59 | - $shareType = self::$shareTypeUserAndGroups; |
|
| 60 | - } |
|
| 36 | + /** |
|
| 37 | + * Generate a unique target for the item |
|
| 38 | + * @param string $itemType |
|
| 39 | + * @param string $itemSource |
|
| 40 | + * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK |
|
| 41 | + * @param string $shareWith User or group the item is being shared with |
|
| 42 | + * @param string $uidOwner User that is the owner of shared item |
|
| 43 | + * @param string $suggestedTarget The suggested target originating from a reshare (optional) |
|
| 44 | + * @param int $groupParent The id of the parent group share (optional) |
|
| 45 | + * @throws \Exception |
|
| 46 | + * @return string Item target |
|
| 47 | + */ |
|
| 48 | + public static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) { |
|
| 49 | + // FIXME: $uidOwner and $groupParent seems to be unused |
|
| 50 | + $backend = \OC\Share\Share::getBackend($itemType); |
|
| 51 | + if ($shareType === self::SHARE_TYPE_LINK || $shareType === self::SHARE_TYPE_REMOTE) { |
|
| 52 | + if (isset($suggestedTarget)) { |
|
| 53 | + return $suggestedTarget; |
|
| 54 | + } |
|
| 55 | + return $backend->generateTarget($itemSource, false); |
|
| 56 | + } else { |
|
| 57 | + if ($shareType == self::SHARE_TYPE_USER) { |
|
| 58 | + // Share with is a user, so set share type to user and groups |
|
| 59 | + $shareType = self::$shareTypeUserAndGroups; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - // Check if suggested target exists first |
|
| 63 | - if (!isset($suggestedTarget)) { |
|
| 64 | - $suggestedTarget = $itemSource; |
|
| 65 | - } |
|
| 66 | - if ($shareType == self::SHARE_TYPE_GROUP) { |
|
| 67 | - $target = $backend->generateTarget($suggestedTarget, false); |
|
| 68 | - } else { |
|
| 69 | - $target = $backend->generateTarget($suggestedTarget, $shareWith); |
|
| 70 | - } |
|
| 62 | + // Check if suggested target exists first |
|
| 63 | + if (!isset($suggestedTarget)) { |
|
| 64 | + $suggestedTarget = $itemSource; |
|
| 65 | + } |
|
| 66 | + if ($shareType == self::SHARE_TYPE_GROUP) { |
|
| 67 | + $target = $backend->generateTarget($suggestedTarget, false); |
|
| 68 | + } else { |
|
| 69 | + $target = $backend->generateTarget($suggestedTarget, $shareWith); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $target; |
|
| 73 | - } |
|
| 74 | - } |
|
| 72 | + return $target; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Delete all reshares and group share children of an item |
|
| 78 | - * @param int $parent Id of item to delete |
|
| 79 | - * @param bool $excludeParent If true, exclude the parent from the delete (optional) |
|
| 80 | - * @param string $uidOwner The user that the parent was shared with (optional) |
|
| 81 | - * @param int $newParent new parent for the childrens |
|
| 82 | - * @param bool $excludeGroupChildren exclude group children elements |
|
| 83 | - */ |
|
| 84 | - public static function delete($parent, $excludeParent = false, $uidOwner = null, $newParent = null, $excludeGroupChildren = false) { |
|
| 85 | - $ids = array($parent); |
|
| 86 | - $deletedItems = array(); |
|
| 87 | - $changeParent = array(); |
|
| 88 | - $parents = array($parent); |
|
| 89 | - while (!empty($parents)) { |
|
| 90 | - $parents = "'".implode("','", $parents)."'"; |
|
| 91 | - // Check the owner on the first search of reshares, useful for |
|
| 92 | - // finding and deleting the reshares by a single user of a group share |
|
| 93 | - $params = array(); |
|
| 94 | - if (count($ids) == 1 && isset($uidOwner)) { |
|
| 95 | - // FIXME: don't concat $parents, use Docrine's PARAM_INT_ARRAY approach |
|
| 96 | - $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 97 | - '`item_target`, `file_target`, `parent` ' . |
|
| 98 | - 'FROM `*PREFIX*share` ' . |
|
| 99 | - 'WHERE `parent` IN ('.$parents.') AND `uid_owner` = ? '; |
|
| 100 | - $params[] = $uidOwner; |
|
| 101 | - } else { |
|
| 102 | - $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 103 | - '`item_target`, `file_target`, `parent`, `uid_owner` ' . |
|
| 104 | - 'FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') '; |
|
| 105 | - } |
|
| 106 | - if ($excludeGroupChildren) { |
|
| 107 | - $queryString .= ' AND `share_type` != ?'; |
|
| 108 | - $params[] = self::$shareTypeGroupUserUnique; |
|
| 109 | - } |
|
| 110 | - $query = \OC_DB::prepare($queryString); |
|
| 111 | - $result = $query->execute($params); |
|
| 112 | - // Reset parents array, only go through loop again if items are found |
|
| 113 | - $parents = array(); |
|
| 114 | - while ($item = $result->fetchRow()) { |
|
| 115 | - $tmpItem = array( |
|
| 116 | - 'id' => $item['id'], |
|
| 117 | - 'shareWith' => $item['share_with'], |
|
| 118 | - 'itemTarget' => $item['item_target'], |
|
| 119 | - 'itemType' => $item['item_type'], |
|
| 120 | - 'shareType' => (int)$item['share_type'], |
|
| 121 | - ); |
|
| 122 | - if (isset($item['file_target'])) { |
|
| 123 | - $tmpItem['fileTarget'] = $item['file_target']; |
|
| 124 | - } |
|
| 125 | - // if we have a new parent for the child we remember the child |
|
| 126 | - // to update the parent, if not we add it to the list of items |
|
| 127 | - // which should be deleted |
|
| 128 | - if ($newParent !== null) { |
|
| 129 | - $changeParent[] = $item['id']; |
|
| 130 | - } else { |
|
| 131 | - $deletedItems[] = $tmpItem; |
|
| 132 | - $ids[] = $item['id']; |
|
| 133 | - $parents[] = $item['id']; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if ($excludeParent) { |
|
| 138 | - unset($ids[0]); |
|
| 139 | - } |
|
| 76 | + /** |
|
| 77 | + * Delete all reshares and group share children of an item |
|
| 78 | + * @param int $parent Id of item to delete |
|
| 79 | + * @param bool $excludeParent If true, exclude the parent from the delete (optional) |
|
| 80 | + * @param string $uidOwner The user that the parent was shared with (optional) |
|
| 81 | + * @param int $newParent new parent for the childrens |
|
| 82 | + * @param bool $excludeGroupChildren exclude group children elements |
|
| 83 | + */ |
|
| 84 | + public static function delete($parent, $excludeParent = false, $uidOwner = null, $newParent = null, $excludeGroupChildren = false) { |
|
| 85 | + $ids = array($parent); |
|
| 86 | + $deletedItems = array(); |
|
| 87 | + $changeParent = array(); |
|
| 88 | + $parents = array($parent); |
|
| 89 | + while (!empty($parents)) { |
|
| 90 | + $parents = "'".implode("','", $parents)."'"; |
|
| 91 | + // Check the owner on the first search of reshares, useful for |
|
| 92 | + // finding and deleting the reshares by a single user of a group share |
|
| 93 | + $params = array(); |
|
| 94 | + if (count($ids) == 1 && isset($uidOwner)) { |
|
| 95 | + // FIXME: don't concat $parents, use Docrine's PARAM_INT_ARRAY approach |
|
| 96 | + $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 97 | + '`item_target`, `file_target`, `parent` ' . |
|
| 98 | + 'FROM `*PREFIX*share` ' . |
|
| 99 | + 'WHERE `parent` IN ('.$parents.') AND `uid_owner` = ? '; |
|
| 100 | + $params[] = $uidOwner; |
|
| 101 | + } else { |
|
| 102 | + $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 103 | + '`item_target`, `file_target`, `parent`, `uid_owner` ' . |
|
| 104 | + 'FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') '; |
|
| 105 | + } |
|
| 106 | + if ($excludeGroupChildren) { |
|
| 107 | + $queryString .= ' AND `share_type` != ?'; |
|
| 108 | + $params[] = self::$shareTypeGroupUserUnique; |
|
| 109 | + } |
|
| 110 | + $query = \OC_DB::prepare($queryString); |
|
| 111 | + $result = $query->execute($params); |
|
| 112 | + // Reset parents array, only go through loop again if items are found |
|
| 113 | + $parents = array(); |
|
| 114 | + while ($item = $result->fetchRow()) { |
|
| 115 | + $tmpItem = array( |
|
| 116 | + 'id' => $item['id'], |
|
| 117 | + 'shareWith' => $item['share_with'], |
|
| 118 | + 'itemTarget' => $item['item_target'], |
|
| 119 | + 'itemType' => $item['item_type'], |
|
| 120 | + 'shareType' => (int)$item['share_type'], |
|
| 121 | + ); |
|
| 122 | + if (isset($item['file_target'])) { |
|
| 123 | + $tmpItem['fileTarget'] = $item['file_target']; |
|
| 124 | + } |
|
| 125 | + // if we have a new parent for the child we remember the child |
|
| 126 | + // to update the parent, if not we add it to the list of items |
|
| 127 | + // which should be deleted |
|
| 128 | + if ($newParent !== null) { |
|
| 129 | + $changeParent[] = $item['id']; |
|
| 130 | + } else { |
|
| 131 | + $deletedItems[] = $tmpItem; |
|
| 132 | + $ids[] = $item['id']; |
|
| 133 | + $parents[] = $item['id']; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if ($excludeParent) { |
|
| 138 | + unset($ids[0]); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - if (!empty($changeParent)) { |
|
| 142 | - $idList = "'".implode("','", $changeParent)."'"; |
|
| 143 | - $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `parent` = ? WHERE `id` IN ('.$idList.')'); |
|
| 144 | - $query->execute(array($newParent)); |
|
| 145 | - } |
|
| 141 | + if (!empty($changeParent)) { |
|
| 142 | + $idList = "'".implode("','", $changeParent)."'"; |
|
| 143 | + $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `parent` = ? WHERE `id` IN ('.$idList.')'); |
|
| 144 | + $query->execute(array($newParent)); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - if (!empty($ids)) { |
|
| 148 | - $idList = "'".implode("','", $ids)."'"; |
|
| 149 | - $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` IN ('.$idList.')'); |
|
| 150 | - $query->execute(); |
|
| 151 | - } |
|
| 147 | + if (!empty($ids)) { |
|
| 148 | + $idList = "'".implode("','", $ids)."'"; |
|
| 149 | + $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` IN ('.$idList.')'); |
|
| 150 | + $query->execute(); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $deletedItems; |
|
| 154 | - } |
|
| 153 | + return $deletedItems; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * get default expire settings defined by the admin |
|
| 158 | - * @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
| 159 | - */ |
|
| 160 | - public static function getDefaultExpireSetting() { |
|
| 156 | + /** |
|
| 157 | + * get default expire settings defined by the admin |
|
| 158 | + * @return array contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
| 159 | + */ |
|
| 160 | + public static function getDefaultExpireSetting() { |
|
| 161 | 161 | |
| 162 | - $config = \OC::$server->getConfig(); |
|
| 162 | + $config = \OC::$server->getConfig(); |
|
| 163 | 163 | |
| 164 | - $defaultExpireSettings = array('defaultExpireDateSet' => false); |
|
| 164 | + $defaultExpireSettings = array('defaultExpireDateSet' => false); |
|
| 165 | 165 | |
| 166 | - // get default expire settings |
|
| 167 | - $defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 168 | - if ($defaultExpireDate === 'yes') { |
|
| 169 | - $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 170 | - $defaultExpireSettings['defaultExpireDateSet'] = true; |
|
| 171 | - $defaultExpireSettings['expireAfterDays'] = (int)($config->getAppValue('core', 'shareapi_expire_after_n_days', '7')); |
|
| 172 | - $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes' ? true : false; |
|
| 173 | - } |
|
| 166 | + // get default expire settings |
|
| 167 | + $defaultExpireDate = $config->getAppValue('core', 'shareapi_default_expire_date', 'no'); |
|
| 168 | + if ($defaultExpireDate === 'yes') { |
|
| 169 | + $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
|
| 170 | + $defaultExpireSettings['defaultExpireDateSet'] = true; |
|
| 171 | + $defaultExpireSettings['expireAfterDays'] = (int)($config->getAppValue('core', 'shareapi_expire_after_n_days', '7')); |
|
| 172 | + $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes' ? true : false; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - return $defaultExpireSettings; |
|
| 176 | - } |
|
| 175 | + return $defaultExpireSettings; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - public static function calcExpireDate() { |
|
| 179 | - $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; |
|
| 180 | - $expireAt = time() + $expireAfter; |
|
| 181 | - $date = new \DateTime(); |
|
| 182 | - $date->setTimestamp($expireAt); |
|
| 183 | - $date->setTime(0, 0, 0); |
|
| 184 | - //$dateString = $date->format('Y-m-d') . ' 00:00:00'; |
|
| 178 | + public static function calcExpireDate() { |
|
| 179 | + $expireAfter = \OC\Share\Share::getExpireInterval() * 24 * 60 * 60; |
|
| 180 | + $expireAt = time() + $expireAfter; |
|
| 181 | + $date = new \DateTime(); |
|
| 182 | + $date->setTimestamp($expireAt); |
|
| 183 | + $date->setTime(0, 0, 0); |
|
| 184 | + //$dateString = $date->format('Y-m-d') . ' 00:00:00'; |
|
| 185 | 185 | |
| 186 | - return $date; |
|
| 186 | + return $date; |
|
| 187 | 187 | |
| 188 | - } |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * calculate expire date |
|
| 192 | - * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
| 193 | - * @param int $creationTime timestamp when the share was created |
|
| 194 | - * @param int $userExpireDate expire timestamp set by the user |
|
| 195 | - * @return mixed integer timestamp or False |
|
| 196 | - */ |
|
| 197 | - public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) { |
|
| 190 | + /** |
|
| 191 | + * calculate expire date |
|
| 192 | + * @param array $defaultExpireSettings contains 'defaultExpireDateSet', 'enforceExpireDate', 'expireAfterDays' |
|
| 193 | + * @param int $creationTime timestamp when the share was created |
|
| 194 | + * @param int $userExpireDate expire timestamp set by the user |
|
| 195 | + * @return mixed integer timestamp or False |
|
| 196 | + */ |
|
| 197 | + public static function calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate = null) { |
|
| 198 | 198 | |
| 199 | - $expires = false; |
|
| 200 | - $defaultExpires = null; |
|
| 199 | + $expires = false; |
|
| 200 | + $defaultExpires = null; |
|
| 201 | 201 | |
| 202 | - if (!empty($defaultExpireSettings['defaultExpireDateSet'])) { |
|
| 203 | - $defaultExpires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400; |
|
| 204 | - } |
|
| 202 | + if (!empty($defaultExpireSettings['defaultExpireDateSet'])) { |
|
| 203 | + $defaultExpires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | 206 | |
| 207 | - if (isset($userExpireDate)) { |
|
| 208 | - // if the admin decided to enforce the default expire date then we only take |
|
| 209 | - // the user defined expire date of it is before the default expire date |
|
| 210 | - if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
| 211 | - $expires = min($userExpireDate, $defaultExpires); |
|
| 212 | - } else { |
|
| 213 | - $expires = $userExpireDate; |
|
| 214 | - } |
|
| 215 | - } else if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
| 216 | - $expires = $defaultExpires; |
|
| 217 | - } |
|
| 207 | + if (isset($userExpireDate)) { |
|
| 208 | + // if the admin decided to enforce the default expire date then we only take |
|
| 209 | + // the user defined expire date of it is before the default expire date |
|
| 210 | + if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
| 211 | + $expires = min($userExpireDate, $defaultExpires); |
|
| 212 | + } else { |
|
| 213 | + $expires = $userExpireDate; |
|
| 214 | + } |
|
| 215 | + } else if ($defaultExpires && !empty($defaultExpireSettings['enforceExpireDate'])) { |
|
| 216 | + $expires = $defaultExpires; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $expires; |
|
| 220 | - } |
|
| 219 | + return $expires; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Strips away a potential file names and trailing slashes: |
|
| 224 | - * - http://localhost |
|
| 225 | - * - http://localhost/ |
|
| 226 | - * - http://localhost/index.php |
|
| 227 | - * - http://localhost/index.php/s/{shareToken} |
|
| 228 | - * |
|
| 229 | - * all return: http://localhost |
|
| 230 | - * |
|
| 231 | - * @param string $remote |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - protected static function fixRemoteURL($remote) { |
|
| 235 | - $remote = str_replace('\\', '/', $remote); |
|
| 236 | - if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
| 237 | - $remote = substr($remote, 0, $fileNamePosition); |
|
| 238 | - } |
|
| 239 | - $remote = rtrim($remote, '/'); |
|
| 222 | + /** |
|
| 223 | + * Strips away a potential file names and trailing slashes: |
|
| 224 | + * - http://localhost |
|
| 225 | + * - http://localhost/ |
|
| 226 | + * - http://localhost/index.php |
|
| 227 | + * - http://localhost/index.php/s/{shareToken} |
|
| 228 | + * |
|
| 229 | + * all return: http://localhost |
|
| 230 | + * |
|
| 231 | + * @param string $remote |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + protected static function fixRemoteURL($remote) { |
|
| 235 | + $remote = str_replace('\\', '/', $remote); |
|
| 236 | + if ($fileNamePosition = strpos($remote, '/index.php')) { |
|
| 237 | + $remote = substr($remote, 0, $fileNamePosition); |
|
| 238 | + } |
|
| 239 | + $remote = rtrim($remote, '/'); |
|
| 240 | 240 | |
| 241 | - return $remote; |
|
| 242 | - } |
|
| 241 | + return $remote; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * split user and remote from federated cloud id |
|
| 246 | - * |
|
| 247 | - * @param string $id |
|
| 248 | - * @return string[] |
|
| 249 | - * @throws HintException |
|
| 250 | - */ |
|
| 251 | - public static function splitUserRemote($id) { |
|
| 252 | - try { |
|
| 253 | - $cloudId = \OC::$server->getCloudIdManager()->resolveCloudId($id); |
|
| 254 | - return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
| 255 | - } catch (\InvalidArgumentException $e) { |
|
| 256 | - $l = \OC::$server->getL10N('core'); |
|
| 257 | - $hint = $l->t('Invalid Federated Cloud ID'); |
|
| 258 | - throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
| 259 | - } |
|
| 260 | - } |
|
| 244 | + /** |
|
| 245 | + * split user and remote from federated cloud id |
|
| 246 | + * |
|
| 247 | + * @param string $id |
|
| 248 | + * @return string[] |
|
| 249 | + * @throws HintException |
|
| 250 | + */ |
|
| 251 | + public static function splitUserRemote($id) { |
|
| 252 | + try { |
|
| 253 | + $cloudId = \OC::$server->getCloudIdManager()->resolveCloudId($id); |
|
| 254 | + return [$cloudId->getUser(), $cloudId->getRemote()]; |
|
| 255 | + } catch (\InvalidArgumentException $e) { |
|
| 256 | + $l = \OC::$server->getL10N('core'); |
|
| 257 | + $hint = $l->t('Invalid Federated Cloud ID'); |
|
| 258 | + throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * check if two federated cloud IDs refer to the same user |
|
| 264 | - * |
|
| 265 | - * @param string $user1 |
|
| 266 | - * @param string $server1 |
|
| 267 | - * @param string $user2 |
|
| 268 | - * @param string $server2 |
|
| 269 | - * @return bool true if both users and servers are the same |
|
| 270 | - */ |
|
| 271 | - public static function isSameUserOnSameServer($user1, $server1, $user2, $server2) { |
|
| 272 | - $normalizedServer1 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server1)); |
|
| 273 | - $normalizedServer2 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server2)); |
|
| 262 | + /** |
|
| 263 | + * check if two federated cloud IDs refer to the same user |
|
| 264 | + * |
|
| 265 | + * @param string $user1 |
|
| 266 | + * @param string $server1 |
|
| 267 | + * @param string $user2 |
|
| 268 | + * @param string $server2 |
|
| 269 | + * @return bool true if both users and servers are the same |
|
| 270 | + */ |
|
| 271 | + public static function isSameUserOnSameServer($user1, $server1, $user2, $server2) { |
|
| 272 | + $normalizedServer1 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server1)); |
|
| 273 | + $normalizedServer2 = strtolower(\OC\Share\Share::removeProtocolFromUrl($server2)); |
|
| 274 | 274 | |
| 275 | - if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
| 276 | - // FIXME this should be a method in the user management instead |
|
| 277 | - \OCP\Util::emitHook( |
|
| 278 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 279 | - 'preLoginNameUsedAsUserName', |
|
| 280 | - array('uid' => &$user1) |
|
| 281 | - ); |
|
| 282 | - \OCP\Util::emitHook( |
|
| 283 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 284 | - 'preLoginNameUsedAsUserName', |
|
| 285 | - array('uid' => &$user2) |
|
| 286 | - ); |
|
| 275 | + if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) { |
|
| 276 | + // FIXME this should be a method in the user management instead |
|
| 277 | + \OCP\Util::emitHook( |
|
| 278 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 279 | + 'preLoginNameUsedAsUserName', |
|
| 280 | + array('uid' => &$user1) |
|
| 281 | + ); |
|
| 282 | + \OCP\Util::emitHook( |
|
| 283 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 284 | + 'preLoginNameUsedAsUserName', |
|
| 285 | + array('uid' => &$user2) |
|
| 286 | + ); |
|
| 287 | 287 | |
| 288 | - if ($user1 === $user2) { |
|
| 289 | - return true; |
|
| 290 | - } |
|
| 291 | - } |
|
| 288 | + if ($user1 === $user2) { |
|
| 289 | + return true; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return false; |
|
| 294 | - } |
|
| 293 | + return false; |
|
| 294 | + } |
|
| 295 | 295 | } |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | $params = array(); |
| 94 | 94 | if (count($ids) == 1 && isset($uidOwner)) { |
| 95 | 95 | // FIXME: don't concat $parents, use Docrine's PARAM_INT_ARRAY approach |
| 96 | - $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 97 | - '`item_target`, `file_target`, `parent` ' . |
|
| 98 | - 'FROM `*PREFIX*share` ' . |
|
| 96 | + $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, '. |
|
| 97 | + '`item_target`, `file_target`, `parent` '. |
|
| 98 | + 'FROM `*PREFIX*share` '. |
|
| 99 | 99 | 'WHERE `parent` IN ('.$parents.') AND `uid_owner` = ? '; |
| 100 | 100 | $params[] = $uidOwner; |
| 101 | 101 | } else { |
| 102 | - $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' . |
|
| 103 | - '`item_target`, `file_target`, `parent`, `uid_owner` ' . |
|
| 102 | + $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, '. |
|
| 103 | + '`item_target`, `file_target`, `parent`, `uid_owner` '. |
|
| 104 | 104 | 'FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') '; |
| 105 | 105 | } |
| 106 | 106 | if ($excludeGroupChildren) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | 'shareWith' => $item['share_with'], |
| 118 | 118 | 'itemTarget' => $item['item_target'], |
| 119 | 119 | 'itemType' => $item['item_type'], |
| 120 | - 'shareType' => (int)$item['share_type'], |
|
| 120 | + 'shareType' => (int) $item['share_type'], |
|
| 121 | 121 | ); |
| 122 | 122 | if (isset($item['file_target'])) { |
| 123 | 123 | $tmpItem['fileTarget'] = $item['file_target']; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | if ($defaultExpireDate === 'yes') { |
| 169 | 169 | $enforceExpireDate = $config->getAppValue('core', 'shareapi_enforce_expire_date', 'no'); |
| 170 | 170 | $defaultExpireSettings['defaultExpireDateSet'] = true; |
| 171 | - $defaultExpireSettings['expireAfterDays'] = (int)($config->getAppValue('core', 'shareapi_expire_after_n_days', '7')); |
|
| 171 | + $defaultExpireSettings['expireAfterDays'] = (int) ($config->getAppValue('core', 'shareapi_expire_after_n_days', '7')); |
|
| 172 | 172 | $defaultExpireSettings['enforceExpireDate'] = $enforceExpireDate === 'yes' ? true : false; |
| 173 | 173 | } |
| 174 | 174 | |