poabob / slim-4-framework
A Restful PHP Microservice Framework!
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 0
Type:project
Requires
- php: >=8.0
- catfan/medoo: ^2.1
- lcobucci/jwt: ^4.0
- php-di/php-di: ^6.4
- selective/basepath: ^2.1
- slim/http: ^1.0
- slim/psr7: ^1.0
- slim/slim: ^4.10
- symfony/dotenv: ^6.0
- zircote/swagger-php: ^4.4
Requires (Dev)
- codeception/codeception: ^4.0
- codeception/module-asserts: ^2.0.0
- codeception/module-phpbrowser: ^2.0.0
- codeception/module-rest: ^2.0.0
- docler-labs/codeception-slim-module: ^3.0
README
Introduction
This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api.
Features
- Framework - SLIM 4
- Container - Docker
- Test - Codeception
- Api Document - Swagger-ui
- ORM - Medoo
- CI/CD - Github Actions
Minimal requirements
- docker/docker-compose
- php: >=8.0
- composer
Installation
Run this command from the directory in which you want to install your new Slim application. You will require PHP 8.0 or newer.
composer create-project poabob/slim-4-framework [my-app]
Config
- Write your Db schema
init.sql
CREATE DATABASE IF NOT EXISTS Example;
USE Example;
CREATE TABLE IF NOT EXISTS `Example`.`Users` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `name` VARCHAR(64) NOT NULL, `password` VARCHAR(64) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
- DB config
If you use sqlite for your database, juse commit mysql config.
docker-compose.yml
mysql:
...
environment:
- MYSQL_DATABASE={DB}
- MYSQL_ROOT_PASSWORD={root_password}
- MYSQL_USER={user}
- MYSQL_PASSWORD={user_password}
- Generate Secret Key for Jwt
# Generate PRIVATE KEY
openssl genrsa -out private.pem 2048
# Generate PUBLIC KEY
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
- .env configuration
If you use sqlite for your database, just commit mysql config.
# dev/prod/stage/test
MODE=dev
# MYSQL CONFIG
DB_DRIVER=mysql
DB_NAME={DB}
DB_HOST=mysql
DB_USER={user}
DB_PASS={user_password}
DB_CHARSET=utf8mb4
# SQLITE CONFIG
# DB_DRIVER=sqlite
# DB_NAME={./path/Example.db}
# SETTINGS FOR DEBUG (0/1)
# please don't display error details in production environment.
DISPLAY_ERROR_DETAILS=1
LOG_ERROR_DETAILS=1
LOG_ERRORS=1
# JWT SETTINGS
JWT_ISSUER=SLIM_4
JWT_LIFETIME=86400
JWT_PRIVATE_KEY="{PRIVATE KEY}"
JWT_PUBLIC_KEY="{PUBLIC KEY}"
Run
dev
composer install
composer run start
prod
composer install --no-dev --optimize-autoloader
composer run start
test
<!-- Before you test, please check out your vendor which was instlled. -->
composer run test