Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Commit

Permalink
Play around with interface, hopefully simplifying it.
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Sep 17, 2014
1 parent 075c7f8 commit b4dd63f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
24 changes: 19 additions & 5 deletions src/FluxBB/Core/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,29 @@ abstract class Action implements MessageProviderInterface


/**
* Determine whether the given subject is authorized to execute this action.
* Make sure the given subject is authorized to execute this action.
*
* If authorization fails, an exception should be thrown.
*
* @param \FluxBB\Server\Request $request
* @param \FluxBB\Models\HasPermissions $subject
* @return bool
* @return $this
* @throws \Exception
*/
public function authorize(Request $request, HasPermissions $subject)
public function authorize(HasPermissions $subject)
{
return true;
return $this;
}

/**
* Set the request instance.
*
* @param \FluxBB\Server\Request $request
* @return $this
*/
public function setRequest($request)
{
$this->request = $request;
return $this;
}

/**
Expand Down
23 changes: 3 additions & 20 deletions src/FluxBB/Server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,9 @@ public function dispatch(Request $request, HasPermissions $subject)
// Create the action instance
$action = $this->resolve($request->getHandler());

// Make sure that we are authorized for this request
$this->ensureAuthorization($action, $request, $subject);

return $action->handle($request);
}

/**
* Throw an exception in case we are not authorized to execute this action.
*
* @param \FluxBB\Core\Action $action
* @param \FluxBB\Server\Request $request
* @param \FluxBB\Models\HasPermissions $subject
* @return void
* @throws \Exception
*/
protected function ensureAuthorization(Action $action, Request $request, HasPermissions $subject)
{
if (!$action->authorize($request, $subject)) {
throw new \Exception('Too bad, we are not authorized.');
}
return $action->setRequest($request)
->authorize($subject)
->execute();
}

/**
Expand Down

0 comments on commit b4dd63f

Please sign in to comment.