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
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/pagesto add fixed routed content - Include a route file in
webroot/index.phpor add toresources/configs/routes.phpif 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alkemann/h2l 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Write down your routing mapping at one place
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
A router designed for web requests for the Monolith framework
统计信息
- 总下载量: 1.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-30