浏览代码

Merge pull request #5948 from nextcloud/remove-explicit-declaration

Remove explicit type hints for Controller
tags/v13.0.0beta1
Morris Jobke 7 年前
父节点
当前提交
3f0f18b4c4

+ 1
- 1
apps/federation/lib/Middleware/AddServerMiddleware.php 查看文件

* @return JSONResponse * @return JSONResponse
* @throws \Exception * @throws \Exception
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if (($controller instanceof SettingsController) === false) { if (($controller instanceof SettingsController) === false) {
throw $exception; throw $exception;
} }

+ 2
- 2
apps/files_sharing/lib/Middleware/OCSShareAPIMiddleware.php 查看文件

* *
* @throws OCSNotFoundException * @throws OCSNotFoundException
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if ($controller instanceof ShareAPIController) { if ($controller instanceof ShareAPIController) {
if (!$this->shareManager->shareApiEnabled()) { if (!$this->shareManager->shareApiEnabled()) {
throw new OCSNotFoundException($this->l->t('Share API is disabled')); throw new OCSNotFoundException($this->l->t('Share API is disabled'));
* @param Response $response * @param Response $response
* @return Response * @return Response
*/ */
public function afterController(Controller $controller, $methodName, Response $response) {
public function afterController($controller, $methodName, Response $response) {
if ($controller instanceof ShareAPIController) { if ($controller instanceof ShareAPIController) {
/** @var ShareAPIController $controller */ /** @var ShareAPIController $controller */
$controller->cleanup(); $controller->cleanup();

+ 2
- 2
apps/files_sharing/lib/Middleware/SharingCheckMiddleware.php 查看文件

* @throws S2SException * @throws S2SException
* @throws ShareNotFound * @throws ShareNotFound
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if(!$this->isSharingEnabled()) { if(!$this->isSharingEnabled()) {
throw new NotFoundException('Sharing is disabled.'); throw new NotFoundException('Sharing is disabled.');
} }
* @return NotFoundResponse * @return NotFoundResponse
* @throws \Exception * @throws \Exception
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if(is_a($exception, '\OCP\Files\NotFoundException')) { if(is_a($exception, '\OCP\Files\NotFoundException')) {
return new NotFoundResponse(); return new NotFoundResponse();
} }

+ 2
- 2
apps/provisioning_api/lib/Middleware/ProvisioningApiMiddleware.php 查看文件

* *
* @throws NotSubAdminException * @throws NotSubAdminException
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) { if (!$this->isAdmin && !$this->reflector->hasAnnotation('NoSubAdminRequired') && !$this->isSubAdmin) {
throw new NotSubAdminException(); throw new NotSubAdminException();
} }
* @throws \Exception * @throws \Exception
* @return Response * @return Response
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if ($exception instanceof NotSubAdminException) { if ($exception instanceof NotSubAdminException) {
throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED); throw new OCSException($exception->getMessage(), \OCP\API::RESPOND_UNAUTHORISED);
} }

+ 2
- 2
core/Middleware/TwoFactorMiddleware.php 查看文件

* @param Controller $controller * @param Controller $controller
* @param string $methodName * @param string $methodName
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if ($this->reflector->hasAnnotation('PublicPage')) { if ($this->reflector->hasAnnotation('PublicPage')) {
// Don't block public pages // Don't block public pages
return; return;
} }
} }


public function afterException(Controller $controller, $methodName, Exception $exception) {
public function afterException($controller, $methodName, Exception $exception) {
if ($exception instanceof TwoFactorAuthRequiredException) { if ($exception instanceof TwoFactorAuthRequiredException) {
$params = []; $params = [];
if (isset($this->request->server['REQUEST_URI'])) { if (isset($this->request->server['REQUEST_URI'])) {

+ 3
- 3
lib/private/AppFramework/Middleware/OCSMiddleware.php 查看文件

* @param Controller $controller * @param Controller $controller
* @param string $methodName * @param string $methodName
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if ($controller instanceof OCSController) { if ($controller instanceof OCSController) {
if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) {
$this->ocsVersion = 2; $this->ocsVersion = 2;
* @throws \Exception * @throws \Exception
* @return BaseResponse * @return BaseResponse
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if ($controller instanceof OCSController && $exception instanceof OCSException) { if ($controller instanceof OCSController && $exception instanceof OCSException) {
$code = $exception->getCode(); $code = $exception->getCode();
if ($code === 0) { if ($code === 0) {
* @param Response $response * @param Response $response
* @return \OCP\AppFramework\Http\Response * @return \OCP\AppFramework\Http\Response
*/ */
public function afterController(Controller $controller, $methodName, Response $response) {
public function afterController($controller, $methodName, Response $response) {
/* /*
* If a different middleware has detected that a request unauthorized or forbidden * If a different middleware has detected that a request unauthorized or forbidden
* we need to catch the response and convert it to a proper OCS response. * we need to catch the response and convert it to a proper OCS response.

+ 2
- 2
lib/private/AppFramework/Middleware/Security/BruteForceMiddleware.php 查看文件

/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
parent::beforeController($controller, $methodName); parent::beforeController($controller, $methodName);


if($this->reflector->hasAnnotation('BruteForceProtection')) { if($this->reflector->hasAnnotation('BruteForceProtection')) {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function afterController(Controller $controller, $methodName, Response $response) {
public function afterController($controller, $methodName, Response $response) {
if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) { if($this->reflector->hasAnnotation('BruteForceProtection') && $response->isThrottled()) {
$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action'); $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
$ip = $this->request->getRemoteAddress(); $ip = $this->request->getRemoteAddress();

+ 3
- 3
lib/private/AppFramework/Middleware/Security/CORSMiddleware.php 查看文件

* @throws SecurityException * @throws SecurityException
* @since 6.0.0 * @since 6.0.0
*/ */
public function beforeController(Controller $controller, $methodName){
public function beforeController($controller, $methodName){
// ensure that @CORS annotated API routes are not used in conjunction // ensure that @CORS annotated API routes are not used in conjunction
// with session authentication since this enables CSRF attack vectors // with session authentication since this enables CSRF attack vectors
if ($this->reflector->hasAnnotation('CORS') && if ($this->reflector->hasAnnotation('CORS') &&
* @return Response a Response object * @return Response a Response object
* @throws SecurityException * @throws SecurityException
*/ */
public function afterController(Controller $controller, $methodName, Response $response){
public function afterController($controller, $methodName, Response $response){
// only react if its a CORS request and if the request sends origin and // only react if its a CORS request and if the request sends origin and


if(isset($this->request->server['HTTP_ORIGIN']) && if(isset($this->request->server['HTTP_ORIGIN']) &&
* @throws \Exception the passed in exception if it can't handle it * @throws \Exception the passed in exception if it can't handle it
* @return Response a Response object or null in case that the exception could not be handled * @return Response a Response object or null in case that the exception could not be handled
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception){
public function afterException($controller, $methodName, \Exception $exception){
if($exception instanceof SecurityException){ if($exception instanceof SecurityException){
$response = new JSONResponse(['message' => $exception->getMessage()]); $response = new JSONResponse(['message' => $exception->getMessage()]);
if($exception->getCode() !== 0) { if($exception->getCode() !== 0) {

+ 2
- 2
lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php 查看文件

* {@inheritDoc} * {@inheritDoc}
* @throws RateLimitExceededException * @throws RateLimitExceededException
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
parent::beforeController($controller, $methodName); parent::beforeController($controller, $methodName);


$anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit'); $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit');
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if($exception instanceof RateLimitExceededException) { if($exception instanceof RateLimitExceededException) {
if (stripos($this->request->getHeader('Accept'),'html') === false) { if (stripos($this->request->getHeader('Accept'),'html') === false) {
$response = new JSONResponse( $response = new JSONResponse(

+ 3
- 3
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 查看文件

* @param string $methodName the name of the method * @param string $methodName the name of the method
* @throws SecurityException when a security check fails * @throws SecurityException when a security check fails
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {


// this will set the current navigation entry of the app, use this only // this will set the current navigation entry of the app, use this only
// for normal HTML requests and not for AJAX requests // for normal HTML requests and not for AJAX requests
* @param Response $response * @param Response $response
* @return Response * @return Response
*/ */
public function afterController(Controller $controller, $methodName, Response $response) {
public function afterController($controller, $methodName, Response $response) {
$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy(); $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();


if (get_class($policy) === EmptyContentSecurityPolicy::class) { if (get_class($policy) === EmptyContentSecurityPolicy::class) {
* @throws \Exception the passed in exception if it can't handle it * @throws \Exception the passed in exception if it can't handle it
* @return Response a Response object or null in case that the exception could not be handled * @return Response a Response object or null in case that the exception could not be handled
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if($exception instanceof SecurityException) { if($exception instanceof SecurityException) {
if($exception instanceof StrictCookieMissingException) { if($exception instanceof StrictCookieMissingException) {
return new RedirectResponse(\OC::$WEBROOT); return new RedirectResponse(\OC::$WEBROOT);

+ 2
- 2
lib/private/AppFramework/Middleware/SessionMiddleware.php 查看文件

* @param Controller $controller * @param Controller $controller
* @param string $methodName * @param string $methodName
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
$useSession = $this->reflector->hasAnnotation('UseSession'); $useSession = $this->reflector->hasAnnotation('UseSession');
if (!$useSession) { if (!$useSession) {
$this->session->close(); $this->session->close();
* @param Response $response * @param Response $response
* @return Response * @return Response
*/ */
public function afterController(Controller $controller, $methodName, Response $response){
public function afterController($controller, $methodName, Response $response){
$useSession = $this->reflector->hasAnnotation('UseSession'); $useSession = $this->reflector->hasAnnotation('UseSession');
if ($useSession) { if ($useSession) {
$this->session->close(); $this->session->close();

+ 4
- 4
lib/public/AppFramework/Middleware.php 查看文件

* the controller * the controller
* @since 6.0.0 * @since 6.0.0
*/ */
public function beforeController(Controller $controller, $methodName){
public function beforeController($controller, $methodName){


} }


* @return Response a Response object in case that the exception was handled * @return Response a Response object in case that the exception was handled
* @since 6.0.0 * @since 6.0.0
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception){
public function afterException($controller, $methodName, \Exception $exception){
throw $exception; throw $exception;
} }


* @return Response a Response object * @return Response a Response object
* @since 6.0.0 * @since 6.0.0
*/ */
public function afterController(Controller $controller, $methodName, Response $response){
public function afterController($controller, $methodName, Response $response){
return $response; return $response;
} }


* @return string the output that should be printed * @return string the output that should be printed
* @since 6.0.0 * @since 6.0.0
*/ */
public function beforeOutput(Controller $controller, $methodName, $output){
public function beforeOutput($controller, $methodName, $output){
return $output; return $output;
} }



+ 2
- 2
settings/Middleware/SubadminMiddleware.php 查看文件

* @param string $methodName * @param string $methodName
* @throws \Exception * @throws \Exception
*/ */
public function beforeController(Controller $controller, $methodName) {
public function beforeController($controller, $methodName) {
if(!$this->reflector->hasAnnotation('NoSubadminRequired')) { if(!$this->reflector->hasAnnotation('NoSubadminRequired')) {
if(!$this->isSubAdmin) { if(!$this->isSubAdmin) {
throw new NotAdminException('Logged in user must be a subadmin'); throw new NotAdminException('Logged in user must be a subadmin');
* @return TemplateResponse * @return TemplateResponse
* @throws \Exception * @throws \Exception
*/ */
public function afterException(Controller $controller, $methodName, \Exception $exception) {
public function afterException($controller, $methodName, \Exception $exception) {
if($exception instanceof NotAdminException) { if($exception instanceof NotAdminException) {
$response = new TemplateResponse('core', '403', array(), 'guest'); $response = new TemplateResponse('core', '403', array(), 'guest');
$response->setStatus(Http::STATUS_FORBIDDEN); $response->setStatus(Http::STATUS_FORBIDDEN);

+ 4
- 4
tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php 查看文件

$this->beforeControllerThrowsEx = $beforeControllerThrowsEx; $this->beforeControllerThrowsEx = $beforeControllerThrowsEx;
} }


public function beforeController(Controller $controller, $methodName){
public function beforeController($controller, $methodName){
self::$beforeControllerCalled++; self::$beforeControllerCalled++;
$this->beforeControllerOrder = self::$beforeControllerCalled; $this->beforeControllerOrder = self::$beforeControllerCalled;
$this->controller = $controller; $this->controller = $controller;
} }
} }


public function afterException(Controller $controller, $methodName, \Exception $exception){
public function afterException($controller, $methodName, \Exception $exception){
self::$afterExceptionCalled++; self::$afterExceptionCalled++;
$this->afterExceptionOrder = self::$afterExceptionCalled; $this->afterExceptionOrder = self::$afterExceptionCalled;
$this->controller = $controller; $this->controller = $controller;
parent::afterException($controller, $methodName, $exception); parent::afterException($controller, $methodName, $exception);
} }


public function afterController(Controller $controller, $methodName, Response $response){
public function afterController($controller, $methodName, Response $response){
self::$afterControllerCalled++; self::$afterControllerCalled++;
$this->afterControllerOrder = self::$afterControllerCalled; $this->afterControllerOrder = self::$afterControllerCalled;
$this->controller = $controller; $this->controller = $controller;
return parent::afterController($controller, $methodName, $response); return parent::afterController($controller, $methodName, $response);
} }


public function beforeOutput(Controller $controller, $methodName, $output){
public function beforeOutput($controller, $methodName, $output){
self::$beforeOutputCalled++; self::$beforeOutputCalled++;
$this->beforeOutputOrder = self::$beforeOutputCalled; $this->beforeOutputOrder = self::$beforeOutputCalled;
$this->controller = $controller; $this->controller = $controller;

正在加载...
取消
保存