horizom/app
Composer 安装命令:
composer create-project horizom/app
包简介
The lightness PHP framework.
关键字:
README 文档
README
The lightness PHP framework — fast, minimal, PSR-compliant.
Overview
Horizom is a lightweight PHP micro-framework built on PSR standards. It provides a clean, expressive foundation for building web applications and REST APIs without the overhead of a full-stack framework.
Core packages:
| Package | Role |
|---|---|
horizom/core |
Application container, configuration, lifecycle |
horizom/routing |
PSR-15 router powered by FastRoute |
horizom/http |
PSR-7 request/response helpers |
Requirements
- PHP 8.0 or higher
- Composer 2.x
Installation
composer create-project horizom/app my-project
cd my-project
cp .env.example .env
Start the built-in development server:
composer serve
# → http://localhost:8000
Project Structure
├── app/
│ ├── Controllers/ # Request handlers (PSR-7)
│ ├── Middlewares/ # PSR-15 middleware (CORS, errors…)
│ ├── Models/ # Domain models
│ └── Providers/ # Service providers
├── bootstrap/
│ ├── app.php # Application bootstrap
│ └── dependencies.php # Middleware registration
├── config/
│ ├── app.php # App settings
│ ├── auth.php # JWT / auth settings
│ └── database.php # Database connections
├── public/
│ └── index.php # Front controller
├── resources/
│ └── views/ # Blade templates
├── routes/
│ ├── web.php # Web routes
│ └── api.php # API routes
└── tests/
└── Unit/ # PHPUnit test suites
Configuration
All sensitive values must be set in your .env file and are never committed to version control.
# Application APP_NAME=Horizom APP_ENV=development APP_URL=http://localhost:8000 APP_DEBUG=false # Database DB_DRIVER=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=horizom DB_USERNAME=root DB_PASSWORD=
Access config values anywhere with the config() helper:
$name = config('app.name'); // "Horizom" $dsn = config('database.default'); // "development"
Routing
Web routes (routes/web.php)
$router->get('/', 'MainController@index');
API routes (routes/api.php)
$router->group(['prefix' => 'api'], function (RouteCollector $router) { $router->get('/status', 'ApiController@status'); $router->get('/version', 'ApiController@version'); });
Use explicit HTTP verbs — avoid any() as it widens the attack surface.
Controllers
Controllers are final classes. They return a PSR-7 ResponseInterface.
<?php declare(strict_types=1); namespace App\Controllers; use Psr\Http\Message\ResponseInterface; final class ApiController { public function status(): ResponseInterface { return response()->json(['status' => 'UP']); } }
Middleware
Registering middleware
Global middleware is registered in bootstrap/dependencies.php:
$app->add(new \App\Middlewares\CorsMiddleware());
CORS (CorsMiddleware)
Handles preflight OPTIONS requests directly — returns 204 without invoking the next handler — and attaches CORS headers to all other responses.
To restrict allowed origins in production, edit the $allowedOrigins property:
// app/Middlewares/CorsMiddleware.php private array $allowedOrigins = [ 'https://myapp.com', 'https://www.myapp.com', ];
Error handling (ErrorHandlerMiddleware)
Maps exceptions to structured HTTP responses:
| Exception | Status |
|---|---|
NotFoundException |
404 Not Found |
MethodNotAllowedException |
405 Method Not Allowed |
Any other Throwable |
500 Internal Server Error |
XHR / AJAX requests receive a JSON payload; browser requests receive an HTML error page.
Stack traces are only included when
app.pretty_debug = true. Never expose them in production.
Built-in API Endpoints
| Method | Path | Description |
|---|---|---|
GET |
/api |
Health check alias |
GET |
/api/status |
Returns { "status": "UP" } |
GET |
/api/version |
Returns the framework version |
Views
Templates use the Blade engine. Layouts live in resources/views/.
@extends('default') @section('content') <h1>Hello, World!</h1> @endsection
Available helpers inside templates:
{{ config('app.name') }} {{ asset('css/style.css') }}
Testing
Tests use PHPUnit 11 and live in tests/Unit/.
composer test # or directly: vendor/bin/phpunit
tests/
└── Unit/
├── Controllers/
│ └── ApiControllerTest.php
└── Middlewares/
├── CorsMiddlewareTest.php
└── ErrorHandlerMiddlewareTest.php
Security
| Concern | Mitigation |
|---|---|
| Secrets in source code | Use .env for all credentials — never hardcode |
| Stack trace exposure | Only shown when app.pretty_debug = true |
| CORS wildcard in production | Replace ['*'] with an explicit origin list |
| Over-broad HTTP verbs | API routes use GET only; avoid any() |
| Type safety | All classes declare strict_types=1 |
Learning Horizom
The full Horizom documentation covers installation, routing, middleware, templating, and more.
License
The Horizom framework is open-sourced software licensed under the MIT license.
horizom/app 适用场景与选型建议
horizom/app 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「horizon」 「horizom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 horizom/app 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horizom/app 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 horizom/app 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Horizon Restart for Laravel.
This is my package LaravelHorizonMonitor
Laravel Horizon integration for October CMS
Adds a command to easily clear all your defined queues at once.
Framework-agnostic PHP core for Crontinel — data objects, monitor contracts, and alert management.
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-10