Download the PHP package constanze-standard/routing without Composer

On this page you can find all versions of the php package constanze-standard/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

Constanze Standard Routing

GitHub license Coverage 100%

路由组件将 HTTP 请求映射到一组预存变量中。主要用于为 Web 应用程序构建路由系统。

安装

开始使用

routing 有两个概念:

  1. RouteCollection 路由表数据的集合,负责收集 URL 匹配的信息。
  2. Matcher 负责将请求数据和路由表进行匹配,并返回匹配结果。

路由集合 (RouteCollection)

使用 RouteCollection 添加一条路由数据:

上例演示了使用 ConstanzeStandard\Routing\RouteCollectionadd 方法添加一条路由数据。add 方法的参数:

匹配器 (Matcher)

使用 Matcher 匹配请求数据:

Matcher 接受一个 RouteCollection 作为初始化参数,然后可以调用 match 方法进行请求匹配。match 方法的返回值受匹配结果影响,分为三种情况:

  1. 匹配成功的情况。将返回包含 4 个元素的数组:array(Matcher::STATUS_OK, $serializable, $unserializable, $arguments), 第一个元素固定为 Matcher::STATUS_OK 的值,表示匹配成功;第二个元素为可序列化数据;第三个元素为不可序列化数据;第四个元素为 URL 参数的 mapping(如:array('id' => 10)).
  2. URL 匹配成功,但 HTTP Method 匹配失败的情况。将返回包含 3 个元素的数组:array(Matcher::STATUS_ERROR, Matcher::ERROR_METHOD_NOT_ALLOWED, $allowedMethods), 第一个元素固定为 Matcher::STATUS_ERROR 的值,表示匹配出错;第二个元素为错误类型 Matcher::ERROR_METHOD_NOT_ALLOWED,表示不支持的 HTTP Method;第三个元素是一个数组,包含了这个 URL 所支持的 HTTP Method(如 array('GET', 'POST')).
  3. 匹配失败的情况。将返回包含 2 个元素的数组:array(Matcher::STATUS_ERROR, Matcher::ERROR_NOT_FOUND), 第一个元素固定为 Matcher::STATUS_ERROR 的值,表示匹配出错;第二个元素为错误类型 Matcher::ERROR_NOT_FOUND 表示找不到匹配项。

路由缓存

当路由数据变得庞大时,一次请求将会面临频繁的读写操作,这时可以使用路由缓存来加速 RouteCollection 的构建。

RouteCollection 唯一的初始化参数 $cacheFile 默认值是 null, 表示不使用缓存,如果希望开启缓存功能,则需要通过这个参数定义缓存文件的路径:

在你第一次开启缓存时,首先要确保缓存文件是不存在的。当缓存文件不存在时,RouteCollection::cache 会根据收集到的路由数据创建缓存文件,如果缓存文件存在,RouteCollection 会直接从缓存文件一次性读取数据,并忽略 cache 方法。

你的程序必须对缓存文件所在的位置有写入权限。


All versions of routing with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
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 constanze-standard/routing contains the following files

Loading the files please wait ....