Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "play.mvc.Controller".setContext implementable #223

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions framework/src/play/mvc/ActionInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void invoke(Http.Request request, Http.Response response) {
// Check the cache (only for GET or HEAD)
if ((request.method.equals("GET") || request.method.equals("HEAD")) && actionMethod.isAnnotationPresent(CacheFor.class)) {
cacheKey = actionMethod.getAnnotation(CacheFor.class).id();
if ("".equals(cacheKey)) {
if (cacheKey != null && cacheKey.isEmpty()) {
cacheKey = "urlcache:" + request.path + '?' + request.querystring;
}
actionResult = Cache.get(cacheKey);
Expand Down Expand Up @@ -184,8 +184,8 @@ boolean actionNeedsSession(Http.Request request) {

private PlayController createController(ActionContext context) {
PlayController controller = Injector.getBeanOfType(context.request.controllerClass);
if (controller instanceof Controller) {
((Controller) controller).setContext(context);
if (controller instanceof PlayContextController) {
((PlayContextController) controller).setContext(context);
}
return controller;
}
Expand Down Expand Up @@ -403,7 +403,6 @@ static void handleFinallies(Http.Request request, Session session, Throwable cau
}
}

@SuppressWarnings("unchecked")
public static void inferResult(Object o) {
// Return type inference
if (o != null) {
Expand Down Expand Up @@ -468,8 +467,8 @@ public static Object[] getActionMethod(String fullAction) {
if (!fullAction.startsWith("controllers.")) {
fullAction = "controllers." + fullAction;
}
String controller = fullAction.substring(0, fullAction.lastIndexOf("."));
String action = fullAction.substring(fullAction.lastIndexOf(".") + 1);
String controller = fullAction.substring(0, fullAction.lastIndexOf('.'));
String action = fullAction.substring(fullAction.lastIndexOf('.') + 1);
controllerClass = Play.classes.getClassIgnoreCase(controller);
if (controllerClass == null) {
throw new ActionNotFoundException(fullAction, new Exception("Controller " + controller + " not found"));
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/mvc/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import play.mvc.results.Forbidden;
import play.rebel.View;

public class Controller implements PlayController {
public class Controller implements PlayContextController {
protected ActionContext actionContext;
protected Http.Request request;
protected Http.Response response;
Expand All @@ -15,7 +15,7 @@ public class Controller implements PlayController {
protected Scope.RenderArgs renderArgs;
protected Validation validation;

protected void setContext(ActionContext actionContext) {
public void setContext(ActionContext actionContext) {
this.actionContext = actionContext;
request = actionContext.request;
response = actionContext.response;
Expand Down
12 changes: 12 additions & 0 deletions framework/src/play/mvc/PlayContextController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package play.mvc;

/**
* Interface for play controllers with ActionContext provided to them by the {@link play.mvc.ActionInvoker}.
*
* This class your controllers should implement, when they need access to the {@link play.mvc.ActionContext}.
* In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features
* useful when implementing controllers.
*/
public interface PlayContextController extends PlayController {
void setContext(ActionContext actionContext);
}
4 changes: 2 additions & 2 deletions framework/src/play/mvc/PlayController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* Marker interface for play controllers
*
* This is the class that your controllers should implement.
* In most cases, you can extend play.mvc.Controller that contains all needed methods for controllers.
* This is the class that your controllers should implement when they need very few capabilities..
* In most cases, you can extend {@link play.mvc.Controller} which provides a basic set of features for controllers.
*/
public interface PlayController {
}