Browse Source

[symfony-raw] Fix and update to PHP 8.1 (#7102)

* [symfony-raw] Fix and update to PHP 8.1

* Small change to run tests in github
Joan Miquel 3 years ago
parent
commit
27683f818e

+ 6 - 7
frameworks/PHP/symfony/src/Controller/DbRawController.php

@@ -24,10 +24,9 @@ class DbRawController
     public function db(): JsonResponse
     {
         $statement = $this->connection->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
-        $statement->execute([mt_rand(1, 10000)]);
-        $world = $statement->fetch(FetchMode::ASSOCIATIVE);
+        $world = $statement->execute([mt_rand(1, 10000)]);
 
-        return new JsonResponse($world);
+        return new JsonResponse($world->fetchAssociative());
     }
 
     /**
@@ -43,8 +42,8 @@ class DbRawController
 
         $statement = $this->connection->prepare('SELECT id,randomNumber FROM World WHERE id = ?');
         for ($i = 0; $i < $queries; ++$i) {
-            $statement->execute([mt_rand(1, 10000)]);
-            $worlds[] = $statement->fetch(FetchMode::ASSOCIATIVE);
+            $world = $statement->execute([mt_rand(1, 10000)]);
+            $worlds[] = $world->fetchAssociative();
         }
 
         return new JsonResponse($worlds);
@@ -65,8 +64,8 @@ class DbRawController
 
         for ($i = 0; $i < $queries; ++$i) {
             $id = mt_rand(1, 10000);
-            $readStatement->execute([$id]);
-            $world =  $readStatement->fetch(FetchMode::ASSOCIATIVE);
+            $world = $readStatement->execute([$id]);
+            $world =  $world->fetchAssociative();
             $writeStatement->execute(
                 [$world['randomNumber'] = mt_rand(1, 10000), $id]
             );

+ 8 - 8
frameworks/PHP/symfony/symfony-raw.dockerfile

@@ -6,13 +6,13 @@ RUN apt-get update -yqq && apt-get install -yqq software-properties-common > /de
 RUN LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 RUN apt-get update -yqq > /dev/null && \
     apt-get install -yqq nginx git unzip curl \
-    php8.0-cli php8.0-fpm php8.0-mysql  \
-    php8.0-mbstring php8.0-xml php8.0-curl > /dev/null
+    php8.1-cli php8.1-fpm php8.1-mysql  \
+    php8.1-mbstring php8.1-xml php8.1-curl > /dev/null
 
 RUN curl -sSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
 
-COPY deploy/conf/* /etc/php/8.0/fpm/
-RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.0/fpm/php-fpm.conf ; fi;
+COPY deploy/conf/* /etc/php/8.1/fpm/
+RUN if [ $(nproc) = 2 ]; then sed -i "s|pm.max_children = 1024|pm.max_children = 512|g" /etc/php/8.1/fpm/php-fpm.conf ; fi;
 
 WORKDIR /symfony
 ADD ./composer.json /symfony/
@@ -24,12 +24,12 @@ 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 sed -i '/PDO::ATTR_STATEMENT_CLASS/d' ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php
 
-RUN php bin/console cache:clear
-RUN echo "opcache.preload=/symfony/var/cache/prod/App_KernelProdContainer.preload.php" >> /etc/php/8.0/fpm/php.ini
+RUN php bin/console cache:clear 
+RUN echo "opcache.preload=/symfony/var/cache/prod/App_KernelProdContainer.preload.php" >> /etc/php/8.1/fpm/php.ini
 
 EXPOSE 8080
 
-CMD service php8.0-fpm start && \
+CMD service php8.1-fpm start && \
     nginx -c /symfony/deploy/nginx.conf