承接 prwhyman/circuit 相关项目开发

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

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

prwhyman/circuit

Composer 安装命令:

composer create-project prwhyman/circuit

包简介

Routing and template system built in pure PHP. Requires web-server to route all traffic to a "gateway" file which will handle routing code internally through PHP.

README 文档

README

A modular, in-language, blacklist philosophy, router.

Circuit was a project I began working on after I created "Pulse", it allows for similar functionality seen in "Laravel" in a more modular form with less bloat. If you are looking for a module that can provide a templating engine and a router -- with nothing else -- this is likely for you.

Circuit uses a "blacklist" philosophy when it comes to directing traffic. All traffic is routed through your index (or another file of your choice) and the URI is interpreted, parsed and acted upon in-language (bypassing the web-server).

The following checks are performed on parsed URIs:

  • A missing EndPoint will return a 404
  • A mismatched variable type will return a 406
  • An incorrect amount of parameters will return a 400

Once the EndPoint is verified you can build logic for how you want it to proceed. Here is an example workflow:

  1. Setup:

       // Create a Circuit Router and Template parser.
       $router = new Router();
       $template = new Template();
    
  2. Define an Endpoint:

       // Create an "EndPoint" at "/home" using a 'home.html' template.
       $router
         ->get('/home')
         ->tplFile(
           'home.html',
           // Closure to populate the template's context.
           function (Command $command) {
             return CategoryController::retrieveCatsAndBoards($command);
           }
         );
    
  3. Handle the Request:

       // Collect the URI and method.
       $uri = $_SERVER['REQUEST_URI'] == '/' ? '/home' : $_SERVER['REQUEST_URI'];
       $met = $_SERVER['REQUEST_METHOD'];
          
       // Validate the endpoint.
       $uriRes = $router->validateEndpoint($uri, $met);
          
       // If the response is bad, serve an error page.
       if ($uriRes['code'] != StatusCodes::OK) {
         serveStatic($uriRes['code']);
       }
    
  4. Execute Callbacks and Render the Template:

     // Run any potential closures and bind the data to the template context.
     $callbackChk = tryCallback($uriRes);
        
     // If the closure failed, serve an error page.
     if (!$callbackChk) {
       serveStatic($uriRes['code']);
     }
        
     // Tokenize and render the template.
     $template->lex('file', "src/View/layout/{$uriRes['ep']->file");
     $template->render();
    

The system is surprisingly fast at parsing EndPoints, though I have yet to scale it beyond 2 dozen or so. Circuit also comes with it's own template engine which allows for multiple renders on changing contexts -- while only needing to tokenize the template once. Circuit's template engine uses a similar syntax to handlebars and makes heavy use of PHP's blazingly fast associative array access time.

The template engine features the following syntax:

  • {{key.value}} - searches for a given key's value inside another key e.g. {{post.content}} where post would be: 'post' => ['content' => 'example]
  • {{key.key.value}} - supports nested associative arrays.
  • {{for x as y}} / {{/for}} - performing loops over nested arrays
  • {{`link/to/template/file}} - running templates inside other templates.

Circuit is by no means feature-complete and exists to solve a problem I had in the moment however I do still work on it and add more function as and when the need arises.

What's next?

  • Converting the Token array into a Linked List
  • Looking at graph tree performance over nested arrays.
  • Adding an Abstract Syntax Tree for 'if' statement support
  • Storing EndPoints inside of a prefix tree for faster accessing.

prwhyman/circuit 适用场景与选型建议

prwhyman/circuit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 prwhyman/circuit 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unlicense
  • 更新时间: 2026-03-13