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

first version #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/NSError+WLRError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// NSError+WLRError.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, WLRError) {

/** The passed URL does not match a registered route. */
WLRErrorNotFound = 45150,

/** The matched route handler does not specify a target view controller. */
WLRErrorHandlerTargetOrSourceViewControllerNotSpecified = 45151,
WLRErrorBlockHandleNoReturnRequest = 45152,
WLRErrorMiddlewareRaiseError = 45153
};
@interface NSError (WLRError)
+(NSError *)WLRNotFoundError;
+(NSError *)WLRTransitionError;
+(NSError *)WLRHandleBlockNoTeturnRequest;
+(NSError *)WLRMiddlewareRaiseErrorWithMsg:(NSString *)error;
@end
16 changes: 16 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/NSString+WLRQuery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NSString+WLRQuery.h
// Pods
//
// Created by Neo on 2016/12/16.
//
//

#import <Foundation/Foundation.h>

@interface NSString (WLRQuery)
+ (NSString *)WLRQueryStringWithParameters:(NSDictionary *)parameters ;
- (NSDictionary *)WLRParametersFromQueryString ;
- (NSString *)WLRStringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding ;
- (NSString *)WLRStringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIViewController+WLRRoute.h
// Pods
//
// Created by Neo on 2016/12/16.
//
//

#import <UIKit/UIKit.h>
@class WLRRouteRequest;
@interface UIViewController (WLRRoute)
@property(nonatomic,strong)WLRRouteRequest * wlr_request;
@end
25 changes: 25 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRMatchResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// WLRMatchResult.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
/**
The WLRMatchResult object is a result of whether a request url is matching for a handler or handleBlock.
该对象是一个url是否匹配的结果对象,paramProperties字典包含了url上的匹配参数。
*/

@interface WLRMatchResult : NSObject
/**
If matched,value is YES.
*/
@property (nonatomic, assign, getter=isMatch) BOOL match;
/**
If matched,the paramProperties dictionary will store url's path keyword paramaters away.
如果匹配成功,url路径中的关键字对应的值将存储在该字典中.
*/
@property (nonatomic, strong) NSDictionary *paramProperties;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// WLRRegularExpression.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
@class WLRMatchResult;
/**
This object is a regularExpression,it can match a url and return the result with WLRMatchResult object.
*/
@interface WLRRegularExpression : NSRegularExpression

/**
This method can return a WLRMatchResult object to check a url string is matched.

@param string a url string
@return matching result
*/
-(WLRMatchResult *)matchResultForString:(NSString *)string;
+(WLRRegularExpression *)expressionWithPattern:(NSString *)pattern;
@end
21 changes: 21 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRRoute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// WLRRoute.h
// Pods
//
// Created by Neo on 2016/12/18.
//
//

