Skip to content

POABOB/Slim-4-Framework

Repository files navigation

SLIM 4 FRAMEWORK

Build Status Coverage Status PHP Version Require License

Introduction

This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api.

Features

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