PHPackages                             holysword/holysword - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. holysword/holysword

ActiveFramework[Framework](/categories/framework)

holysword/holysword
===================

HolySword - A lightweight PHP API framework

00PHP

Since Jan 3Pushed 4mo agoCompare

[ Source](https://github.com/ziyueyijun/holysword)[ Packagist](https://packagist.org/packages/holysword/holysword)[ RSS](/packages/holysword-holysword/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

HolySword Framework
===================

[](#holysword-framework)

一个轻量级的 PHP 8.1+ 原生框架，专注于简洁、高效和易用性。

特性
--

[](#特性)

- **轻量级**：核心代码精简，无冗余依赖
- **原生 PHP**：基于 PHP 8.1+ 原生特性构建
- **完整的 ORM**：支持 MySQL、PostgreSQL、SQLite、SQL Server
- **优雅的路由**：支持 RESTful API 和 Web 路由
- **依赖注入**：内置服务容器
- **中间件支持**：灵活的请求/响应处理
- **模型关联**：支持一对一、一对多、多对多关联

环境要求
----

[](#环境要求)

- PHP &gt;= 8.1
- MySQL &gt;= 5.7 / PostgreSQL &gt;= 10 / SQLite 3
- Composer

快速开始
----

[](#快速开始)

### 1. 安装

[](#1-安装)

```
# 克隆项目
git clone https://github.com/holysword/framework.git holysword

# 进入目录
cd holysword

# 安装依赖
composer install

# 复制环境配置
cp .env.example .env

# 配置数据库连接
# 编辑 .env 文件，设置数据库信息

```

### 2. 配置 Web 服务器

[](#2-配置-web-服务器)

#### Nginx 配置

[](#nginx-配置)

```
server {
    listen 80;
    server_name your-domain.com;
    root /path/to/holysword/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

```

#### Apache 配置

[](#apache-配置)

确保 `public/.htaccess` 文件存在：

```

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]

```

### 3. 测试安装

[](#3-测试安装)

访问 `http://your-domain.com/api/status`，应返回：

```
{
    "code": 0,
    "message": "success",
    "data": {
        "status": "running",
        "timestamp": 1234567890,
        "app": "HolySword"
    }
}

```

基本使用
----

[](#基本使用)

### 路由定义

[](#路由定义)

```
// routes/api.php

// 基础路由
$router->get('/users', [UserController::class, 'index']);
$router->post('/users', [UserController::class, 'store']);
$router->get('/users/{id}', [UserController::class, 'show']);
$router->put('/users/{id}', [UserController::class, 'update']);
$router->delete('/users/{id}', [UserController::class, 'destroy']);

// 闭包路由
$router->get('/hello', function () {
    return Response::success(['message' => 'Hello World']);
});

```

### 控制器

[](#控制器)

```
// app/Controllers/UserController.php

namespace App\Controllers;

use HolySword\Http\Response;
use App\Models\User;

class UserController extends Controller
{
    public function index()
    {
        $users = User::all();
        return Response::success($users);
    }

    public function show($id)
    {
        $user = User::find($id);
        if (!$user) {
            return Response::error('用户不存在', 404);
        }
        return Response::success($user);
    }
}

```

### 模型

[](#模型)

```
// app/Models/User.php

namespace App\Models;

use HolySword\Database\Model\Model;

class User extends Model
{
    protected string $table = 'users';

    protected array $fillable = [
        'name', 'email', 'password'
    ];

    protected array $hidden = [
        'password'
    ];
}

```

### 数据库操作

[](#数据库操作)

```
// 查询所有
$users = User::all();

// 条件查询
$users = User::where('status', 1)->get();

// 查找单条
$user = User::find(1);
$user = User::where('email', 'test@example.com')->first();

// 创建
$user = User::create([
    'name' => '张三',
    'email' => 'zhangsan@example.com'
]);

// 更新
$user->update(['name' => '李四']);

// 删除
$user->delete();

```

目录结构
----

[](#目录结构)

```
holysword/
├── app/                    # 应用代码
│   ├── Controllers/        # 控制器
│   ├── Middleware/         # 中间件
│   ├── Models/             # 模型
│   └── Services/           # 服务层
├── config/                 # 配置文件
│   ├── app.php             # 应用配置
│   └── database.php        # 数据库配置
├── docs/                   # 文档
├── example/                # 示例代码
├── public/                 # Web 入口
│   └── index.php           # 入口文件
├── routes/                 # 路由定义
│   ├── api.php             # API 路由
│   └── web.php             # Web 路由
├── src/                    # 框架核心
├── tests/                  # 测试文件
├── .env.example            # 环境配置示例
├── .gitignore              # Git 忽略文件
├── composer.json           # Composer 配置
└── README.md               # 项目说明

```

文档
--

[](#文档)

详细文档请参阅 `docs/` 目录：

- [安装部署](docs/%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2.md)
- [路由使用](docs/%E8%B7%AF%E7%94%B1%E4%BD%BF%E7%94%A8.md)
- [数据库操作](docs/%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C.md)

许可证
---

[](#许可证)

本项目采用 [MIT 许可证](LICENSE)。

贡献
--

[](#贡献)

欢迎提交 Issue 和 Pull Request。

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance51

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1663991e674b3a34b07f71e8fb8bb7c1b50f11f75fc3ce05b1fd62e683a92139?d=identicon)[ziyueyijun](/maintainers/ziyueyijun)

---

Top Contributors

[![ziyueyijun](https://avatars.githubusercontent.com/u/27916971?v=4)](https://github.com/ziyueyijun "ziyueyijun (2 commits)")

### Embed Badge

![Health badge](/badges/holysword-holysword/health.svg)

```
[![Health](https://phpackages.com/badges/holysword-holysword/health.svg)](https://phpackages.com/packages/holysword-holysword)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

712181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91545.3M590](/packages/laravel-pail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
