horizom/app 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

horizom/app

Composer 安装命令:

composer create-project horizom/app

包简介

The lightness PHP framework.

README 文档

README

Total Downloads Latest Stable Version License

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

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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-10