#ifndef WLRRoute_h
#define WLRRoute_h
#import <WLRRoute/NSError+WLRError.h>
#import <WLRRoute/NSString+WLRQuery.h>
#import <WLRRoute/UIViewController+WLRRoute.h>
#import <WLRRoute/WLRMatchResult.h>
#import <WLRRoute/WLRRegularExpression.h>
#import <WLRRoute/WLRRouteHandler.h>
#import <WLRRoute/WLRRouteMatcher.h>
#import <WLRRoute/WLRRouteMiddlewareProtocol.h>
#import <WLRRoute/WLRRouter.h>
#import <WLRRoute/WLRRouteRequest.h>
#endif /* WLRRoute_h */
22 changes: 22 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRRouteHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// WLRRouteHandler.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
@class WLRRouteRequest;
/**
This is a handler object, if a WLRRouteRequest object matched, WLRRouter object will invoke shouldHandleWithRequest、handleRequest method and transitionWithWithRequest method,you can overwrite some method to complete viewcontroller transition.
WLRRouteHandler对象与WLRRouteMatcher对象相对应,如果一个WLRRouteRequest对象匹配到该handler对象,则WLRRouter将触发 handleRequest 方法和transitionWithWithRequest方法,完成一次视图控制器的转场.
*/
@interface WLRRouteHandler : NSObject
- (BOOL)shouldHandleWithRequest:(WLRRouteRequest *)request;
-(UIViewController *)targetViewControllerWithRequest:(WLRRouteRequest *)request;
-(UIViewController *)sourceViewControllerForTransitionWithRequest:(WLRRouteRequest *)request;
-(BOOL)handleRequest:(WLRRouteRequest *)request error:(NSError *__autoreleasing *)error;
-(BOOL)transitionWithWithRequest:(WLRRouteRequest *)request sourceViewController:(UIViewController *)sourceViewController targetViewController:(UIViewController *)targetViewController isPreferModal:(BOOL)isPreferModal error:(NSError *__autoreleasing *)error;
- (BOOL)preferModalPresentationWithRequest:(WLRRouteRequest *)request;
@end
34 changes: 34 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRRouteMatcher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// WLRRouteMatcher.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
@class WLRRouteRequest;
/**
This object create a route WLRRouteRequest object with url matched string,it store the routeExpressionPattern and originalRouteExpression.
该对象会根据url匹配表达式生成一个WLRRouteRequest路由请求对象,如果为nil则说明不匹配,如果不为nil则说明该url可以匹配.
*/
@interface WLRRouteMatcher : NSObject
/**
a url matched regex pattern string.
*/
@property(nonatomic,copy)NSString * routeExpressionPattern;
/**
original route url matched pattern string
*/
@property(nonatomic,copy)NSString * originalRouteExpression;
+(instancetype)matcherWithRouteExpression:(NSString *)expression;
/**
If a NSURL object matched with routeExpressionPattern,return a WLRRouteRequest object or,otherwise return nil.

@param URL a request url string.
@param primitiveParameters some primitive parameters like UIImage object and so on.
@param targetCallBack if complete handle or complete block progress,it will call targetCallBack.
@return a WLRRouteRequest request object.
*/
-(WLRRouteRequest *)createRequestWithURL:(NSURL *)URL primitiveParameters:(NSDictionary *)primitiveParameters targetCallBack:(void(^)(NSError *, id responseObject))targetCallBack;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// WLRRouteMiddlewareProtocol.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
@class WLRRouteRequest;
@protocol WLRRouteMiddleware <NSObject>


/**
middleware handle a request, if middleware can handle this request, should return a response object, middleware could modify primitiveRequest inner, router will check and capture error and return dictionary, if return nil, router will transfer this request from current middleware to other

@param primitiveRequest primitive request, middleware can modify this request
@param error if middleware can handle this request and raise a error, router will handle this request with error and no long transfer.
@return if middleware can handle this request and return a responseObject,
router will handle this request with responseObject and no long transfer.
*/
-(NSDictionary *)middlewareHandleRequestWith:(WLRRouteRequest *__autoreleasing *)primitiveRequest error:(NSError *__autoreleasing *)error;
@end
28 changes: 28 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRRouteRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// WLRRouteRequest.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>

@interface WLRRouteRequest : NSObject<NSCopying>
/**
请求的URL
*/
@property (nonatomic, copy, readonly) NSURL *URL;
@property(nonatomic,copy)NSString * routeExpression;
@property (nonatomic, copy, readonly) NSDictionary *queryParameters;
@property (nonatomic, copy, readonly) NSDictionary *routeParameters;
@property (nonatomic, copy, readonly) NSDictionary *primitiveParams;

@property (nonatomic, strong) NSURL *callbackURL;
@property(nonatomic,copy)void(^targetCallBack)(NSError *error,id responseObject);
@property(nonatomic)BOOL isConsumed;
- (id)objectForKeyedSubscript:(NSString *)key;
-(instancetype)initWithURL:(NSURL *)URL routeExpression:(NSString *)routeExpression routeParameters:(NSDictionary *)routeParameters primitiveParameters:(NSDictionary *)primitiveParameters targetCallBack:(void(^)(NSError * error,id responseObject))targetCallBack;
-(instancetype)initWithURL:(NSURL *)URL;
-(void)defaultFinishTargetCallBack;
@end
57 changes: 57 additions & 0 deletions Example/build/Debug-iphonesimulator/WLRRoute/WLRRouter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// WLRRouter.h
// Pods
//
// Created by Neo on 2016/12/15.
//
//

