From 416b95a54908009ca4acd23bdee193808da70935 Mon Sep 17 00:00:00 2001 From: Benoit Foujols Date: Sun, 20 Aug 2023 13:12:59 +0200 Subject: [PATCH] add new release v0.3.0 --- .env.example | 8 +++-- .gitignore | 1 + README.md | 20 ++--------- app/Controller/HomeController.php | 6 ++-- composer.json | 10 +++++- docker/docker-compose-maria-db.yml | 42 +++++++++++++++++++++++ docker/docker-compose-mysql-5.yml | 37 +++++++++++++++++++++ public/index.php | 53 ++++++++++++++---------------- 8 files changed, 125 insertions(+), 52 deletions(-) create mode 100644 docker/docker-compose-maria-db.yml create mode 100644 docker/docker-compose-mysql-5.yml diff --git a/.env.example b/.env.example index 85376e3..0291a20 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,10 @@ DB_HOST_STATUS=false DB_HOST=127.0.0.1 DB_SOCKET=3306 DB_USER=root -DB_PASSWORD= +DB_PASSWORD=root DB_NAME=app_db -## >> Config Database \ No newline at end of file +## >> Config Database + +## << Config préfixe des conteneurs Docker +APP_NAME=edu-framework +## >> Config préfixe des conteneurs Docker diff --git a/.gitignore b/.gitignore index 36e69dc..a972cc3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ # Managed by Composer vendor/ +var/ composer.phar composer.lock diff --git a/README.md b/README.md index 817890a..1ff6ed7 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,4 @@ -![separe](https://github.com/studoo-app/.github/blob/main/profile/studoo-banner-logo.png) -# edu-framework-skeleton -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a15f20cbdf2743618efe54e2db39f605)](https://app.codacy.com/gh/studoo-app/edu-framework/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) -[![Latest Stable Version](https://poser.pugx.org/studoo/edu-framework/v)](//packagist.org/packages/studoo/edu-framework) -[![Total Downloads](https://poser.pugx.org/studoo/edu-framework/downloads)](//packagist.org/packages/studoo/edu-framework) -[![Latest Unstable Version](https://poser.pugx.org/studoo/edu-framework/v/unstable)](//packagist.org/packages/edu-framework) -[![License](https://poser.pugx.org/studoo/edu-framework/license)](//packagist.org/packages/studoo/edu-framework) - -Edu-Framework est une proposition d'architecture MVC pour la création de projets ou de travaux pratiques. L'objectif pédagogique est : -- Appréhender un projet par couche via MVC -- Faire un projet "full POO" et dans les "best practices" attendu par les entreprises -- Orchestrer via un gestionnaire de package (composer) -- Développement de test unitaire -- Début d'approche pour l'enseignement d'un framework (Symfony, Laravel ...) +## Bienvenu dans votre projet avec Edu-Framework > [!NOTE] -> L'ensemble de la documentation est disponible sur le [https://edu-framework.studoo.app/](https://edu-framework.studoo.app/) - -> [!IMPORTANT] -> Ce framework n'est pas adapté à une utilisation en production. Il est destiné à des fins pédagogiques. +> Pour installation et la configuration, voir -> [https://edu-framework.studoo.app/](https://edu-framework.studoo.app/) diff --git a/app/Controller/HomeController.php b/app/Controller/HomeController.php index 84aa512..cc4eaf5 100644 --- a/app/Controller/HomeController.php +++ b/app/Controller/HomeController.php @@ -12,11 +12,13 @@ class HomeController implements ControllerInterface { /** + * @param Request $request Requête HTTP + * @return string|null + * @throws LoaderError * @throws RuntimeError * @throws SyntaxError - * @throws LoaderError */ - public function execute(Request $request): string + public function execute(Request $request): string|null { return TwigCore::getEnvironment()->render('home/home.html.twig', [ diff --git a/composer.json b/composer.json index b43e8d7..a506927 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,14 @@ ], "edu:init": [ "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" - ] + ], + "edu:docker:db-service:start": "Studoo\\EduFramework\\Scripts\\DockerPilot::start", + "edu:docker:db-service:down": "Studoo\\EduFramework\\Scripts\\DockerPilot::down" + }, + "scripts-descriptions": { + "edu:init": "Create env file", + "edu:start": "Start local server", + "edu:docker:db-service:start": "Start docker related database service [args : mysql / maria-db]", + "edu:docker:db-service:down": "Stop and remove docker related database service [args : mysql / maria-db]" } } diff --git a/docker/docker-compose-maria-db.yml b/docker/docker-compose-maria-db.yml new file mode 100644 index 0000000..4ec357a --- /dev/null +++ b/docker/docker-compose-maria-db.yml @@ -0,0 +1,42 @@ +version: "3.8" +services: + ########################## + # CONTENEURS SERVICES # + ########################## + + #Base de données Mysql + database: + container_name: ${APP_NAME}-db + image: mariadb:10.5.8 + restart: always + ports: + - "3306:3306" + volumes: + - ../var/db-data:/var/lib/mysql + environment: + #MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} + MYSQL_DATABASE: ${DB_NAME} + #MYSQL_USER: app_db_user + #MYSQL_PASSWORD: app_db_password + networks: + - dev + #PHP My Admin + phpmyadmin: + container_name: ${APP_NAME}-pma + image: phpmyadmin:latest + restart: always + depends_on: + - database + ports: + - "8081:80" + environment: + PMA_HOST: db + networks: + - dev +#Network +networks: + dev: +#Volumes +volumes: + db-data: diff --git a/docker/docker-compose-mysql-5.yml b/docker/docker-compose-mysql-5.yml new file mode 100644 index 0000000..afc832a --- /dev/null +++ b/docker/docker-compose-mysql-5.yml @@ -0,0 +1,37 @@ +version: "3.8" +services: + + database: + container_name: ${APP_NAME}-database + image: mysql:5.7 + platform: linux/amd64 + ports: + - "3306:3306" + restart: always + environment: + #MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' + MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} + MYSQL_DATABASE: ${DB_NAME} + #MYSQL_USER: app_db_user + #MYSQL_PASSWORD: app_db_password + volumes: + - ../var/dbdata:/var/lib/mysql + #PHP My Admin + phpmyadmin: + container_name: ${APP_NAME}-pma + image: phpmyadmin:latest + restart: always + depends_on: + - database + ports: + - "8081:80" + environment: + PMA_HOST: db + networks: + - dev +#Network +networks: + dev: +#Volumes +volumes: + db-data: diff --git a/public/index.php b/public/index.php index 0d01fdc..83e0a7a 100644 --- a/public/index.php +++ b/public/index.php @@ -1,36 +1,31 @@ chargement automatique des classes depuis le dossier vendor/ -require_once __DIR__ . '/../vendor/autoload.php'; +session_start(); -// Utilisation des classes utilisées dans le fichier -use Controller\HomeController; -use Dotenv\Dotenv; -use Studoo\EduFramework\Core\Controller\FastRouteCore; -use Studoo\EduFramework\Core\Service\DatabaseService; -use Studoo\EduFramework\Core\View\TwigCore; +// Masquer les deprecations de PHP 8.1 +error_reporting(E_ALL & ~E_DEPRECATED); -// Gestion des fichiers environnement .env -$dotenv = Dotenv::createImmutable(__DIR__ . "/../"); -$dotenv->load(); +if (version_compare(PHP_VERSION, '8.0', '<') === false) { + // Autoloader => chargement automatique des classes depuis le dossier vendor/ + require_once __DIR__ . '/../vendor/autoload.php'; -// Gestion de la couche View -(new TwigCore(__DIR__ . '/../app/Template')); -$en = TwigCore::getEnvironment(); + // Chargement des configurations de l'application + (new ConfigCore( + [ + 'base_path' => __DIR__ . '/../', + 'twig_path' => __DIR__ . '/../app/Template', + 'route_config_path' => __DIR__ . '/../app/config/' + ] + ) + ); -// Gestion de la couche Model et de la connexion à la base de données -if ($_ENV['DB_HOST_STATUS'] === 'true') { - (new DatabaseService()); -} - -// Gestion des routes -$route = new FastRouteCore(); -// Load des routes depuis le fichier de configuration -$route->loadRouteConfig(__DIR__ . '/../app/config/'); - -// Récupération de la route à appeler -try { - echo $route->getRoute(); -} catch (\Twig\Error\LoaderError|\Twig\Error\RuntimeError|\Twig\Error\SyntaxError|Exception $e) { - echo $e->getMessage(); + // Chargement des classes utilisées par l'application + (new LoadCouchCore())->run(); +} else { + echo "Cet app nécessite au moins PHP8.0. " + . PHP_VERSION . + " est actuellement installé. Veuillez mettre à jour votre version de PHP.\n"; }