定制 alkemann/h2l 二次开发

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

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

alkemann/h2l

Composer 安装命令:

composer require alkemann/h2l

包简介

A micro framework for websites and apis. This is a sequel of h.l, made for PHP 8

README 文档

README

Get started quickly with static pages and small apis

Packagist Tag PHP codecov StyleCI Scrutinizer Code Quality

Documentation

Hosted on Github pages: https://alkemann.github.io/h2l/

Requirements

  • PHP 8.1

Install

  • Install via composer: composer require alkemann/h2l
  • While you can use the library as only a lib, it comes with an index.php file. The library comes with 3 skeletons to get you started, the "min" contains basically just the index.php, the minimum expected folder structure and a hello world base route. You can also use the "base" that contains a an app, some base css, config files. Thirdly there is an "example" version that contains some more illustative example pages and dynamic routes. install by simply copying the skeleton folder contents of choice down to the root of your app (presumably the same folder that contains the "vendor" composer): vendor/bin/skeleton base (base automagic website using routes by files and folders). There more other skeleton alternatives:
    • min (bare bones)
    • heroku_react (set up for plug and play heroku app with H2L as backend and an react-redux frontend)
    • heroku_min (set up for plug and play heroku app with H2L)
    • api (no automagic routing, for pure api apps and specifically routed responses)
    • hyper (start out with Tailwind, alpine.js and HTMX for server side "SPA")

Usage from skeleton

  • Change the homepage by changing the file content/pages/home.html.php
  • Add files and folders to content/pages to add fixed routed content
  • Include a route file in webroot/index.php or add to resources/configs/routes.php if you installed the base skeleton.
  • Add dynamic routes there by supplying a regex match on url and a closure handler:

Some example routes:

use alkemann\h2l\{Request, Router, Response, response\Json};

// Get task by id, i.e. GET http://example.com/api/tasks/12
Router::add(
  '|^api/tasks/(?<id>\d+)$|',
  function(Request $request): Response
  {
    $id = $request->param('id'); // from the regex matched url part
    $data_model = app\Task::get($id);
    return new Json($data_model); // since Task model implements \JsonSerializable
  }
);

// http://example.com/version
Router::add('version', function($r) {
	return new Json(['version' => '1.3']);
});

Raw usage

A minimal webroot\index.php could look something like this

$root_path = realpath(dirname(dirname(__FILE__)));
require_once($root_path . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');

use alkemann\h2l\{Environment, Dispatch};

Environment::setEnvironment(Environment::PROD);
Environment::set([
    'debug' => false,
    'layout_path'  => $root_path . 'layouts' . DIRECTORY_SEPARATOR,
    'content_path' => $root_path .  'pages' . DIRECTORY_SEPARATOR,
]);

$dispatch = new Dispatch($_REQUEST, $_SERVER, $_GET, $_POST);
$dispatch->setRouteFromRouter();
$response = $dispatch->response();
if ($response) echo $response->render();

Tests

To run tests you must can checkout the repo and require with dev and run ./bin/runtests in the same folder as this README.md.

Or to run tests on the vendor included lib into your application, you must also require phpunit; composer require phpunit/phpunit and then you can run h2l tests with vendor/bin/testh2l

alkemann/h2l 适用场景与选型建议

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

它主要适用于以下技术方向: 「framework」 「microframework」 「routing」 「router」 「php8」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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