#import <Foundation/Foundation.h>
#import "WLRRouteMiddlewareProtocol.h"
@class WLRRouteRequest;
@class WLRRouteHandler;

/**
Main route object,it can register a route pattern for a handler or block,manage middlewares,provide Subscription.
路由对象实体,提供注册route表达式和对应handler、block功能,提供中间件注册,提供下标访问的快捷方法
*/
@interface WLRRouter : NSObject

/**
注册一个route表达式并与一个block处理相关联

@param routeHandlerBlock block用以处理匹配route表达式的url的请求
@param route url的路由表达式,支持正则表达式的分组,例如app://login/:phone({0,9+})是一个表达式,:phone代表该路径值对应的key,可以在WLRRouteRequest对象中的routeParameters中获取
*/
-(void)registerBlock:(WLRRouteRequest *(^)(WLRRouteRequest * request))routeHandlerBlock forRoute:(NSString *)route;
/**
注册一个route表达式并与一个block处理相关联

@param routeHandlerBlock handler对象用以处理匹配route表达式的url的请求
@param route url的路由表达式,支持正则表达式的分组,例如app://login/:phone({0,9+})是一个表达式,:phone代表该路径值对应的key,可以在WLRRouteRequest对象中的routeParameters中获取
*/
-(void)registerHandler:(WLRRouteHandler *)handler forRoute:(NSString *)route;

/**
检测url是否能够被处理,不包含中间件的检查

@param url 请求的url
@return 是否可以handle
*/
-(BOOL)canHandleWithURL:(NSURL *)url;
-(void)setObject:(id)obj forKeyedSubscript:(NSString *)key;
-(id)objectForKeyedSubscript:(NSString *)key;

/**
处理url请求

@param URL 调用的url
@param primitiveParameters 携带的原生对象
@param targetCallBack 传给目标对象的回调block
@param completionBlock 完成路由中转的block
@return 是否能够handle
*/
-(BOOL)handleURL:(NSURL *)URL primitiveParameters:(NSDictionary *)primitiveParameters targetCallBack:(void(^)(NSError *, id responseObject))targetCallBack withCompletionBlock:(void(^)(BOOL handled, NSError *error))completionBlock;
-(void)addMiddleware:(id<WLRRouteMiddleware>)middleware;
-(void)removeMiddleware:(id<WLRRouteMiddleware>)middleware;
@end
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/Pods-WLRRoute_Example/Pods-WLRRoute_Example-dummy.m
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/Pods-WLRRoute_Example.build/Objects-normal/x86_64/Pods-WLRRoute_Example-dummy.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/Pods-WLRRoute_Tests.build/Objects-normal/x86_64/Pods-WLRRoute_Tests-dummy.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSError+WLRError.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSError+WLRError.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSString+WLRQuery.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSString+WLRQuery.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/UIViewController+WLRRoute.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/UIViewController+WLRRoute.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteRequest.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRMatchResult.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRMatchResult.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRegularExpression.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRegularExpression.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRMatchResult.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-dummy.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/NSError+WLRError.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/NSString+WLRQuery.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/UIViewController+WLRRoute.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRMatchResult.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRegularExpression.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRoute-dummy.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRouteHandler.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRouteMatcher.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRouter.o
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/build/Pods.build/Debug-iphonesimulator/WLRRoute.build/Objects-normal/x86_64/WLRRouteRequest.o
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteHandler.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteHandler.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRMatchResult.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/UIViewController+WLRRoute.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSError+WLRError.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteMatcher.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteMatcher.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRegularExpression.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteRequest.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRMatchResult.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteRequest.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteRequest.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSString+WLRQuery.h
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies: \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouter.m \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/Example/Pods/Target\ Support\ Files/WLRRoute/WLRRoute-prefix.pch \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouter.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteMiddlewareProtocol.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteHandler.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteMatcher.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/WLRRouteRequest.h \
/Users/JosephYu/Desktop/rubbish/p/WLRRoute/WLRRoute/Classes/NSError+WLRError.h
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading