hezecom/slim-starter
Composer 安装命令:
composer create-project hezecom/slim-starter
包简介
Slim Framework 4 Starter App
README 文档
README
Slim Framework 4 skeleton MVC application with build in authentication system.
Features
- Light weight and organised for easy understanding.
- Simple, fast routing engine.
- Highly secured, ready to use authentication system.
- Simplify helper function for faster development.
- Build in email notification.
- Build in email templates (can easily be modified)
- PSR-7 implementation and PHP-DI container implementation
- Detailed HTML error reporting.
Requirements
- PHP 7.4 | 8.0+
- PDO PHP Extension
- Suport MySQL 5.5.3+ or MariaDB 5.5.23+ or PostgreSQL 9.5.10+ or SQLite 3.14.1+ ...
Installation
composer create-project "hezecom/slim-starter v1.0" [my-app]
Database (Required for auth to work)
- Create a database or use existing database to import/copy to your SQL console to create required tables for the authentication.
- Dasbase option (MySQL, SQLite or PostgreSQL)
- Database file is located at /
database
.env
Copy file .env.example to .env
DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=slimapp
DB_USERNAME=root
DB_PASSWORD=
DB_PORT=3306
# Email setting Driver = (smtp | sendmail | mail)
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS='info@example.com'
MAIL_FROM_NAME='Example'
Router
Routing example below
<?php $app->get('/', 'HomeController:index')->setName('home'); $app->group('', function ($route) { $route->get('/register', AuthController::class . ':createRegister')->setName('register'); $route->post('/register', AuthController::class . ':register'); $route->get('/login', AuthController::class . ':createLogin')->setName('login'); $route->post('/login', AuthController::class . ':login'); $route->get('/verify-email', AuthController::class.':verifyEmail')->setName('verify.email'); $route->get('/verify-email-resend',AuthController::class.':verifyEmailResend')->setName('verify.email.resend'); $route->get('/forgot-password', PasswordController::class . ':createForgotPassword')->setName('forgot.password'); $route->post('/forgot-password', PasswordController::class . ':forgotPassword'); $route->get('/reset-password', PasswordController::class.':resetPassword')->setName('reset.password'); $route->get('/update-password', PasswordController::class.':createUpdatePassword')->setName('update.password'); $route->post('/update-password', PasswordController::class.':updatePassword'); })->add(new GuestMiddleware($container));
Controller
Controller example simplify
<?php namespace App\Controllers; class HomeController extends Controller { public function index(Request $request, Response $response) { return view($response,'index.twig'); } }
Model
Uses Eloquent ORM used by Laravel Framework. It currently supports MySQL, Postgres, SQL Server, and SQLite. Reference - illuminate/database
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; protected $fillable = [ 'email', 'username', 'password', ]; }
Middleware
<?php namespace App\Middleware; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface as RequestHandler; class AuthMiddleware extends Middleware { public function __invoke(Request $request, RequestHandler $handler) { if(! $this->container->get('auth')->isLogin()) { return redirect()->route('login')->with('error', 'Access denied, you need to login.'); } $response = $handler->handle($request); return $response; } }
Validation
Use the most awesome validation engine ever created for PHP. Reference - Respect/Validation
<?php namespace App\Controllers\Auth; use App\Controllers\Controller; use Respect\Validation\Validator as v; class AuthController extends Controller { public function register(Request $request, Response $response) { $validation = $this->validator->validate($request, [ 'email' => v::noWhitespace()->notEmpty()->email(), 'username' => v::noWhitespace()->notEmpty()->alnum(), 'password' => v::notEmpty()->stringType()->length(8), ]); if ($validation->failed()) { redirect()->route('register'); } // more coding here } }
More basic functions
reference slim official documents - Slim Framework
Directory Structure
|-- slim-born |-- app |-- Auth |-- Controllers |-- Middleware |-- Models |-- Lib |-- bootstrap |-- app.php |-- database.php |-- helper.php |-- logs |-- public |-- resources |-- route ....
Testing
$ phpunit
Contributing
All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.
License
This project is licensed under the terms of the MIT License.
hezecom/slim-starter 适用场景与选型建议
hezecom/slim-starter 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 93 次下载、GitHub Stars 达 9, 最近一次更新时间为 2022 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「orm」 「Authentication」 「template」 「Skeleton」 「slim」 「slim 4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hezecom/slim-starter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hezecom/slim-starter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hezecom/slim-starter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
Kinikit - PHP Application development framework MVC component
GraphQL authentication for your headless Craft CMS applications.
PHP Database ORM for Symfony1. Do NOT use for new projects: please move to a newest Symfony release and Doctrine2
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
Email Toolkit Plugin for CakePHP
统计信息
- 总下载量: 93
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-23