Skip to content

Commit

Permalink
ref: symfony 7 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafikart authored Nov 1, 2024
1 parent 091e908 commit d821d44
Show file tree
Hide file tree
Showing 457 changed files with 6,095 additions and 5,634 deletions.
17 changes: 9 additions & 8 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
REDIS_URL=redis://redis
REDIS_HOST=localhost
REDIS_POOL=grafikart_cache

TYPESENSE_KEY=typesensekey
TYPESENSE_HOST=typesense:8108

Expand Down Expand Up @@ -41,15 +43,14 @@ MESSENGER_TRANSPORT_DSN=redis://redis:6379/messages
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
# https://symfony.com/doc/current/configuration/secrets.html
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=31cdbe196ba4b896a8ad8ac3fafe71cf
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$'
###< symfony/framework-bundle ###

###> doctrine/doctrine-bundle ###
Expand All @@ -67,14 +68,14 @@ MAILER_DSN=smtp://mail:1025?encryption=null&auth_mode=null
ADMIN_PREFIX=/admin

###> nelmio/cors-bundle ###
CORS_ALLOW_ORIGIN="^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?\$"
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
###< nelmio/cors-bundle ###

###> symfony/mercure-bundle ###
MERCURE_PUBLISH_URL=http://mercure/.well-known/mercure
MERCURE_SUBSCRIBE_URL=http://grafikart.localhost:8001/.well-known/mercure
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.igEPFS-VblsI_at_-WbC7s1nQETOZspaNuwVl3gCQ5M
MERCURE_SUBSCRIBER_KEY=mercure_subscribermercure_subscribermercure_subscribermercure_subscriber
MERCURE_URL=http://mercure/.well-known/mercure
MERCURE_PUBLIC_URL=http://grafikart.localhost:8001/.well-known/mercure
MERCURE_PUBLISHER_SECRET=MercurePublisherJWTSecretForDebugPurpose
MERCURE_SUBSCRIBER_SECRET=MercureSubscriberJWTSecretForDebugPurpose
###< symfony/mercure-bundle ###

###> symfony/messenger ###
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DATABASE_URL=postgresql://test:test@dbtest:5432/test?serverVersion=12&charset=ut
MAILER_DSN=null://null
MESSENGER_TRANSPORT_DSN=sync://
MESSENGER_TRANSPORT_FAILED_DSN=sync://
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Migration.md
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
.phpunit.result.cache
/phpunit.xml
###< symfony/phpunit-bridge ###
Expand All @@ -43,12 +42,6 @@ Migration.md
.idea

###> friendsofphp/php-cs-fixer ###
/.php_cs
/.php_cs.cache
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> squizlabs/php_codesniffer ###
/.phpcs-cache
/phpcs.xml
###< squizlabs/php_codesniffer ###
9 changes: 4 additions & 5 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('var')
;

$config = new PhpCsFixer\Config();
return $config
return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
Expand Down
63 changes: 25 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.PHONY: help deploy sync install build-docker dev devmac dump dumpimport seed migration migrate rollback test tt lint security-check format refactor doc twitch routes provision

isDocker := $(shell docker info > /dev/null 2>&1 && echo 1)
isProd := $(shell grep "APP_ENV=prod" .env.local > /dev/null && echo 1)
domain := "grafikart.fr"
Expand All @@ -10,9 +12,9 @@ bun :=
php :=
ifeq ($(isDocker), 1)
ifneq ($(isProd), 1)
dc := USER_ID=$(user) GROUP_ID=$(group) docker-compose
dcimport := USER_ID=$(user) GROUP_ID=$(group) docker-compose -f docker-compose.import.yml
de := docker-compose exec
dc := USER_ID=$(user) GROUP_ID=$(group) docker compose
dcimport := USER_ID=$(user) GROUP_ID=$(group) docker compose -f docker-compose.import.yml
de := docker compose exec
dr := $(dc) run --rm
drtest := $(dc) -f docker-compose.test.yml run --rm
sy := $(de) php bin/console
Expand All @@ -22,19 +24,18 @@ ifeq ($(isDocker), 1)
endif

.DEFAULT_GOAL := help
.PHONY: help
help: ## Affiche cette aide
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: deploy
deploy: ## Déploie une nouvelle version du site
ssh -A $(server) 'cd $(domain) && git pull origin master && make install'

.PHONY: sync
devdeploy: ## Déploie une nouvelle version du site
ssh -A $(server) 'cd dev.$(domain) && git pull origin develop && make install'

sync: ## Récupère les données depuis le serveur
rsync -avz --ignore-existing --progress --exclude=avatars grafikart:/home/grafikart/grafikart.fr/public/uploads/ ./public/uploads/

.PHONY: install
install: vendor/autoload.php public/assets/.vite/manifest.json ## Installe les différentes dépendances
APP_ENV=prod APP_DEBUG=0 $(php) composer install --no-dev --optimize-autoloader
make migrate
Expand All @@ -43,88 +44,74 @@ install: vendor/autoload.php public/assets/.vite/manifest.json ## Installe les d
$(sy) messenger:stop-workers
sudo service php8.2-fpm reload

.PHONY: build-docker
build-docker:
$(dc) pull --ignore-pull-failures
$(dc) build php
$(dc) build messenger

.PHONY: dev
dev: vendor/autoload.php node_modules/time ## Lance le serveur de développement
dev: node_modules/time ## Lance le serveur de développement
$(dc) up

.PHONY: devmac
devmac: ## Sur MacOS on ne préfèrera exécuter PHP en local pour les performances
docker-compose -f docker-compose.macos.yml up
docker compose -f docker-compose.macos.yml up

.PHONY: dump
dump: var/dump ## Génère un dump SQL
$(de) db sh -c 'PGPASSWORD="grafikart" pg_dump grafikart -U grafikart > /var/www/var/dump/dump.sql'

