Skip to content

Commit fadf100

Browse files
committed
PHP 8.5 support
This commit adds support for building a docker image based on PHP 8.5 (RC). It also removes some unused code in tests that was triggering deprecation warnings. For similar deprecation warnings coming from testbench we have a temporary patch script until this is resolved upstream. This commit also adds logic to the DisallowSqliteAttach feature leveraging the new native setAuthorizer() method, instead of loading a compiled extension. We also remove the unused `php` parameter from ci.yml
1 parent 91f6c61 commit fadf100

File tree

7 files changed

+53
-25
lines changed

7 files changed

+53
-25
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
matrix:
1818
include:
1919
- laravel: "^12.0"
20-
php: "8.4"
2120

2221
steps:
2322
- name: Checkout

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,9 @@ Use `composer phpstan` to run our phpstan suite.
4949
Create `.env` with `PROJECT_PATH=/full/path/to/this/directory`. Configure a Docker-based interpreter for tests (with exec, not run).
5050

5151
If you want to use XDebug, use `composer docker-rebuild-with-xdebug`.
52+
53+
## PHP 8.5
54+
55+
To use PHP 8.5 during development, run:
56+
- `PHP_VERSION=8.5.0RC2 composer docker-rebuild` to build the `test` container with PHP 8.5
57+
- `composer php85-patch` to get rid of some deprecation errors coming from `config/database.php` from within testbench-core

Dockerfile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
11
ARG PHP_VERSION=8.4
2-
32
FROM php:${PHP_VERSION}-cli-bookworm
43
SHELL ["/bin/bash", "-c"]
54

6-
RUN apt-get update && apt-get install -y --no-install-recommends \
7-
git unzip libzip-dev libicu-dev libmemcached-dev zlib1g-dev libssl-dev sqlite3 libsqlite3-dev libpq-dev mariadb-client
5+
RUN apt-get update
86

97
RUN apt-get install -y gnupg2 \
108
&& curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \
119
&& curl https://packages.microsoft.com/config/debian/12/prod.list > /etc/apt/sources.list.d/mssql-release.list \
1210
&& apt-get update \
1311
&& ACCEPT_EULA=Y apt-get install -y unixodbc-dev msodbcsql18
1412

13+
RUN apt-get install -y --no-install-recommends \
14+
git unzip libzip-dev libicu-dev libmemcached-dev zlib1g-dev libssl-dev sqlite3 libsqlite3-dev libpq-dev mariadb-client
15+
1516
RUN apt autoremove && apt clean
1617

1718
RUN pecl install apcu && docker-php-ext-enable apcu
1819
RUN pecl install pcov && docker-php-ext-enable pcov
19-
RUN pecl install redis && docker-php-ext-enable redis
20+
RUN pecl install redis-6.3.0RC1 && docker-php-ext-enable redis
2021
RUN pecl install memcached && docker-php-ext-enable memcached
21-
RUN pecl install pdo_sqlsrv && docker-php-ext-enable pdo_sqlsrv
2222
RUN docker-php-ext-install zip && docker-php-ext-enable zip
2323
RUN docker-php-ext-install intl && docker-php-ext-enable intl
2424
RUN docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql
2525
RUN docker-php-ext-install pdo_pgsql && docker-php-ext-enable pdo_pgsql
2626

