swiftphp.ma/installer 问题修复 & 功能扩展

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

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

swiftphp.ma/installer

Composer 安装命令:

composer require swiftphp.ma/installer

包简介

Modern PHP framework with AI-powered CLI, built-in auth, multi-tenant support, and 70% less code

README 文档

README

Modern PHP framework with an expressive router, a simple ORM, built-in authentication, multi-tenant support, middleware, validation, and a lightweight view system. Ships with an AI-friendly CLI to generate controllers, models, and migrations fast — aiming for 70% less boilerplate.

SwiftPHP targets PHP 8+ and PSR-12 coding style. It’s ideal for small to medium apps, dashboards, APIs, and admin tools.

Repository: https://github.com/moaminemahnoudi/swiftphp

Features

  • Routing: Simple, declarative routes with controller binding
  • Controllers: Base controller with dependency injection via attributes
  • ORM & Query Builder: Lightweight Model + ModelQuery with Database and QueryBuilder
  • Migrations: Built-in migrator and generator via CLI
  • Authentication: Session-based auth helpers and middleware
  • Multi-Tenant: Tenant resolution + role-based access via traits
  • Middleware: Auth, CORS, Rate Limiting, Roles, Tenant
  • Validation: Declarative validation with Validator and exceptions
  • Views: PHP templates (.swift.php) with layout and components
  • CLI: swiftphp to generate, migrate, serve, and scaffold resources
  • Error Handling: Friendly error template and handler
  • Security: Helpers to harden common web risks

Requirements

  • PHP 8.1+
  • Composer
  • PDO extension for your database (e.g., MySQL, SQLite)

Installation

You can install globally (installer) or scaffold directly from source.

Packagist (recommended)

Once published:

composer global require swiftphp.ma/installer
composer create-project swiftphp.ma/installer my-app

From Source (this repository)

# Install dependencies
composer install

# Ensure storage directories exist
mkdir storage\views

# Start PHP built-in server
php -S localhost:8000 -t public

Open http://localhost:8000 in your browser.

Quick Start

  1. Configure app and database:
    • config/app.php
    • config/database.php
  2. Run migrations:
# Windows PowerShell
php bin\swiftphp migrate
  1. Start the server:
php -S localhost:8000 -t public
  1. Visit http://localhost:8000 — default home.swift.php view renders.

Documentation

Project Structure

app/
  Controllers/       # Application controllers
  Models/            # Domain models (extends src/Core/Model)
config/              # App + DB config
database/migrations/ # Migration files
public/              # Front controller (index.php)
resources/views/     # Views (layouts, components, pages)
src/                 # Framework source (core, router, db, console, etc.)
storage/views/       # Compiled/cached views

Key framework modules:

  • src/Core: Application, Container, Controller, Model, Router
  • src/Http: Request, Response
  • src/Database: Database, QueryBuilder
  • src/Auth: Auth helpers, Tenant
  • src/Middleware: Middleware base and built-ins
  • src/Validation: Validator, ValidationException
  • src/View: View engine
  • src/Console: CLI application + commands

Routing

Define routes in public/index.php using the Router.

Example:

use Src\Core\Application;
use Src\Core\Router;
use App\Controllers\UserController;

$app = new Application();
$router = new Router($app);

$router->get('/', [UserController::class, 'home']);
$router->get('/users', [UserController::class, 'index']);
$router->get('/users/{id}', [UserController::class, 'show']);
$router->post('/users', [UserController::class, 'store']);

$router->dispatch();

Route parameters like {id} are available via Request.

Controllers

Controllers live in app/Controllers and extend Src\Core\Controller.

namespace App\Controllers;

use Src\Core\Controller;
use Src\Http\Request;
use App\Models\User;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = User::query()->get();
        return $this->view('users/index', compact('users'));
    }
}

Dependency injection is supported via the container and Attributes\Inject.

Models & Querying

Models extend Src\Core\Model. A simple User model:

namespace App\Models;

use Src\Core\Model;

class User extends Model
{
    protected string $table = 'users';
    protected array $fillable = ['name', 'email'];
}

Query examples:

$all = User::query()->get();
$one = User::query()->where('id', 1)->first();
User::query()->insert(['name' => 'Ada', 'email' => 'ada@example.com']);
User::query()->update(1, ['name' => 'Ada Lovelace']);
User::query()->delete(1);

Migrations

Migration files live in database/migrations. Use the CLI to create and run them.

# Generate migration
php bin\swiftphp make:migration create_posts_table

# Run migrations
php bin\swiftphp migrate

Example migration file name: 2024_01_01_000000_create_users_table.php.

Views

SwiftPHP uses plain PHP templates with a .swift.php suffix.

  • Layouts: resources/views/layouts/app.swift.php
  • Components: resources/views/components/*.swift.php
  • Pages: resources/views/*.swift.php

Render from a controller:

return $this->view('users/index', ['users' => $users]);

The engine compiles views to storage/views for performance.

Authentication & Authorization

  • src/Auth/Auth.php: login, logout, current user helpers
  • src/Middleware/AuthMiddleware.php: gate routes to authenticated users
  • src/Traits/HasRoles.php: role management on models
  • src/Auth/Tenant.php + src/Traits/HasTenant.php: multi-tenant helpers

Apply middleware on routes or in controller dispatch.

Middleware

Built-ins:

  • AuthMiddleware
  • CorsMiddleware
  • RateLimitMiddleware
  • RoleMiddleware
  • TenantMiddleware

Register and apply to routes via the router or a pipeline.

Validation

Use Src\Validation\Validator to validate request data.

use Src\Validation\Validator;

Validator::make($request->all(), [
  'email' => ['required', 'email'],
  'name'  => ['required', 'min:2']
])->validate();

On failure, throws ValidationException which the error handler renders.

CLI Commands

Run via php bin\\swiftphp (or bin\\swiftphp.bat on Windows):

  • new: Scaffold a new project
  • serve: Start a dev server
  • make:controller: Generate a controller
  • make:model: Generate a model
  • make:migration: Generate a migration
  • migrate: Run migrations
  • help: Show available commands

Examples:

php bin\swiftphp serve
php bin\swiftphp make:controller UserController
php bin\swiftphp make:model User
php bin\swiftphp make:migration add_auth_fields_to_users_table
php bin\swiftphp migrate

Configuration

  • config/app.php: app name, env, debug, timezone, etc.
  • config/database.php: driver, host, database, user, password

Use environment variables via src/Support/Env.php.

Error Handling & Security

  • Error pages via src/Error/error_template.php
  • Central ErrorHandler to catch and render
  • src/Security/Security.php provides helpers for sanitization and headers

Publishing

See PUBLISHING.md for full Packagist steps:

  • Tag releases (e.g., v1.0.0)
  • Submit GitHub repo to Packagist
  • Optionally configure auto-update hooks

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

  • Follow PSR-12
  • Add tests when possible
  • Update CHANGELOG.md for user-facing changes

Security issues? See SECURITY.md for our policy.

License

MIT. See LICENSE.

FAQ

  • Where do I define routes?
    • In public/index.php using Router.
  • How do I enable auth-protected pages?
    • Register AuthMiddleware on routes or controllers.
  • Does it support JSON APIs?
    • Yes. Use Response to return JSON and skip views.
  • Can I use SQLite?
    • Yes. Configure config/database.php for SQLite with PDO.

Credits

Built with care by the SwiftPHP community.

swiftphp.ma/installer 适用场景与选型建议

swiftphp.ma/installer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 swiftphp.ma/installer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-02