-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring route to use object serialization and force reindexing #725
- Loading branch information
Showing
9 changed files
with
140 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.routing; | ||
|
||
import fr.adrienbrault.idea.symfony2plugin.routing.dict.RouteInterface; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
|
@@ -13,9 +12,13 @@ | |
* @author Adrien Brault <[email protected]> | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class Route { | ||
public class Route implements RouteInterface { | ||
|
||
@NotNull | ||
final private String name; | ||
|
||
@NotNull | ||
private Collection<String> methods = new HashSet<>(); | ||
private String controller; | ||
private String path; | ||
private Set<String> pathCache; | ||
|
@@ -25,7 +28,7 @@ public class Route { | |
private HashMap<String, String> requirements = new HashMap<String, String>(); | ||
private List<Collection<String>> tokens = new ArrayList<Collection<String>>(); | ||
|
||
public Route(String name, HashSet<String> variables, HashMap<String, String> defaults, HashMap<String, String> requirements, ArrayList<Collection<String>> tokens) { | ||
public Route(@NotNull String name, HashSet<String> variables, HashMap<String, String> defaults, HashMap<String, String> requirements, ArrayList<Collection<String>> tokens) { | ||
this.name = name; | ||
|
||
this.variables = variables; | ||
|
@@ -50,23 +53,7 @@ public Route(@NotNull RouteInterface routeInterface) { | |
this.name = routeInterface.getName(); | ||
this.controller = routeInterface.getController(); | ||
this.path = routeInterface.getPath(); | ||
} | ||
|
||
public Route(@NotNull String name, @Nullable String[] indexed) { | ||
this.name = name; | ||
|
||
// its not valid to provide nullable value, | ||
// but index based allows this | ||
if(indexed != null) { | ||
if(indexed.length >= 1 && StringUtils.isNotBlank(indexed[0])) { | ||
this.controller = indexed[0]; | ||
} | ||
|
||
if(indexed.length >= 2 && StringUtils.isNotBlank(indexed[1])) { | ||
this.path = indexed[1]; | ||
} | ||
} | ||
|
||
this.methods = routeInterface.getMethods(); | ||
} | ||
|
||
@NotNull | ||
|
@@ -118,4 +105,9 @@ public String getPath() { | |
return path; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<String> getMethods() { | ||
return this.methods; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
|
@@ -17,6 +20,9 @@ public class JsonRoute implements RouteInterface { | |
@Nullable | ||
private String path; | ||
|
||
@Nullable | ||
private Collection<String> methods; | ||
|
||
public JsonRoute(@NotNull String name) { | ||
this.name = name; | ||
} | ||
|
@@ -39,6 +45,12 @@ public String getPath() { | |
return this.path; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Collection<String> getMethods() { | ||
return this.methods == null ? Collections.emptyList() : this.methods; | ||
} | ||
|
||
public JsonRoute setPath(@Nullable String path) { | ||
this.path = path; | ||
|
||
|
@@ -50,4 +62,10 @@ public JsonRoute setController(@Nullable String controller) { | |
|
||
return this; | ||
} | ||
|
||
public JsonRoute setMethods(@Nullable Collection<String> methods) { | ||
this.methods = methods; | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
|
@@ -16,4 +18,7 @@ public interface RouteInterface { | |
|
||
@Nullable | ||
String getPath(); | ||
|
||
@NotNull | ||
Collection<String> getMethods(); | ||
} |
4 changes: 3 additions & 1 deletion
4
src/fr/adrienbrault/idea/symfony2plugin/stubs/dict/StubIndexedRoute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.