@@ -20,11 +20,11 @@ NS_ASSUME_NONNULL_BEGIN
2020/* *
2121 JLRRouteDefinition is a model object representing a registered route, including the URL scheme, route pattern, and priority.
2222
23- This class can be subclassed to customize route parsing behavior by overriding -routeResponseForRequest:decodePlusSymbols: .
23+ This class can be subclassed to customize route parsing behavior by overriding -routeResponseForRequest:.
2424 -callHandlerBlockWithParameters can also be overriden to customize the parameters passed to the handlerBlock.
2525 */
2626
27- @interface JLRRouteDefinition : NSObject
27+ @interface JLRRouteDefinition : NSObject < NSCopying >
2828
2929// / The URL scheme for which this route applies, or JLRoutesGlobalRoutesScheme if global.
3030@property (nonatomic , copy , readonly ) NSString *scheme;
@@ -35,28 +35,33 @@ NS_ASSUME_NONNULL_BEGIN
3535// / The priority of this route pattern.
3636@property (nonatomic , assign , readonly ) NSUInteger priority;
3737
38+ // / The route pattern path components.
39+ @property (nonatomic , copy , readonly ) NSArray <NSString *> *patternPathComponents;
40+
3841// / The handler block to invoke when a match is found.
3942@property (nonatomic , copy , readonly ) BOOL (^handlerBlock)(NSDictionary *parameters);
4043
44+ // / Check for route definition equality.
45+ - (BOOL )isEqualToRouteDefinition : (JLRRouteDefinition *)routeDefinition ;
4146
42- // /---------------------------------
47+
48+ // /----------------------------------
4349// / @name Creating Route Definitions
44- // /---------------------------------
50+ // /----------------------------------
4551
4652
4753/* *
4854 Creates a new route definition. The created definition can be directly added to an instance of JLRoutes.
4955
5056 This is the designated initializer.
5157
52- @param scheme The URL scheme this route applies for, or JLRoutesGlobalRoutesScheme if global.
5358 @param pattern The full route pattern ('/foo/:bar')
5459 @param priority The route priority, or 0 if default.
5560 @param handlerBlock The handler block to call when a successful match is found.
5661
5762 @returns The newly initialized route definition.
5863 */
59- - (instancetype )initWithScheme : ( NSString *) scheme pattern : (NSString *)pattern priority : (NSUInteger )priority handlerBlock : (BOOL (^)(NSDictionary *parameters))handlerBlock NS_DESIGNATED_INITIALIZER;
64+ - (instancetype )initWithPattern : (NSString *)pattern priority : (NSUInteger )priority handlerBlock : (BOOL (^)(NSDictionary *parameters))handlerBlock NS_DESIGNATED_INITIALIZER;
6065
6166// / Unavailable, use initWithScheme:pattern:priority:handlerBlock: instead.
6267- (instancetype )init NS_UNAVAILABLE;
@@ -65,6 +70,19 @@ NS_ASSUME_NONNULL_BEGIN
6570+ (instancetype )new NS_UNAVAILABLE;
6671
6772
73+ // /----------------------------------
74+ // / @name Responding To Registration
75+ // /----------------------------------
76+
77+
78+ /* *
79+ Called when the route has been registered for the given scheme.
80+
81+ @param scheme The scheme this route has become active for.
82+ */
83+ - (void )didBecomeRegisteredForScheme : (NSString *)scheme ;
84+
85+
6886// /-------------------------------
6987// / @name Matching Route Requests
7088// /-------------------------------
@@ -74,11 +92,10 @@ NS_ASSUME_NONNULL_BEGIN
7492 Creates and returns a JLRRouteResponse for the provided JLRRouteRequest. The response specifies if there was a match or not.
7593
7694 @param request The JLRRouteRequest to create a response for.
77- @param decodePlusSymbols The global plus symbol decoding option value.
7895
7996 @returns An JLRRouteResponse instance representing the result of attempting to match request to thie route definition.
8097 */
81- - (JLRRouteResponse *)routeResponseForRequest : (JLRRouteRequest *)request decodePlusSymbols : ( BOOL ) decodePlusSymbols ;
98+ - (JLRRouteResponse *)routeResponseForRequest : (JLRRouteRequest *)request ;
8299
83100
84101/* *
@@ -90,6 +107,71 @@ NS_ASSUME_NONNULL_BEGIN
90107 */
91108- (BOOL )callHandlerBlockWithParameters : (NSDictionary *)parameters ;
92109
110+
111+ // /---------------------------------
112+ // / @name Creating Match Parameters
113+ // /---------------------------------
114+
115+
116+ /* *
117+ Creates and returns the full set of match parameters to be passed as part of a valid match.
118+ Subclasses can override this method to mutate the match parameters, or simply call it to generate the expected value.
119+
120+ @param request The request being routed.
121+ @param routeVariables The parsed route variables (aka a route of '/route/:param' being routed with '/foo/bar' would create [ 'param' : 'bar' ])
122+
123+ @returns The full set of match parameters to be passed as part of a valid match.
124+ @see defaultMatchParametersForRequest:
125+ @see routeVariablesForRequest:
126+ */
127+ - (NSDictionary *)matchParametersForRequest : (JLRRouteRequest *)request routeVariables : (NSDictionary <NSString *, NSString *> *)routeVariables ;
128+
129+
130+ /* *
131+ Creates and returns the default base match parameters for a given request. Does not include any parsed fields.
132+
133+ @param request The request being routed.
134+
135+ @returns The default match parameters for a given request. Only includes key/value pairs for JLRoutePatternKey, JLRouteURLKey, and JLRouteSchemeKey.
136+ */
137+ - (NSDictionary *)defaultMatchParametersForRequest : (JLRRouteRequest *)request ;
138+
139+
140+ // /-------------------------------
141+ // / @name Parsing Route Variables
142+ // /-------------------------------
143+
144+
145+ /* *
146+ Parses and returns route variables for the given request.
147+
148+ @param request The request to parse variable values from.
149+
150+ @returns The parsed route variables if there was a match, or nil if it was not a match.
151+ */
152+ - (nullable NSDictionary <NSString *, NSString *> *)routeVariablesForRequest : (JLRRouteRequest *)request ;
153+
154+
155+ /* *
156+ Parses value into a variable name, including stripping out any extra characters if needed.
157+
158+ @param value The raw string value that should be parsed into a variable name.
159+
160+ @returns The variable name to use as the key of a key/value pair in the parsed route variables.
161+ */
162+ - (NSString *)routeVariableNameForValue : (NSString *)value ;
163+
164+
165+ /* *
166+ Parses value into a variable value, including stripping out any extra characters if needed.
167+
168+ @param value The raw string value that should be parsed into a variable value.
169+
170+ @returns The variable value to use as the value of a key/value pair in the parsed route variables.
171+ */
172+ - (NSString *)routeVariableValueForValue : (NSString *)value ;
173+
174+
93175@end
94176
95177
0 commit comments