diego03/path-to-regexp 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

diego03/path-to-regexp

最新稳定版本:1.0.2

Composer 安装命令:

composer require diego03/path-to-regexp

包简介

A very simpler path-to-regexp in php

README 文档

README

The PathToRegexp PHP library allows you to easily convert route paths into regular expression patterns for flexible route matching in web applications. This readme provides an overview of the library and includes various examples of usage.

Installation

composer require diego03/path-to-regexp

Usage

Basic Usage

use Diego\PathToRegexp\PathParser;

$pathParser = new PathParser();
$pattern = $pathParser->toRegex('/users/:id/edit');

// Use $pattern in your route matching logic
if ($pattern->match($uri)) {
    // Matched!
}

Route with Parameter

$pathParser = new PathParser();
$pattern = $pathParser->toRegex('/posts/:postId');

// The resulting pattern will match paths like '/posts/123'
if ($pattern->match($uri)) {
    // Matched!
}

Route with Optional Parameter

$pathParser = new PathParser();
$pattern = $pathParser->toRegex('/articles/:slug?');

// The resulting pattern will match paths like '/articles' and '/articles/some-slug'
if ($pattern->match($uri)) {
    // Matched!
}

Route with Text Segment

$pathParser = new PathParser();
$pattern = $pathParser->toRegex('/categories/:categoryName');

// The resulting pattern will match paths like '/categories/some-category'
if ($pattern->match($uri)) {
    // Matched!
}

Complex Route

$pathParser = new PathParser();
$pattern = $pathParser->toRegex('/users/:userId/:action?');

// The resulting pattern will match paths like '/users/123' and '/users/123/edit'
if ($pattern->match($uri)) {
    // Matched!
}

Note on Regular Expression Patterns

The library uses the TRegx\CleanRegex\Pattern class for regular expression patterns. You can leverage its features for more advanced use cases. Check the T-Regx documentation for detailed information.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

License

This library is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固