承接 caiquebispo/laraslim 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

caiquebispo/laraslim

Composer 安装命令:

composer create-project caiquebispo/laraslim

包简介

A lightweight PHP microframework combining Slim and Laravel features for fast and structured API development.

README 文档

README

LaraSlim Logo

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Description

LaraSlim is a microframework for PHP that combines the lightness of the Slim Framework with a structure inspired by Laravel. It's ideal for creating clean, modular APIs with a lightweight and fast setup.

Note: This project does not include an authentication engine by default. You can integrate your own or use third-party libraries.

It also doesn't include a template engine, but you can integrate it with Blade (Laravel) or any other engine of your choice.

⚠️ This is a beta project: some features may be under development and bugs may occur.

Features

  • 🚀 Lightweight & Fast - Built on Slim Framework 4
  • 🔒 Security First - CORS and Security Headers middlewares included
  • 📝 Centralized Error Handling - PSR-3 logging, JSON error responses
  • 🐳 Docker Ready - Multi-stage builds for dev and production
  • Testing Infrastructure - Pest PHP with HTTP testing helpers
  • 🔧 Environment Validation - Automatic validation of required variables

Requirements

  • PHP ^8.4
  • Docker (optional)
  • Composer

Installation via Composer

composer create-project caiquebispo/laraslim example_app

Quick Start

Using PHP Built-in Server

cd example_app
cp .env.example .env
composer install
php -S localhost:8008 -t public

Using Docker

# Development
docker compose up

# Production
docker compose --profile production up

Docker Commands

Command Description
./bin/build Build Docker containers
./bin/up Start Docker containers
./bin/attach Attach to container
./bin/down Stop Docker containers

Application Access

  • API: http://localhost:8003 (Docker) or http://localhost:8008 (PHP server)
  • PHPMyAdmin: http://localhost:8080 (User: root, Password: root)

Project Structure

app/
├── Contracts/          # Interfaces and contracts
├── Http/
│   ├── Controllers/    # Application controllers
│   ├── Middleware/     # CORS, Security Headers
│   └── Request/        # Form validation
├── Kernel/
│   ├── Exceptions/     # HttpException, ValidationException, Handler
│   └── Providers/      # Service providers (Logging, Database, etc.)
├── Models/             # Eloquent models
├── DTOs/               # Data Transfer Objects
└── Services/           # Business logic
config/
├── app.php             # Application config
├── cors.php            # CORS configuration
└── environments.php    # Environment validation
tests/
├── Feature/            # Feature tests
├── Unit/               # Unit tests
└── Traits/             # Test helpers (DatabaseMigrations, WithFaker)

Environment Configuration

Copy .env.example to .env and configure:

# Application
APP_ENV=local
APP_DEBUG=true

# Database (MySQL)
DB_CONNECTION=mysql
DB_HOST=mysql
DB_DATABASE=LaraSlim_db
DB_USERNAME=root
DB_PASSWORD=root

# Or SQLite
DB_CONNECTION=sqlite
DB_DATABASE=../storage/database.sqlite

Artisan Commands

php artisan-slim make:migration users
php artisan-slim make:model User
php artisan-slim make:controller UserController
php artisan-slim make:request UserRequest
php artisan-slim          # List all commands

Response Helpers

use LaraSlim\Kernel\Providers\Response;

// Success response
return response()->success($data, 'Created', 201);

// Error response
return response()->error('Not found', 404);

// Validation error
return response()->validationError($errors);

// Paginated response
return response()->paginate($items, $total, $page, $perPage);

Exception Handling

use LaraSlim\Kernel\Exceptions\HttpException;

// Throw HTTP exception
throw HttpException::notFound('User not found');
throw HttpException::unauthorized();

// Or use helpers
abort(404, 'Resource not found');
abort_if($condition, 403, 'Forbidden');

Helper Functions

Function Description
env($key, $default) Get environment variable
config($key, $default) Get config value (dot notation)
response() Get Response helper instance
abort($code, $message) Throw HTTP exception
logger() Get PSR-3 logger
info($message) Log info message
base_path($path) Get base path
storage_path($path) Get storage path

Security

LaraSlim includes built-in security middlewares:

  • CORS - Configurable via config/cors.php or environment variables
  • Security Headers - X-Frame-Options, X-Content-Type-Options, HSTS (production)

Testing

# Run all tests
composer test

# Or just Pest
vendor/bin/pest

# With coverage
vendor/bin/pest --coverage

Examples

Route Group

use Slim\Routing\RouteCollectorProxy;

$app->group('/api', function (RouteCollectorProxy $group) {
    $group->get('/users', 'UserController:index');
    $group->post('/users', 'UserController:store');
});

Controller with Response Helper

<?php

namespace LaraSlim\Http\Controllers;

use LaraSlim\Services\UserServices;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class UserController
{
    public function __construct(private UserServices $userServices) {}

    public function store(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $data = $request->getParsedBody();
        $user = $this->userServices->store($data);

        return response($response)->created($user, 'User created successfully');
    }
}

Author

License

This project is licensed under the terms of the MIT License.

caiquebispo/laraslim 适用场景与选型建议

caiquebispo/laraslim 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 8, 最近一次更新时间为 2025 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 caiquebispo/laraslim 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-15