From 9ba0cd824661156ad626367a2159ed257b7140c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 9 Sep 2019 08:26:23 +0200 Subject: [PATCH 1/2] Configure symfony to use persistent connections --- frameworks/PHP/symfony/config/packages/doctrine.yaml | 5 +++-- frameworks/PHP/symfony/symfony.dockerfile | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frameworks/PHP/symfony/config/packages/doctrine.yaml b/frameworks/PHP/symfony/config/packages/doctrine.yaml index 1f1096a9b17..f4e37e0f98f 100644 --- a/frameworks/PHP/symfony/config/packages/doctrine.yaml +++ b/frameworks/PHP/symfony/config/packages/doctrine.yaml @@ -2,12 +2,13 @@ doctrine: dbal: # configure these for your database server driver: 'pdo_mysql' - server_version: '5.7' + server_version: '8.0' charset: utf8mb4 default_table_options: charset: utf8mb4 collate: utf8mb4_unicode_ci - + options: + !php/const \PDO::ATTR_PERSISTENT: true url: '%env(resolve:DATABASE_URL)%' orm: auto_generate_proxy_classes: true diff --git a/frameworks/PHP/symfony/symfony.dockerfile b/frameworks/PHP/symfony/symfony.dockerfile index f42d6953581..cc5d5ae45ff 100644 --- a/frameworks/PHP/symfony/symfony.dockerfile +++ b/frameworks/PHP/symfony/symfony.dockerfile @@ -18,6 +18,11 @@ WORKDIR /symfony RUN mkdir -m 777 -p /symfony/var/cache/{dev,prod} /symfony/var/log RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --classmap-authoritative --no-dev RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod + +# removes hardcoded option `ATTR_STATEMENT_CLASS` conflicting with `ATTR_PERSISTENT`. Hack not needed when upgrading to Doctrine 3 +# see https://github.com/doctrine/dbal/issues/2315 +RUN sed -i '/PDO::ATTR_STATEMENT_CLASS/d' ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php + RUN php bin/console cache:clear CMD service php7.3-fpm start && \ From 35c720c0990aef2e7b37d89bc0c99d0ba6681a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 9 Sep 2019 08:59:38 +0200 Subject: [PATCH 2/2] Replace alias by native functions --- frameworks/PHP/symfony/src/Controller/DbController.php | 4 ++-- frameworks/PHP/symfony/src/Controller/DbRawController.php | 4 ++-- frameworks/PHP/symfony/src/Controller/FortunesController.php | 2 +- frameworks/PHP/symfony/symfony-raw.dockerfile | 5 +++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/frameworks/PHP/symfony/src/Controller/DbController.php b/frameworks/PHP/symfony/src/Controller/DbController.php index a0210ccd113..32fe28a9f1f 100644 --- a/frameworks/PHP/symfony/src/Controller/DbController.php +++ b/frameworks/PHP/symfony/src/Controller/DbController.php @@ -36,7 +36,7 @@ public function db(): JsonResponse */ public function queries(Request $request): JsonResponse { - $queries = $request->query->getInt('queries', 1); + $queries = (int) $request->query->get('queries', 1); $queries = min(max($queries, 1), 500); // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php @@ -54,7 +54,7 @@ public function queries(Request $request): JsonResponse */ public function update(Request $request): JsonResponse { - $queries = $request->query->getInt('queries', 1); + $queries = (int) $request->query->get('queries', 1); $queries = min(500, max(1, $queries)); $worlds = []; diff --git a/frameworks/PHP/symfony/src/Controller/DbRawController.php b/frameworks/PHP/symfony/src/Controller/DbRawController.php index 7f16e271510..ffc3f8dbf36 100644 --- a/frameworks/PHP/symfony/src/Controller/DbRawController.php +++ b/frameworks/PHP/symfony/src/Controller/DbRawController.php @@ -35,7 +35,7 @@ public function db(): JsonResponse */ public function queries(Request $request): JsonResponse { - $queries = $request->query->getInt('queries', 1); + $queries = (int) $request->query->get('queries', 1); $queries = min(max($queries, 1), 500); // possibility for enhancement is the use of SplFixedArray -> http://php.net/manual/de/class.splfixedarray.php @@ -55,7 +55,7 @@ public function queries(Request $request): JsonResponse */ public function updates(Request $request): JsonResponse { - $queries = $request->query->getInt('queries', 1); + $queries = (int) $request->query->get('queries', 1); $queries = min(500, max(1, $queries)); $worlds = []; diff --git a/frameworks/PHP/symfony/src/Controller/FortunesController.php b/frameworks/PHP/symfony/src/Controller/FortunesController.php index 22c26f65114..5838bd0262d 100644 --- a/frameworks/PHP/symfony/src/Controller/FortunesController.php +++ b/frameworks/PHP/symfony/src/Controller/FortunesController.php @@ -26,7 +26,7 @@ public function __construct(Environment $twig, FortuneRepository $fortuneReposit */ public function fortunes(): Response { - $fortunes = $this->fortuneRepository->findAll(); + $fortunes = $this->fortuneRepository->findBy([]); $runtimeFortune = new Fortune(); $runtimeFortune->setId(0); diff --git a/frameworks/PHP/symfony/symfony-raw.dockerfile b/frameworks/PHP/symfony/symfony-raw.dockerfile index f42d6953581..cc5d5ae45ff 100644 --- a/frameworks/PHP/symfony/symfony-raw.dockerfile +++ b/frameworks/PHP/symfony/symfony-raw.dockerfile @@ -18,6 +18,11 @@ WORKDIR /symfony RUN mkdir -m 777 -p /symfony/var/cache/{dev,prod} /symfony/var/log RUN COMPOSER_ALLOW_SUPERUSER=1 composer install --classmap-authoritative --no-dev RUN COMPOSER_ALLOW_SUPERUSER=1 composer dump-env prod + +# removes hardcoded option `ATTR_STATEMENT_CLASS` conflicting with `ATTR_PERSISTENT`. Hack not needed when upgrading to Doctrine 3 +# see https://github.com/doctrine/dbal/issues/2315 +RUN sed -i '/PDO::ATTR_STATEMENT_CLASS/d' ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php + RUN php bin/console cache:clear CMD service php7.3-fpm start && \