Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hezecom/slim-starter
Slim Framework 4 Starter App
https://github.com/hezecom/slim-starter
authentication mysql php php-framework php74 php8 postgresql slim slim-4 slim-framework sqlite twig
Last synced: about 1 month ago
JSON representation
Slim Framework 4 Starter App
- Host: GitHub
- URL: https://github.com/hezecom/slim-starter
- Owner: hezecom
- Created: 2021-10-15T11:10:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-25T08:01:00.000Z (about 3 years ago)
- Last Synced: 2024-09-29T20:01:20.492Z (about 2 months ago)
- Topics: authentication, mysql, php, php-framework, php74, php8, postgresql, slim, slim-4, slim-framework, sqlite, twig
- Language: HTML
- Homepage:
- Size: 62.5 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Slim Framework 4 Starter App
> 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
```shell
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='[email protected]'
MAIL_FROM_NAME='Example'
```## Router
Routing example below
```php
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
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](https://github.com/Respect/Validation)
```php
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](http://www.slimframework.com/docs/)
## Directory Structure
```shell
|-- slim-born
|-- app
|-- Auth
|-- Controllers
|-- Middleware
|-- Models
|-- Lib
|-- bootstrap
|-- app.php
|-- database.php
|-- helper.php
|-- logs
|-- public
|-- resources
|-- route
....
```## Testing
``` bash
$ 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](https://opensource.org/licenses/MIT).