27+
RUN if [[ "${PHP_VERSION}" == *"8.5"* ]]; then \
28+
mkdir sqlsrv \
29+
&& cd sqlsrv \
30+
&& pecl download pdo_sqlsrv-5.12.0 \
31+
&& tar xzf pdo_sqlsrv-5.12.0.tgz \
32+
&& cd pdo_sqlsrv-5.12.0 \
33+
&& sed -i 's/= dbh->error_mode;/= static_cast<pdo_error_mode>(dbh->error_mode);/' pdo_dbh.cpp \
34+
&& sed -i 's/zval_ptr_dtor( &dbh->query_stmt_zval );/OBJ_RELEASE(dbh->query_stmt_obj);dbh->query_stmt_obj=NULL;/' php_pdo_sqlsrv_int.h \
35+
&& phpize \
36+
&& ./configure --with-php-config=$(which php-config) \
37+
&& make -j$(nproc) \
38+
&& cp modules/pdo_sqlsrv.so $(php -r 'echo ini_get("extension_dir");') \
39+
&& cd / \
40+
&& rm -rf /sqlsrv; \
41+
else \
42+
pecl install pdo_sqlsrv; \
43+
fi
44+
45+
RUN docker-php-ext-enable pdo_sqlsrv
46+
2747
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
2848
RUN echo "apc.enable_cli=1" >> "$PHP_INI_DIR/php.ini"
2949

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@
6565
"docker-restart": "docker compose down && docker compose up -d",
6666
"docker-rebuild": [
6767
"Composer\\Config::disableProcessTimeout",
68-
"PHP_VERSION=8.4 docker compose up -d --no-deps --build"
68+
"docker compose up -d --no-deps --build"
6969
],
7070
"docker-rebuild-with-xdebug": [
7171
"Composer\\Config::disableProcessTimeout",
72-
"PHP_VERSION=8.4 XDEBUG_ENABLED=true docker compose up -d --no-deps --build"
72+
"XDEBUG_ENABLED=true docker compose up -d --no-deps --build"
7373
],
7474
"docker-m1": "ln -s docker-compose-m1.override.yml docker-compose.override.yml",
75+
"php85-patch": [
76+
"php -r '$file=\"vendor/orchestra/testbench-core/laravel/config/database.php\"; file_put_contents($file, str_replace(\"PDO::MYSQL_ATTR_SSL_CA\", \"Pdo\\\\Mysql::ATTR_SSL_CA\", file_get_contents($file)));'"
77+
],
7578
"testbench-unlink": "rm ./vendor/orchestra/testbench-core/laravel/vendor",
7679
"testbench-link": "ln -s /var/www/html/vendor ./vendor/orchestra/testbench-core/laravel/vendor",
7780
"testbench-repair": "mkdir -p ./vendor/orchestra/testbench-core/laravel/storage/framework/sessions && mkdir -p ./vendor/orchestra/testbench-core/laravel/storage/framework/views && mkdir -p ./vendor/orchestra/testbench-core/laravel/storage/framework/cache",

src/Features/DisallowSqliteAttach.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function bootstrap(): void
1919
// Handle any already resolved connections
2020
foreach (DB::getConnections() as $connection) {
2121
if ($connection instanceof SQLiteConnection) {
22-
if (! $this->loadExtension($connection->getPdo())) {
22+
if (! $this->setAuthorizer($connection->getPdo())) {
2323
return;
2424
}
2525
}
@@ -28,16 +28,19 @@ public function bootstrap(): void
2828
// Apply the change to all sqlite connections resolved in the future
2929
DB::extend('sqlite', function ($config, $name) {
3030
$conn = app(ConnectionFactory::class)->make($config, $name);
31-
$this->loadExtension($conn->getPdo());
31+
$this->setAuthorizer($conn->getPdo());
3232

3333
return $conn;
3434
});
3535
}
3636

37-
protected function loadExtension(PDO $pdo): bool
37+
protected function setAuthorizer(PDO $pdo): bool
3838
{
39-
// todo@php85 In PHP 8.5, we can use setAuthorizer() instead of loading an extension.
40-
// However, this is currently blocked on https://github.com/phpredis/phpredis/issues/2688
39+
if (PHP_VERSION_ID >= 80500) {
40+
$this->setNativeAuthorizer($pdo);
41+
return true;
42+
}
43+
4144
static $loadExtensionSupported = method_exists($pdo, 'loadExtension');
4245

4346
if ((! $loadExtensionSupported) ||
@@ -64,4 +67,13 @@ protected function loadExtension(PDO $pdo): bool
6467

6568
return true;
6669
}
70+
71+
protected function setNativeAuthorizer(PDO $pdo): void
72+
{
73+
$pdo->setAuthorizer(static function (int $action): int {
74+
return $action === 24 // SQLITE_ATTACH
75+
? Pdo\Sqlite::DENY
76+
: Pdo\Sqlite::OK;
77+
});
78+
}
6779
}

tests/TenantDatabaseManagerTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,6 @@
245245
'prefix_indexes' => true,
246246
'strict' => true,
247247
'engine' => null,
248-
'options' => extension_loaded('pdo_mysql') ? array_filter([
249-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
250-
]) : [],
251248
],
252249
]);
253250

@@ -293,9 +290,6 @@
293290
'prefix_indexes' => true,
294291
'strict' => true,
295292
'engine' => null,
296-
'options' => extension_loaded('pdo_mysql') ? array_filter([
297-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
298-
]) : [],
299293
],
300294
]);
301295

@@ -333,9 +327,6 @@
333327
'prefix_indexes' => true,
334328
'strict' => true,
335329
'engine' => null,
336-
'options' => extension_loaded('pdo_mysql') ? array_filter([
337-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
338-
]) : [],
339330
],
340331
]);
341332

tests/TestCase.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ protected function getEnvironmentSetUp($app)
144144
'prefix_indexes' => true,
145145
'strict' => true,
146146
'engine' => null,
147-
'options' => extension_loaded('pdo_mysql') ? array_filter([
148-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
149-
]) : [],
150147
],
151148
'database.connections.sqlite.database' => ':memory:',
152149
'database.connections.mysql.charset' => 'utf8mb4',

0 commit comments

Comments
 (0)