Download the PHP package sojf/routing without Composer

On this page you can find all versions of the php package sojf/routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package routing

路由类库(Routing)

本路由类库最终目的只是提供路由编译结果,拿到结果后可以按实际需求开发。

安装

快速例子:


web开发,离不开http协议,http协议抽象化后可得出2个概念: 请求 响应。 路由处理的便是http请求,具体来说,路由处理http请求中的URL部分。 本路由类库有三个概念:路由类型路由规则路由目标

路由规则:

路由规则例子:

当前请求URL 路由规则 匹配结果
/user /user(/name)? 成功
/user/name /user(/name)? 成功
/user/money /user/name 失败
/user/info /user/\w+ 成功
/user/100 /user/\w+ 失败
/img/2010/10/1 /img/\d{4}/\d{1,2}/\d{1} 成功
/img/year/month/day /img/\d{4}/\d{1,2}/\d{1} 失败

捕获变量:

如何获取当前请求URL中的值? 由于路由规则就是正则表达式,所以可以使用正则子组,为了方便使用这个子组, 还可以给子组命名,这样便可以在正则匹配结果中获取的到,然后进行你下一步的操作。

当前请求URL 路由规则 正则匹配结果(数组)
/api-3bbe1210b /api-(?<token>\w*) [token] => 3bbe1210b
/img/2010/10/1 /img/(?<year>\d{4})/(?<month>\d{1,2})/(?<day>\d{1}) [year] => 2010, [month] => 10, [day] => 1

路由类型:

路由类型,用来区分不同使用场景。 需要说明的是,本路由类库最终目的只是提供路由编译结果,拿到结果后可以按实际需求开发,如不适合,完全可以替换掉。 下面是默认的路由类型,主要用于自己的框架,供大家参考。

路由类型 类型标识(区分大小写) 使用要求 说明
普通路由 NORM 必须指定控制器@方法 URL和控制器@方法是一对一关系
动态路由 DM 必须在路由规则设置子组命名_DM_ URL和控制器@方法是一对多关系
REST路由 REST 暂无 http请求方法和应控制器@方法一对一关系

本类库主要有四个类:

Route类

构造函数:

参数 默认值 说明 格式
scheme 空字符串 路由方案,用来指定路由类型和路由规则 用冒号分隔,不能有空格。路由类型:路由规则
controller 空字符串 控制器,指定路由匹配成功后执行的目标 控制器@方法
suffix 空字符串 路由后缀,seo优化用。例如,url以html,shtml结尾 任意字符串,有多个后缀可用|分隔。html|shtml
name 空字符串 路由索引,不可以和别的name重名,用于后期查找路由。暂时不用理会,不传可以 任意字符串

例子1:

例子2:

Collection类

如果有很多路由,可以使用Collection对象来存储路由

方法 参数 返回值 说明
conf array $data 批量添加路由对象到集合中,数组格式为 [['scheme'=>'', 'controller'=>'', 'suffix'=>'', 'index'=>'']]
add Route $route 添加路由对象到集合中
all array 返回所有路由对象

例子:

Compiler类

Compiler类负责对路由信息进行处理,并输出处理结果,其最主要作用是生成路由匹配正则表达式。 默认Compiler类实现了应用名,控制器,控制器方法,模型命名空间,视图命名控制等等功能编译,如果一时不懂,可以看源码即可。 默认Compiler类的实现主要是用于自己框架。如不适合,可自行替换掉Compiler类。

方法 参数 返回值 说明
setRoute RouteInterface $route $this 设置要编译的路由信息对象
setCompiled CompiledInterface $compiled $this 设置编译结果存储对象
compile Compiled 对象 编译路由信息,并返回编译结果对象
getCompiled Compiled 对象 获取编译结果对象
getRoute Route 对象 获取路由信息对象

例子:


Compiled类

Compiled类,主要用来保存编译结果,供后续逻辑使用。 默认Compiled类的实现主要是用于自己框架。如不适合,可自行替换掉Compiled类。

方法 参数 返回值 说明
setRouteType mixed $routeType 设置路由类型
getRouteType mixed 获取路由类型
setRoutePathRegexp mixed $routePathRegexp 设置路由正则
getRoutePathRegexp mixed 获取路由正则
setRoutePath mixed $routePath 设置路由规则
getRoutePath mixed 获取路由规则
setControllerClass mixed $controller 设置控制器类
getControllerClass mixed 获取控制器类
setControllerMethod mixed $controllerMethod 设置控制器方法
getControllerMethod mixed 获取控制器方法
setAppName mixed $appName 设置应用名
getAppName mixed 获取应用名
setModelNameSpace mixed $modelNameSpace 设置模型命名空间
getModelNameSpace mixed 获取模型命名空间
setViewNameSpace mixed $viewNameSpace 设置视图命名空间
getViewNameSpace mixed 获取视图命名空间
setMatchRes array $matchRes 设置路由正则匹配结果,用于给控制器解析器获取匹配里面的捕获变量
getMatchRes mixed 获取路由正则匹配结果,用于给控制器解析器获取匹配里面的捕获变量

All versions of routing with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sojf/routing contains the following files

Loading the files please wait ....