承接 erlendellingsen/flex-router 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

erlendellingsen/flex-router

Composer 安装命令:

composer require erlendellingsen/flex-router

包简介

A small, lightweight php-router for creating clean, RESTful urls. Extremely easy to setup and configure.

README 文档

README

flexRouter logo

Build Status MIT Licence

flexRouter

An extremely small and lightweight PHP-router for clean, RESTful urls. Extremely easy to setup and requires no configuration. Just plain dead simple routing.

Supports parameters, different HTTP-methods and wildcard urls.

What's Changed

As the new maintainer I tried to implement a better more robust architecture without going away from the initial goal of the router which was to work off of if based control structures.

This may change in the future as the project evolves. Below is the reworked example of how I envision you using the router in its new, unit tested, form.

Installation

composer require erlendellingsen/flex-router

Setup

URL-rewrite must be enabled on the target server. This guide consists of an example on how to set it up on Apache-servers. If you do have IIS, Nginx or other examples, then please contribute!

Apache

Configuration

  • Apache-module mod_rewrite must be enabled.
  • Required Apache-vhost/Directory-setting AllowOverride all

.htaccess-file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ index.php?path=$1 [NC,L,QSA]

Non-Apache

You somehow have to enable rewriting of urls in your web server/directory to point all requests to index.php?path=x. If you have somewhat idea how, but need assistance then don't hesitate to reach out.

If you do have an example for other web servers then please consider getting in touch. (Open an issue, a fork, or just email me). Contributions are very much appreciated ☺️

Usage

The example beneath demonstrates how to setup flexRouter.

<?php

// Load the namespaces
use FlexRouter\FlexRouter;
use FlexRouter\Utilities\FlexResolver;

// Load in composer's autoloader
require_once 'vendor/autoload.php';

// Create a new router instance
$router = new FlexRouter();

/* Register your routes

Register Method        | Request Method | Route           | Route Id                           */
$router->registerRoute('GET',           '/',              'homepage'); // Can pass single method
$router->registerRoute(['GET', 'POST'], '/test',          'test');     // Or an array of methods
$router->registerRoute('GET',           '/test/:id/post', 'param');    // You can create URL params
$router->registerRoute('GET',           '/asdf*',         'wildcard'); // Or Wildcard Params

// Create your resolver
$requestMethod = $_SERVER['REQUEST_METHOD']; // Can be attained from either globals or request object
$requestUri    = $_SERVER['REQUEST_URI'];    // Can be attained from either globals or request object
$resolver      = new FlexResolver($requestMethod, $requestUri, $router);

// Start resolving your routes in whatever way you would like,
if ($resolver->resolve('homepage')) {
    echo 'The homepage route was found';

    return;
}

if ($resolver->resolve('test')) {
    echo 'The nested test route was found';

    return;
}

if ($resolver->resolve('param')) {
    echo "The param test route was found\r\n";
    echo $resolver->access()->params('url', 'id');

    return;
}

if ($resolver->resolve('wildcard')) {
    echo 'The wildcard test route was found';

    return;
}

// This is the 404 catch all
$resolver->notFound(function () {
    echo 'Nothing found';

    return;
});

Contribution

Want to contribute? Lovely! Contributions are very much appreciated. There are a ton of things to do in this project, but I don't have the time do to it. (At least not all).

Areas where contribution is deeply needed

  • Writing documentation (Get in touch if you need help!)
  • Making a better readme
  • Creating tests
  • Improving exception-handling
  • Better way to handle GET/POST (Support DELETE, PUT, etc).

And probably much much more.

License

MIT Copyright Erlend Ellingsen 2017. See LICENSE.

erlendellingsen/flex-router 适用场景与选型建议

erlendellingsen/flex-router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 18, 最近一次更新时间为 2016 年 06 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 erlendellingsen/flex-router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 erlendellingsen/flex-router 我们能提供哪些服务?
定制开发 / 二次开发

基于 erlendellingsen/flex-router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 18
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-03