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
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) orhttp://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.phpor 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
- Caique Bispo
📧 caiquebispodanet86@gmail.com
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 caiquebispo/laraslim 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A lightweight, secure-by-default PHP microframework built on Slim – providing Laravel-like features (ORM, authentication, migrations, caching) without the bloat. Perfect for building REST APIs and small-to-medium PHP applications.
Alfabank REST API integration
Reducido núcleo de trabajo para PHP
A Slim Framework MVC skeleton application for rapid development
A TidyPHP is a micro Framework for build fast and tidy web applications
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-15