定制 movisio/lazy-router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

movisio/lazy-router

Composer 安装命令:

composer require movisio/lazy-router

包简介

Nette RouteList with capability of lazy loading routes with prefix

README 文档

README

Nette RouteList with capability of lazy loading routes.
It is usable especially when you have many (hundreds?) of routes, which slows your system and you don't need to load them all for every request.

For example, when your application have more independent modules and every module has its own routes, they can be separated and lazy loaded per-module.

Note that this router was created especially for hundreds of static routes for large API and should not be used for normal route <module>/<presenter>/<action>.

Usage

By default, LazyRouteList behaves exactly like ordinary RouteList. For lazy loading function, use setLazyCachedRoutes method. It has only one argument: callback for loading routes into cache. Return value of callback should be array of routers. Function also accepts argument $dependencies, just like nette Cache::load callback.

$router = new LazyRouteList($cache);
$router->setLazyCachedRoutes(function (&$dependencies) : array {
    
    // .... read routes from files or whatever ...
    $routes = [
        new \Nette\Routing\Route('/api/v1/route/to/resource', 'Module:ApiPresenter:action')    
    ];
    
    // optional cache dependency for automatic cache invalidation and routes reloading
    $dependencies[\Nette\Caching\Cache::FILES] = ['path/to/file', 'path/to/another/file'];
    
    return $routes;
});

Routes will be separated into groups by static part of path (without parameters) and by presenters and will be cached.

When matching, router will load only routes with matching static part of path.
When creating links, only routes matching target presenter will be loaded from cache.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固