diff --git a/.env b/.env new file mode 100644 index 000000000..e69de29bb diff --git a/.env.test b/.env.test new file mode 100644 index 000000000..bc2dfd14b --- /dev/null +++ b/.env.test @@ -0,0 +1,74 @@ +APP_ENV=test + +## App configuration +DATABASE_HOST=dbtest +DATABASE_PORT=3306 +DATABASE_NAME=web +DATABASE_USER=afup +DATABASE_PASSWORD=afup + +SECRET=ThisTokenIsNotSoSecretChangeIt + +GITHUB_CLIENT_ID=id +GITHUB_CLIENT_SECRET=secret + +ALGOLIA_APP_ID=DVB92YWTPE +ALGOLIA_BACKEND_API_KEY=78e71e5r5c2Rb353f5a03376gb9878779 +ALGOLIA_FRONTEND_API_KEY=74e71e5r5c2Rb353f5a03376gb9878777 + +HOME_ALGOLIA_ENABLED=false + +SLACK_URL=http://yolo + +BLUESKY_API_IDENTIFIER=xxx +BLUESKY_API_APP_PASSWORD=yyy + +MAILCHIMP_API_KEY=xxx-yyyy +MAILCHIMP_MEMBERS_LIST= +MAILCHIMP_SUBSCRIBERS_LIST= +MAILCHIMP_TECHLETTER_LIST= +MAILCHIMP_TECHLETTER_API_KEY=xxx-yyyy +MAILCHIMP_TECHLETTER_WEBHOOK_KEY="abc" + +GOOGLE_MAPS_API_KEY= + +MEETUP_API_CONSUMER_KEY= +MEETUP_API_CONSUMER_SECRET= + +TECHNO_WATCH_CALENDAR_URL=https://docs.google.com/spreadsheets/d/2cUeAk86Ov7BLYyn0Ad9ge3ecbsdboeQH64wIU9a9Zzp/export?format=csv +TECHNO_WATCH_CALENDAR_KEY=9Yt0feebMyMrUWx + +SUPER_APERO_CSV_URL=../tests/behat/files/super_apero.csv + +GOOGLE_ANALYTICS_ENABLED=false +GOOGLE_ANALYTICS_ID=G-CHPWDR3C1M + +TECHLETTER_TEST_EMAIL_ADDRESS=pole-veille@afup.org + +SLACK_MEMBERS_LEGACY_TOKEN=aaaa-90909097 + +SLACK_API_URL=https://slack.com/api +SLACK_MEMBRE_TOKEN= + +RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI +RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe + +PAYBOX_DOMAIN_SERVER=preprod-tpeweb.paybox.com +PAYBOX_SECRET_KEY=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF +PAYBOX_SITE=1999888 +PAYBOX_RANG=32 +PAYBOX_IDENTIFIANT=110647233 + +BLOG_API_KEY=123456 + +SMTP_HOST="localhost" +SMTP_PORT=1025 +SMTP_TLS=0 +SMTP_USERNAME="" +SMTP_PASSWORD="" + +QR_CODE_SALT="" +# https://symfony.com/doc/current/reference/configuration/framework.html#ide +IDE_USED="phpstorm" + +AFUP_GLOBAL_MENU_EVENT_LABEL="Forum PHP" diff --git a/.gitignore b/.gitignore index a356abd5c..a5a8b3420 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ -.env +/.env.local +/.env.local.php +/.env.*.local deps.lock .idea diff --git a/Makefile b/Makefile index efb9984ef..bfe66f758 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ --include .env default: help # Variables @@ -51,7 +50,7 @@ init: htdocs/uploads ##@ Docker ### Démarrer les containers -docker-up: .env var/logs/.docker-build data compose.override.yml +docker-up: .env.local var/logs/.docker-build data compose.override.yml $(DOCKER_COMP) up $(DOCKER_UP_OPTIONS) ### Stopper les containers @@ -154,8 +153,8 @@ var/logs/.docker-build: compose.yml compose.override.yml $(shell find docker -ty CURRENT_UID=$(CURRENT_UID) ENABLE_XDEBUG=$(ENABLE_XDEBUG) $(DOCKER_COMPOSE_BIN) build touch var/logs/.docker-build -.env: - cp .env.dist .env +.env.local: + cp .env.dist .env.local compose.override.yml: cp compose.override.yml-dist compose.override.yml diff --git a/app/config/config.php b/app/config/config.php deleted file mode 100644 index abe8a5af9..000000000 --- a/app/config/config.php +++ /dev/null @@ -1,32 +0,0 @@ -setParameter($name, $value); -} diff --git a/app/config/config.yml b/app/config/config.yml index fcf8c9ff5..72d530cce 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -1,4 +1,3 @@ imports: - - { resource: config.php } - { resource: services.yml } - { resource: packages/*.yaml } diff --git a/app/config/packages/ewz_recaptcha.yaml b/app/config/packages/ewz_recaptcha.yaml index 9d8881561..dafd6d6a7 100644 --- a/app/config/packages/ewz_recaptcha.yaml +++ b/app/config/packages/ewz_recaptcha.yaml @@ -1,3 +1,3 @@ ewz_recaptcha: - public_key: '%recaptcha_public_key%' - private_key: '%recaptcha_private_key%' + public_key: '%env(RECAPTCHA_PUBLIC_KEY)%' + private_key: '%env(RECAPTCHA_PRIVATE_KEY)%' diff --git a/app/config/packages/framework.yaml b/app/config/packages/framework.yaml index e47d0b9b7..1803697bf 100644 --- a/app/config/packages/framework.yaml +++ b/app/config/packages/framework.yaml @@ -4,7 +4,7 @@ framework: fallbacks: ["%locale%"] enabled: true default_path: "%kernel.project_dir%/../translations" - secret: "%secret%" + secret: "%env(SECRET)%" router: resource: "%kernel.project_dir%/config/routing.yml" strict_requirements: ~ diff --git a/app/config/packages/knpu_oauth2_client.yaml b/app/config/packages/knpu_oauth2_client.yaml index 42a050629..379cfa378 100644 --- a/app/config/packages/knpu_oauth2_client.yaml +++ b/app/config/packages/knpu_oauth2_client.yaml @@ -3,7 +3,7 @@ knpu_oauth2_client: # will create a service: knpu.oauth2.client.facebook_main github_main: type: github - client_id: "%github_client_id%" - client_secret: "%github_client_secret%" + client_id: "%env(GITHUB_CLIENT_ID)%" + client_secret: "%env(GITHUB_CLIENT_SECRET)%" # see below redirect_route: connection_github_check diff --git a/app/config/packages/security.yaml b/app/config/packages/security.yaml index 4ac6cc1c1..6ddcf9948 100644 --- a/app/config/packages/security.yaml +++ b/app/config/packages/security.yaml @@ -67,7 +67,7 @@ security: - { path: ^/admin/(members/reporting|association/relances|talk|slackmembers/check|healthcheck), roles: ROLE_ADMIN} - { path: ^/member, roles: [ROLE_USER, ROLE_MEMBER_EXPIRED]} - { path: ^/admin/, roles: ROLE_MEMBER_EXPIRED } - - { path: ^/blog, allow_if: "request.getClientIp() in ['217.70.189.71', '127.0.0.1', '192.168.42.1'] or request.server.get('ALLOW_BLOG_FROM_ALL') == 1 or request.headers.get('x-afup-blog-api-key') == '%blog_api_key%'" } + - { path: ^/blog, allow_if: "request.getClientIp() in ['217.70.189.71', '127.0.0.1', '192.168.42.1'] or request.server.get('ALLOW_BLOG_FROM_ALL') == 1 or request.headers.get('x-afup-blog-api-key') == '%env(BLOG_API_KEY)%'" } - { path: ^/blog, roles: ROLE_NO_ACCESS } - { path: ^/(event/\w+/tickets|association)paybox-callback, roles: PUBLIC_ACCESS, ips: "%paybox_ips%" } - { path: ^/(event/\w+/tickets|association)paybox-callback, roles: ROLE_SUPER_ADMIN } diff --git a/app/config/packages/ting.yaml b/app/config/packages/ting.yaml index 957263fa2..63605869c 100644 --- a/app/config/packages/ting.yaml +++ b/app/config/packages/ting.yaml @@ -4,10 +4,10 @@ ting: namespace: CCMBenchmark\Ting\Driver\Mysqli charset: utf8mb4 master: - host: "%database_host%" - port: "%database_port%" - user: "%database_user%" - password: "%database_password%" + host: "%env(DATABASE_HOST)%" + port: "%env(int:DATABASE_PORT)%" + user: "%env(DATABASE_USER)%" + password: "%env(DATABASE_PASSWORD)%" repositories: event: @@ -16,46 +16,46 @@ ting: options: default: connection: main - database: '%database_name%' + database: '%env(DATABASE_NAME)%' site: namespace : AppBundle\Site\Model\Repository directory : "@AppBundle/Site/Model/Repository" options: default: connection: main - database: '%database_name%' + database: '%env(DATABASE_NAME)%' accounting: namespace: AppBundle\Accounting\Model\Repository directory: "@AppBundle/Accounting/Model/Repository" options: default: connection: main - database: "%database_name%" + database: "%env(DATABASE_NAME)%" association: namespace : AppBundle\Association\Model\Repository directory : "@AppBundle/Association/Model/Repository" options: default: connection: main - database: '%database_name%' + database: '%env(DATABASE_NAME)%' membershipfee: namespace: AppBundle\MembershipFee\Model\Repository directory: "@AppBundle/MembershipFee/Model/Repository" options: default: connection: main - database: "%database_name%" + database: "%env(DATABASE_NAME)%" throttling: namespace : AppBundle\Security\ActionThrottling directory : "@AppBundle/Security/ActionThrottling" options: default: connection: main - database: '%database_name%' + database: '%env(DATABASE_NAME)%' techletter: namespace: AppBundle\TechLetter\Model\Repository directory: "@AppBundle/TechLetter/Model/Repository" options: default: connection: main - database: "%database_name%" + database: "%env(DATABASE_NAME)%" diff --git a/app/config/packages/twig.yaml b/app/config/packages/twig.yaml index 8848a9798..e94925235 100644 --- a/app/config/packages/twig.yaml +++ b/app/config/packages/twig.yaml @@ -3,7 +3,7 @@ twig: strict_variables: "%kernel.debug%" globals: photo_storage: '@AppBundle\CFP\PhotoStorage' - global_menu_event_label: '%afup_global_menu_event_label%' + global_menu_event_label: '%env(AFUP_GLOBAL_MENU_EVENT_LABEL)%' form_themes: ['form_theme.html.twig'] exception_controller: null default_path: "%kernel.project_dir%/../templates" diff --git a/app/config/services.yml b/app/config/services.yml index b102700f9..046ce94b5 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -4,8 +4,8 @@ parameters: app.badge_dir: "%kernel.project_dir%/../htdocs/uploads/badges" app.members_logo_dir: "%kernel.project_dir%/../htdocs/uploads/members_logo" app.general_meetings_dir: "%kernel.project_dir%/../htdocs/uploads/general_meetings_reports" - bluesky.api.identifier: "%bluesky_api_identifier%" - bluesky.api.app_password: "%bluesky_api_app_password%" + bluesky.api.identifier: "%env(BLUESKY_API_IDENTIFIER)%" + bluesky.api.app_password: "%env(BLUESKY_API_APP_PASSWORD)%" services: # service_name: @@ -26,9 +26,9 @@ services: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler: public: false arguments: - - 'mysql:host=%database_host%;port=%database_port%;dbname=%database_name%' - - db_username: '%database_user%' - db_password: '%database_password%' + - 'mysql:host=%env(DATABASE_HOST)%;port=%env(int:DATABASE_PORT)%;dbname=%env(DATABASE_NAME)%' + - db_username: '%env(DATABASE_USER)%' + db_password: '%env(DATABASE_PASSWORD)%' lock_mode: !php/const Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler::LOCK_NONE Laminas\Feed\Reader\Http\ClientInterface: '@PlanetePHP\SymfonyFeedClient' @@ -81,19 +81,19 @@ services: AppBundle\Payment\PayboxFactory: autowire: true - arguments: ["@router", "%paybox_domain_server%", "%paybox_secret_key%", "%paybox_site%", "%paybox_rang%", "%paybox_identifiant%"] + arguments: ["@router", "%env(PAYBOX_DOMAIN_SERVER)%", "%env(PAYBOX_SECRET_KEY)%", "%env(PAYBOX_SITE)%", "%env(PAYBOX_RANG)%", "%env(PAYBOX_IDENTIFIANT)%"] AppBundle\Slack\LegacyClient: - arguments: ["%slack_members_legacy_token%"] + arguments: ["%env(SLACK_MEMBERS_LEGACY_TOKEN)%"] Algolia\AlgoliaSearch\SearchClient: factory: [ Algolia\AlgoliaSearch\SearchClient, create ] - arguments: ["%algolia_app_id%", "%algolia_backend_api_key%"] + arguments: ["%env(ALGOLIA_APP_ID)%", "%env(ALGOLIA_BACKEND_API_KEY)%"] # API/Client Meetup techletter app.mailchimp_techletter_client: class: DrewM\MailChimp\MailChimp - arguments: ["%mailchimp_techletter_api_key%"] + arguments: ["%env(MAILCHIMP_TECHLETTER_API_KEY)%"] public: false app.mailchimp_techletter_api: class: AppBundle\Mailchimp\Mailchimp @@ -103,7 +103,7 @@ services: # API/Client Meetup app.mailchimp_client: class: DrewM\MailChimp\MailChimp - arguments: ["%mailchimp_api_key%"] + arguments: ["%env(MAILCHIMP_API_KEY)%"] public: false app.mailchimp_api: class: AppBundle\Mailchimp\Mailchimp @@ -114,23 +114,27 @@ services: autowire: true arguments: $mailchimp: '@app.mailchimp_techletter_api' - $listId: "%mailchimp_techletter_list%" + $listId: "%env(MAILCHIMP_TECHLETTER_LIST)%" AppBundle\Mailchimp\MailchimpMembersAutoListSynchronizer: autowire: true arguments: $mailchimp: '@app.mailchimp_api' - $listId: "%mailchimp_members_list%" + $listId: "%env(MAILCHIMP_MEMBERS_LIST)%" AppBundle\Email\Mailer\Adapter\MailerAdapter: - class: AppBundle\Email\Mailer\Adapter\PhpMailerAdapter - factory: [AppBundle\Email\Mailer\Adapter\PhpMailerAdapter, createFromConfiguration] - arguments: ['@Afup\Site\Utils\Configuration'] + class: AppBundle\Email\Mailer\Adapter\PhpMailerAdapter + arguments: + $smtpServer: '%env(SMTP_HOST)%' + $tls: '%env(SMTP_TLS)%' + $username: '%env(SMTP_USERNAME)%' + $password: '%env(SMTP_PASSWORD)%' + $port: '%env(SMTP_PORT)%' AppBundle\Mailchimp\EventEventSubscriber: arguments: - '@app.mailchimp_api' - - "%mailchimp_members_list%" + - "%env(MAILCHIMP_MEMBERS_LIST)%" tags: - { name: kernel.event_listener, event: user.disabled, method: onUserDisabled } @@ -140,10 +144,7 @@ services: AppBundle\Event\Ticket\QrCodeGenerator: autowire: true - arguments: ["%qr_code_salt%"] - - Afup\Site\Utils\Configuration: - autowire: true + arguments: ["%env(QR_CODE_SALT)%"] Afup\Site\Utils\LegacyConnectionFactory: ~ Afup\Site\Utils\Base_De_Donnees: @@ -189,7 +190,7 @@ services: geocoder_provider_google_maps: class: Geocoder\Provider\GoogleMaps\GoogleMaps - arguments: ['@Psr\Http\Client\ClientInterface', null, "%google_maps_api_key%"] + arguments: ['@Psr\Http\Client\ClientInterface', null, "%env(GOOGLE_MAPS_API_KEY)%"] AppBundle\Offices\OfficeFinder: arguments: ['@geocoder'] @@ -203,7 +204,7 @@ services: Doctrine\DBAL\Connection: factory: '@AppBundle\Doctrine\ConnectionFactory' arguments: - $url: 'mysql://%database_user%:%database_password%@%database_host%:%database_port%/%database_name%?charset=utf8mb4' + $url: 'mysql://%env(DATABASE_USER)%:%env(DATABASE_PASSWORD)%@%env(DATABASE_HOST)%:%env(DATABASE_PORT)%/%env(DATABASE_NAME)%?charset=utf8mb4' AppBundle\Github\GithubClient: arguments: diff --git a/bin/console b/bin/console index 10c672c81..819332e4e 100755 --- a/bin/console +++ b/bin/console @@ -4,6 +4,7 @@ use AppBundle\AppKernel; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Dotenv\Dotenv; // if you don't want to setup permissions the proper way, just uncomment the following PHP line // read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information @@ -11,13 +12,14 @@ use Symfony\Component\Console\Input\ArgvInput; set_time_limit(0); -/** @var Composer\Autoload\ClassLoader $loader */ -$loader = require __DIR__.'/../vendor/autoload.php'; +require __DIR__.'/../vendor/autoload.php'; $input = new ArgvInput(); $env = $input->getParameterOption(['--env', '-e'], getenv('APP_ENV') ?: 'dev'); $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; +(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env', $env); + $kernel = new AppKernel($env, $debug); $application = new Application($kernel); $application->run($input); diff --git a/compose.yml b/compose.yml index 32903be5e..c6d31b01e 100644 --- a/compose.yml +++ b/compose.yml @@ -35,8 +35,6 @@ services: APP_ENV: "dev" HOST_PWD: ${PWD} SYMFONY_IDE: "%env(IDE_USED)%://open?url=file://%%f&line=%%l&/var/www/html/>%env(HOST_PWD)%/" - env_file: - .env volumes: - ./:/var/www/html links: @@ -54,8 +52,6 @@ services: APP_ENV: "test" HOST_PWD: ${PWD} SYMFONY_IDE: "%env(IDE_USED)%://open?url=file://%%f&line=%%l&/var/www/html/>%env(HOST_PWD)%/" - env_file: - .env volumes: - ./:/var/www/html links: diff --git a/composer.json b/composer.json index c1fafc40e..5be55ec5b 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "symfony/asset": "7.3.*", "symfony/clock": "7.3.*", "symfony/console": "7.3.*", + "symfony/dotenv": "^7.4", "symfony/expression-language": "7.3.*", "symfony/form": "7.3.*", "symfony/framework-bundle": "7.3.*", diff --git a/composer.lock b/composer.lock index fa62bca5f..073f23678 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7175fc353c2cfcab0594fdcd92aa8606", + "content-hash": "1d95d86348fd7fc74918361df94e9992", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -5504,6 +5504,84 @@ ], "time": "2024-09-25T14:21:43+00:00" }, + { + "name": "symfony/dotenv", + "version": "v7.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/dotenv.git", + "reference": "1658a4d34df028f3d93bcdd8e81f04423925a364" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dotenv/zipball/1658a4d34df028f3d93bcdd8e81f04423925a364", + "reference": "1658a4d34df028f3d93bcdd8e81f04423925a364", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "conflict": { + "symfony/console": "<6.4", + "symfony/process": "<6.4" + }, + "require-dev": { + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Dotenv\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Registers environment variables from a .env file", + "homepage": "https://symfony.com", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "support": { + "source": "https://github.com/symfony/dotenv/tree/v7.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2025-11-16T10:14:42+00:00" + }, { "name": "symfony/error-handler", "version": "v7.3.4", diff --git a/doc/dev-setup.md b/doc/dev-setup.md index 70aaaeba0..39f750367 100644 --- a/doc/dev-setup.md +++ b/doc/dev-setup.md @@ -52,7 +52,7 @@ La base de test inclus un utilisateur administration avec les identifiants suiva Plusieurs possibilités de configuration des containers sont disponibles, via l'utilisation de variables d'environnement. -Pour faciliter leur configuration, un fichier `.env` est créé à la racine du projet à la première exécution de la commande `make docker-up`. +Pour faciliter leur configuration, un fichier `.env.local` est créé à la racine du projet à la première exécution de la commande `make docker-up`. Ce fichier contient la liste des options disponibles. ### Options Docker diff --git a/htdocs/index.php b/htdocs/index.php index c13ba7673..ed9ade06f 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -3,12 +3,16 @@ declare(strict_types=1); use AppBundle\AppKernel; -use Composer\Autoload\ClassLoader; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\HttpFoundation\Request; +require __DIR__ . '/../vendor/autoload.php'; + $isDevEnv = isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] == 'dev'; $isTestEnv = isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] == 'test'; +(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env'); + if ($_SERVER['HTTP_HOST'] === 'afup.dev' || $isDevEnv || $isTestEnv) { if (!$isDevEnv && !$isTestEnv && @@ -22,14 +26,8 @@ exit('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.'); } - /** @var ClassLoader $loader */ - $loader = require __DIR__ . '/../vendor/autoload.php'; - $kernel = $isDevEnv ? new AppKernel('dev', true) : new AppKernel('test', true); } else { - /** @var ClassLoader $loader */ - $loader = require __DIR__ . '/../vendor/autoload.php'; - $kernel = new AppKernel('prod', false); } diff --git a/phinx.php b/phinx.php index a03a14c64..05a3d8b91 100644 --- a/phinx.php +++ b/phinx.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use AppBundle\AppKernel; +use Symfony\Component\Dotenv\Dotenv; require 'vendor/autoload.php'; @@ -10,45 +10,15 @@ 'default_migration_table' => 'phinxlog', ]; -if (is_file(__DIR__ . '/vendor/behat/behat/composer.json')) { - $kernelDev = new AppKernel('dev', true); - $kernelDev->boot(); - $containerDev = $kernelDev->getContainer(); - $environments['development'] = [ - 'adapter' => 'mysql', - 'host' => $containerDev->getParameter('database_host'), - 'name' => $containerDev->getParameter('database_name'), - 'user' => $containerDev->getParameter('database_user'), - 'pass' => $containerDev->getParameter('database_password'), - 'port' => $containerDev->getParameter('database_port'), - 'charset' => 'utf8mb4', - ]; +(new Dotenv())->bootEnv(__DIR__ . '/.env'); - $kernelDev = new AppKernel('test', true); - $kernelDev->boot(); - $containerDev = $kernelDev->getContainer(); - $environments['test'] = [ - 'adapter' => 'mysql', - 'host' => $containerDev->getParameter('database_host'), - 'name' => $containerDev->getParameter('database_name'), - 'user' => $containerDev->getParameter('database_user'), - 'pass' => $containerDev->getParameter('database_password'), - 'port' => $containerDev->getParameter('database_port'), - 'charset' => 'utf8mb4', - ]; -} - -$kernelProd = new AppKernel('prod', true); -$kernelProd->boot(); -$containerProd = $kernelProd->getContainer(); - -$environments['production'] = [ +$environments[getenv('APP_ENV') ?: 'dev'] = [ 'adapter' => 'mysql', - 'host' => $containerProd->getParameter('database_host'), - 'name' => $containerProd->getParameter('database_name'), - 'user' => $containerProd->getParameter('database_user'), - 'pass' => $containerProd->getParameter('database_password'), - 'port' => $containerProd->getParameter('database_port'), + 'host' => $_ENV['DATABASE_HOST'], + 'name' => $_ENV['DATABASE_NAME'], + 'user' => $_ENV['DATABASE_USER'], + 'pass' => $_ENV['DATABASE_PASSWORD'], + 'port' => $_ENV['DATABASE_PORT'], 'charset' => 'utf8mb4', ]; diff --git a/phpunit.xml b/phpunit.xml index fd7c6b15f..342721f14 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - + + diff --git a/sources/Afup/Bootstrap/_Common.php b/sources/Afup/Bootstrap/_Common.php index 26f4f4ff2..7eba4635a 100644 --- a/sources/Afup/Bootstrap/_Common.php +++ b/sources/Afup/Bootstrap/_Common.php @@ -21,12 +21,14 @@ // racine de l'application (pas du document root !) use Afup\Site\Corporate\_Site_Base_De_Donnees; -use Afup\Site\Utils\Configuration; +use Symfony\Component\Dotenv\Dotenv; $root = dirname(__DIR__, 3); require_once $root . '/vendor/autoload.php'; +(new Dotenv())->bootEnv(__DIR__ . '/../../../.env'); + // définitions des constantes if (!defined('AFUP_CHEMIN_RACINE')) { define('AFUP_CHEMIN_RACINE', $root . '/htdocs/'); @@ -45,12 +47,6 @@ // préparation de la requête / session require_once __DIR__ . '/../fonctions.php'; -// chargement de la configuration -$conf = new Configuration(); - -// mets la configuration dans une 'clé de registre' accessible à tout moment -$GLOBALS['AFUP_CONF'] = $conf; - // initialisation de la couche d'abstraction de la base de données $bdd = new _Site_Base_De_Donnees(); diff --git a/sources/Afup/Bootstrap/commonStart.php b/sources/Afup/Bootstrap/commonStart.php index 060a41c31..bc438e0ff 100644 --- a/sources/Afup/Bootstrap/commonStart.php +++ b/sources/Afup/Bootstrap/commonStart.php @@ -185,9 +185,9 @@ 'main' => [ 'namespace' => '\CCMBenchmark\Ting\Driver\Mysqli', 'master' => [ - 'host' => $GLOBALS['AFUP_CONF']->obtenir('database_host'), - 'user' => $GLOBALS['AFUP_CONF']->obtenir('database_user'), - 'password' => $GLOBALS['AFUP_CONF']->obtenir('database_password'), + 'host' => $_ENV['DATABASE_HOST'], + 'user' => $_ENV['DATABASE_USER'], + 'password' => $_ENV['DATABASE_PASSWORD'], 'port' => 3306, ], ], @@ -198,7 +198,7 @@ ->batchLoadMetadata( 'AppBundle\Event\Model\Repository', __DIR__ . '/../Event/Model/Repository/*.php', - ['default' => ['database' => $GLOBALS['AFUP_CONF']->obtenir('database_name')]], + ['default' => ['database' => $_ENV['DATABASE_NAME']]], ) ; $services->set('security.csrf.token_manager', fn(): CsrfTokenManager => new CsrfTokenManager()); diff --git a/sources/Afup/Corporate/_Site_Base_De_Donnees.php b/sources/Afup/Corporate/_Site_Base_De_Donnees.php index 6a4da1b57..f9e6afaa5 100644 --- a/sources/Afup/Corporate/_Site_Base_De_Donnees.php +++ b/sources/Afup/Corporate/_Site_Base_De_Donnees.php @@ -5,21 +5,17 @@ namespace Afup\Site\Corporate; use Afup\Site\Utils\Base_De_Donnees; -use Afup\Site\Utils\Configuration; class _Site_Base_De_Donnees extends Base_De_Donnees { public function __construct() { - /** - * @var Configuration $conf - */ - $conf = $GLOBALS['AFUP_CONF']; - parent::__construct($conf->obtenir('database_host'), - $conf->obtenir('database_name'), - $conf->obtenir('database_user'), - $conf->obtenir('database_password'), - $conf->obtenir('database_port'), + parent::__construct( + $_ENV['DATABASE_HOST'], + $_ENV['DATABASE_NAME'], + $_ENV['DATABASE_USER'], + $_ENV['DATABASE_PASSWORD'], + $_ENV['DATABASE_PORT'], ); } } diff --git a/sources/Afup/Utils/Configuration.php b/sources/Afup/Utils/Configuration.php deleted file mode 100644 index 3a5d4a34b..000000000 --- a/sources/Afup/Utils/Configuration.php +++ /dev/null @@ -1,64 +0,0 @@ -loadSymfonyParameters(); - $parameters = [ - 'database_host', 'database_name', 'database_user', 'database_password', 'database_port', - 'smtp_host', 'smtp_port', 'smtp_tls', 'smtp_username', 'smtp_password', - ]; - - foreach ($parameters as $param) { - - // env var exist ? - if (false !== $value = getenv(strtoupper($param))) { - self::$values[$param] = $value; - } - - // override by parameter_ENV.yaml ? - if (isset($sfParameters[$param])) { - self::$values[$param] = $sfParameters[$param]; - } - } - } - - private function loadSymfonyParameters(): array - { - $parameters = []; - $basePath = __DIR__ . '/../../../app/config'; - - if (isset($_ENV['APP_ENV'])) { - $file = $basePath . '/config_' . $_ENV['APP_ENV'] . '.yml'; - if (is_file($file)) { - $values = Yaml::parseFile($file); - if (isset($values['parameters'])) { - $parameters = array_merge($parameters, $values['parameters']); - } - } - } - - return $parameters; - } - - public function obtenir($cle) - { - return self::$values[$cle] ?? null; - } -} diff --git a/sources/Afup/Utils/Mail.php b/sources/Afup/Utils/Mail.php index 9e4d7ede7..c7fd71319 100644 --- a/sources/Afup/Utils/Mail.php +++ b/sources/Afup/Utils/Mail.php @@ -16,12 +16,10 @@ class Mail public static function createMailer(): Mailer { - $configuration = new Configuration(); - return new Mailer( new NullLogger(), new Environment(new FilesystemLoader(self::PROJECT_DIR . '/templates/')), - PhpMailerAdapter::createFromConfiguration($configuration), + PhpMailerAdapter::createFromConfiguration(), ); } } diff --git a/sources/Afup/Utils/SymfonyKernel.php b/sources/Afup/Utils/SymfonyKernel.php index 1f2d8aa19..7669d9bf4 100644 --- a/sources/Afup/Utils/SymfonyKernel.php +++ b/sources/Afup/Utils/SymfonyKernel.php @@ -5,6 +5,7 @@ namespace Afup\Site\Utils; use AppBundle\AppKernel; +use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelInterface; @@ -29,6 +30,8 @@ public function __construct(Request $request = null) $env = 'test'; } + (new Dotenv())->bootEnv(__DIR__ . '/../../../.env', $env); + $this->kernel = new AppKernel($env, $debug); $this->kernel->boot(); if (!$request instanceof Request) { diff --git a/sources/AppBundle/Command/UpdateMailchimpMembersCommand.php b/sources/AppBundle/Command/UpdateMailchimpMembersCommand.php index 0ffae73c7..5d3a676e7 100644 --- a/sources/AppBundle/Command/UpdateMailchimpMembersCommand.php +++ b/sources/AppBundle/Command/UpdateMailchimpMembersCommand.php @@ -21,7 +21,7 @@ public function __construct( #[Autowire('@app.mailchimp_api')] private Mailchimp $mailchimp, private UserRepository $userRepository, - #[Autowire('%mailchimp_members_list%')] + #[Autowire('%env(MAILCHIMP_MEMBERS_LIST)%')] private string $mailchimpMembersList, ) {} diff --git a/sources/AppBundle/Controller/Admin/TechLetter/GenerateAction.php b/sources/AppBundle/Controller/Admin/TechLetter/GenerateAction.php index f6fdf1d65..a109e11b4 100644 --- a/sources/AppBundle/Controller/Admin/TechLetter/GenerateAction.php +++ b/sources/AppBundle/Controller/Admin/TechLetter/GenerateAction.php @@ -19,7 +19,7 @@ public function __construct( #[Autowire('@app.mailchimp_techletter_api')] private readonly Mailchimp $mailchimp, private readonly TechLetterFactory $techLetterFactory, - #[Autowire('%mailchimp_techletter_list%')] + #[Autowire('%env(MAILCHIMP_TECHLETTER_LIST)%')] private readonly string $mailchimpTechletterList, ) {} diff --git a/sources/AppBundle/Controller/Admin/TechLetter/SendTestAction.php b/sources/AppBundle/Controller/Admin/TechLetter/SendTestAction.php index d9214dcd9..9039c0ebe 100644 --- a/sources/AppBundle/Controller/Admin/TechLetter/SendTestAction.php +++ b/sources/AppBundle/Controller/Admin/TechLetter/SendTestAction.php @@ -20,7 +20,7 @@ public function __construct( private readonly SendingRepository $sendingRepository, private readonly Mailer $mailer, private readonly TechLetterFactory $techLetterFactory, - #[Autowire('%techletter_test_email_address%')] + #[Autowire('%env(TECHLETTER_TEST_EMAIL_ADDRESS)%')] private readonly string $techletterTestEmailAddress, ) {} diff --git a/sources/AppBundle/Controller/Website/Global/HomeAction.php b/sources/AppBundle/Controller/Website/Global/HomeAction.php index 9d56e9b73..2ea98b622 100644 --- a/sources/AppBundle/Controller/Website/Global/HomeAction.php +++ b/sources/AppBundle/Controller/Website/Global/HomeAction.php @@ -31,7 +31,7 @@ public function __construct( private readonly CacheItemPoolInterface $cache, private readonly SearchClient $client, private readonly TalkRepository $talkRepository, - #[Autowire('%home_algolia_enabled%')] + #[Autowire('%env(HOME_ALGOLIA_ENABLED)%')] private readonly bool $homeAlgoliaEnabled, ) {} diff --git a/sources/AppBundle/Controller/Website/Meetups/ListAction.php b/sources/AppBundle/Controller/Website/Meetups/ListAction.php index f8aebbb1c..956da2e5f 100644 --- a/sources/AppBundle/Controller/Website/Meetups/ListAction.php +++ b/sources/AppBundle/Controller/Website/Meetups/ListAction.php @@ -14,9 +14,9 @@ final class ListAction extends AbstractController { public function __construct( private readonly ViewRenderer $view, - #[Autowire('%algolia_app_id%')] + #[Autowire('%env(ALGOLIA_APP_ID)%')] private readonly string $algoliaAppId, - #[Autowire('%algolia_frontend_api_key%')] + #[Autowire('%env(ALGOLIA_FRONTEND_API_KEY)%')] private readonly string $algoliaFrontendApikey, ) {} diff --git a/sources/AppBundle/Controller/Website/NewsletterController.php b/sources/AppBundle/Controller/Website/NewsletterController.php index f5b974c99..4e47468b2 100644 --- a/sources/AppBundle/Controller/Website/NewsletterController.php +++ b/sources/AppBundle/Controller/Website/NewsletterController.php @@ -19,7 +19,7 @@ public function __construct( private readonly ViewRenderer $view, #[Autowire('@app.mailchimp_api')] private readonly Mailchimp $mailchimp, - #[Autowire('%mailchimp_subscribers_list%')] + #[Autowire('%env(MAILCHIMP_SUBSCRIBERS_LIST)%')] private readonly string $mailchimpSubscribersList, ) {} diff --git a/sources/AppBundle/Controller/Website/Static/SuperAperoAction.php b/sources/AppBundle/Controller/Website/Static/SuperAperoAction.php index 0d30b18f1..87194a2e3 100644 --- a/sources/AppBundle/Controller/Website/Static/SuperAperoAction.php +++ b/sources/AppBundle/Controller/Website/Static/SuperAperoAction.php @@ -12,7 +12,7 @@ { public function __construct( private ViewRenderer $view, - #[Autowire('%super_apero_csv_url%')] + #[Autowire('%env(SUPER_APERO_CSV_URL)%')] private string $superAperoCsvUrl, ) {} diff --git a/sources/AppBundle/Controller/Website/Talks/ListAction.php b/sources/AppBundle/Controller/Website/Talks/ListAction.php index 26c0fab77..4b4831244 100644 --- a/sources/AppBundle/Controller/Website/Talks/ListAction.php +++ b/sources/AppBundle/Controller/Website/Talks/ListAction.php @@ -16,9 +16,9 @@ final class ListAction extends AbstractController { public function __construct( private readonly ViewRenderer $view, - #[Autowire('%algolia_app_id%')] + #[Autowire('%env(ALGOLIA_APP_ID)%')] private readonly string $algoliaAppId, - #[Autowire('%algolia_frontend_api_key%')] + #[Autowire('%env(ALGOLIA_FRONTEND_API_KEY)%')] private readonly string $algoliaFrontendApikey, ) {} diff --git a/sources/AppBundle/Controller/Website/Techletter/WebhookAction.php b/sources/AppBundle/Controller/Website/Techletter/WebhookAction.php index 9da349ed4..ae4519c41 100644 --- a/sources/AppBundle/Controller/Website/Techletter/WebhookAction.php +++ b/sources/AppBundle/Controller/Website/Techletter/WebhookAction.php @@ -13,7 +13,7 @@ { public function __construct( private TechletterUnsubscriptionsRepository $techletterUnsubscriptionsRepository, - #[Autowire('%mailchimp_techletter_webhook_key%')] + #[Autowire('%env(MAILCHIMP_TECHLETTER_WEBHOOK_KEY)%')] private string $mailchimpTechletterWebhookKey, ) {} diff --git a/sources/AppBundle/Controller/Website/TechnoWatch/CalendarAction.php b/sources/AppBundle/Controller/Website/TechnoWatch/CalendarAction.php index 2b39955a6..71ae88103 100644 --- a/sources/AppBundle/Controller/Website/TechnoWatch/CalendarAction.php +++ b/sources/AppBundle/Controller/Website/TechnoWatch/CalendarAction.php @@ -13,9 +13,9 @@ final class CalendarAction extends AbstractController { public function __construct( - #[Autowire('%techno_watch_calendar_key%')] + #[Autowire('%env(TECHNO_WATCH_CALENDAR_KEY)%')] private readonly string $technoWatchCalendarKey, - #[Autowire('%techno_watch_calendar_url%')] + #[Autowire('%env(TECHNO_WATCH_CALENDAR_URL)%')] private readonly string $technoWatchCalendarUrl, ) {} diff --git a/sources/AppBundle/Email/Mailer/Adapter/PhpMailerAdapter.php b/sources/AppBundle/Email/Mailer/Adapter/PhpMailerAdapter.php index 3510c7b66..4f5af3035 100644 --- a/sources/AppBundle/Email/Mailer/Adapter/PhpMailerAdapter.php +++ b/sources/AppBundle/Email/Mailer/Adapter/PhpMailerAdapter.php @@ -4,7 +4,6 @@ namespace AppBundle\Email\Mailer\Adapter; -use Afup\Site\Utils\Configuration; use AppBundle\Email\Mailer\MailUser; use AppBundle\Email\Mailer\Message; use PHPMailer\PHPMailer\PHPMailer; @@ -20,14 +19,14 @@ public function __construct( private readonly ?string $port, ) {} - public static function createFromConfiguration(Configuration $configuration): self + public static function createFromConfiguration(): self { return new self( - $configuration->obtenir('smtp_host'), - (string) $configuration->obtenir('smtp_tls'), - $configuration->obtenir('smtp_username'), - $configuration->obtenir('smtp_password'), - (string) $configuration->obtenir('smtp_port'), + $_ENV['SMTP_HOST'], + (string) $_ENV['SMTP_TLS'], + $_ENV['SMTP_USERNAME'], + $_ENV['SMTP_PASSWORD'], + (string) $_ENV['SMTP_PORT'], ); } diff --git a/sources/AppBundle/Mailchimp/Runner.php b/sources/AppBundle/Mailchimp/Runner.php index 4abab518e..5e80f1838 100644 --- a/sources/AppBundle/Mailchimp/Runner.php +++ b/sources/AppBundle/Mailchimp/Runner.php @@ -14,7 +14,7 @@ public function __construct( #[Autowire('@app.mailchimp_api')] private Mailchimp $mailchimp, private UserRepository $userRepository, - #[Autowire('%mailchimp_members_list%')] + #[Autowire('%env(MAILCHIMP_MEMBERS_LIST)%')] private string $membersListId, ) {} diff --git a/sources/AppBundle/Notifier/SlackNotifier.php b/sources/AppBundle/Notifier/SlackNotifier.php index 4b7ae98a6..114ec891b 100644 --- a/sources/AppBundle/Notifier/SlackNotifier.php +++ b/sources/AppBundle/Notifier/SlackNotifier.php @@ -16,7 +16,7 @@ final readonly class SlackNotifier { public function __construct( - #[Autowire('%slack_url%')] + #[Autowire('%env(SLACK_URL)%')] private string $postUrl, private MessageFactory $messageFactory, #[Autowire('@jms_serializer.serializer')] diff --git a/sources/AppBundle/Slack/UsersClient.php b/sources/AppBundle/Slack/UsersClient.php index 7b8014352..eee8e8491 100644 --- a/sources/AppBundle/Slack/UsersClient.php +++ b/sources/AppBundle/Slack/UsersClient.php @@ -12,9 +12,9 @@ public const USER_LIST_API = '/users.list'; public function __construct( - #[Autowire('%slack_membre_token%')] + #[Autowire('%env(SLACK_MEMBRE_TOKEN)%')] private string $token, - #[Autowire('%slack_api_url%')] + #[Autowire('%env(SLACK_API_URL)%')] private string $apiBaseUrl, ) {} diff --git a/sources/AppBundle/Twig/TwigExtension.php b/sources/AppBundle/Twig/TwigExtension.php index d6253f9ea..5f922d721 100644 --- a/sources/AppBundle/Twig/TwigExtension.php +++ b/sources/AppBundle/Twig/TwigExtension.php @@ -16,9 +16,9 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface public function __construct( private readonly Parsedown $parsedown, private readonly Parsedown $emailParsedown, - #[Autowire('%google_analytics_enabled%')] + #[Autowire('%env(GOOGLE_ANALYTICS_ENABLED)%')] private readonly string $googleAnalyticsEnabled, - #[Autowire('%google_analytics_id%')] + #[Autowire('%env(GOOGLE_ANALYTICS_ID)%')] private readonly string $googleAnalyticsId, ) {} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 000000000..ad361e028 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,13 @@ +bootEnv(dirname(__DIR__) . '/.env'); + +if ($_SERVER['APP_DEBUG']) { + umask(0000); +}