.PHONY: dumpimport
dumpimport: ## Import un dump SQL
$(de) db sh -c 'pg_restore -c -d grafikart -U grafikart /var/www/var/dump'

.PHONY: seed
seed: vendor/autoload.php ## Génère des données dans la base de données (docker-compose up doit être lancé)
seed: vendor/autoload.php ## Génère des données dans la base de données (docker compose up doit être lancé)
$(sy) doctrine:migrations:migrate -q
$(sy) app:seed -q

.PHONY: migration
migration: vendor/autoload.php ## Génère les migrations
$(sy) make:migration

.PHONY: migrate
migrate: vendor/autoload.php ## Migre la base de données (docker-compose up doit être lancé)
migrate: vendor/autoload.php ## Migre la base de données (docker compose up doit être lancé)
$(sy) doctrine:migrations:migrate -q

.PHONY: rollback
rollback:
$(sy) doctrine:migration:migrate prev

.PHONY: test
test: vendor/autoload.php node_modules/time ## Execute les tests
$(drtest) phptest bin/console doctrine:schema:validate --skip-sync
$(drtest) phptest vendor/bin/paratest -p 4 --runner=WrapperRunner
# $(drtest) phptest vendor/bin/phpunit --filter=ContentSubscriber
# (drtest) phptest bin/phpunit
$(bun) bun run test

.PHONY: tt
tt: vendor/autoload.php ## Lance le watcher phpunit
$(drtest) phptest bin/console cache:clear --env=test
$(drtest) phptest vendor/bin/phpunit-watcher watch --filter="nothing"
$(drtest) phptest bin/console doctrine:schema:validate --skip-sync
$(drtest) phptest bin/phpunit
# $(drtest) phptest bin/console cache:clear --env=test
# $(drtest) phptest vendor/bin/phpunit-watcher watch --filter="nothing"

.PHONY: lint
lint: vendor/autoload.php ## Analyse le code
docker run -v $(PWD):/app -w /app -t --rm php:8.2-cli-alpine php -d memory_limit=-1 bin/console lint:container
docker run -v $(PWD):/app -w /app -t --rm php:8.2-cli-alpine php -d memory_limit=-1 ./vendor/bin/phpstan analyse
docker run -v $(PWD):/app -w /app -t --rm grafikart/php:php8.2-2 php -d memory_limit=-1 bin/console lint:container
docker run -v $(PWD):/app -w /app -t --rm grafikart/php:php8.2-2 php -d memory_limit=-1 ./vendor/bin/phpstan analyse

.PHONY: security-check
security-check: vendor/autoload.php ## Check pour les vulnérabilités des dependencies
$(de) php local-php-security-checker --path=/var/www

.PHONY: format
format: ## Formate le code
npx prettier-standard --lint --changed "assets/**/*.{js,css,jsx}"
docker run -v $(PWD):/app -w /app -t --rm php:8.2-cli-alpine php -d memory_limit=-1 ./vendor/bin/phpcbf
docker run -v $(PWD):/app -w /app -t --rm php:8.2-cli-alpine php -d memory_limit=-1 ./vendor/bin/php-cs-fixer fix
bunx prettier-standard --lint --changed "assets/**/*.{js,css,jsx}"
docker run -v $(PWD):/app -w /app -t --rm grafikart/php:php8.2-2 php -d memory_limit=-1 ./vendor/bin/php-cs-fixer fix

.PHONY: refactor
refactor: ## Reformate le code avec rector
docker run -v $(PWD):/app -w /app -t --rm php:8.2-cli-alpine php -d memory_limit=-1 ./vendor/bin/rector process --clear-cache
docker run -v $(PWD):/app -w /app -t --rm grafikart/php:php8.2-2 php -d memory_limit=-1 ./vendor/bin/rector process src

.PHONY: doc
doc: ## Génère le sommaire de la documentation
npx doctoc ./README.md

.PHONY: twitch
twitch:
twitch event trigger stream.online -F http://localhost:8000/twitch/webhook -s testsecret

routes:
$(de) php bin/console cache:clear

# -----------------------------------
# Déploiement
# -----------------------------------
.PHONY: provision
provision: ## Configure la machine distante
ansible-playbook --vault-password-file .vault_pass -i tools/ansible/hosts.yml tools/ansible/install.yml

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Dépôt pour la nouvelle version de Grafikart.fr. L'objectif est de rendre le pr

- Erreur dans les logs de PHPUnit : https://github.com/symfony/monolog-bundle/pull/336
- Plusieurs listeners Doctrine ne peuvent pas utiliser la même class : https://github.com/doctrine/DoctrineBundle/issues/1224
- Mettre à jour les index côté SQL : https://www.doctrine-project.org/projects/doctrine-dbal/en/4.0/how-to/postgresql-identity-migration.html

## Participer (faire une PR)

Expand Down
4 changes: 2 additions & 2 deletions assets/elements/forum/ForumReport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export function ForumReport ({ message, topic, owner }) {
function ReportForm ({ onSuccess, message, topic }) {
const data = { message: null, topic: null }
if (message) {
data.message = `/api/forum/messages/${message}`
data.message = message
} else if (topic) {
data.topic = `/api/forum/topics/${topic}`
data.topic = topic
} else {
throw new Error('Impossible de charger le formulaire de signalement')
}
Expand Down
40 changes: 9 additions & 31 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,19 @@

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;

if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
return new Application($kernel);
};
24 changes: 17 additions & 7 deletions bin/phpunit
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/usr/bin/env php
<?php

if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}
if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
if (PHP_VERSION_ID >= 80000) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';
} else {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
}
} else {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit d821d44

Please sign in to comment.