From 5b6a1031bf7cfd3b246b814f56d637067a92772d Mon Sep 17 00:00:00 2001 From: Kamil Wylegala Date: Tue, 4 Feb 2025 22:29:07 +0100 Subject: [PATCH] Php8.4 (#83) * SessionHandlerAdapter for Cake's interface. * Removed deprecated E_STRICT. --- .github/workflows/phpcs.yml | 54 ------------------- README.md | 5 ++ lib/Cake/Error/ErrorHandler.php | 4 -- lib/Cake/Model/Datasource/CakeSession.php | 9 ++-- .../Datasource/SessionHandlerAdapter.php | 43 +++++++++++++++ 5 files changed, 51 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/phpcs.yml create mode 100644 lib/Cake/Model/Datasource/SessionHandlerAdapter.php diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml deleted file mode 100644 index 174620946..000000000 --- a/.github/workflows/phpcs.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: PHP Coding Standard - -on: - push: - branches: - - 'master' - pull_request: - branches: - - '*' - -permissions: - contents: read - -jobs: - phpcs: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - php-version: - - '7.4' - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install PHP with extensions - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On - tools: composer - - - name: Composer get cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Cache Composer - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - ${{ runner.os }}-php${{ matrix.php-version }}-composer- - - - name: Install Composer Packages - run: composer install --no-ansi --no-interaction --no-progress --ignore-platform-req=php - - - name: Install CodeSniffer Rule - run: vendors/bin/phpcs --config-set installed_paths vendors/cakephp/cakephp-codesniffer - - - name: Check CodeSniffer - run: vendors/bin/phpcs -p --extensions=php --standard=ruleset.xml ./lib/Cake diff --git a/README.md b/README.md index d5d8e2584..de79003fb 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,11 @@ It means that composer will look at `master` branch of repository configured und ## Changelog +### 2025-02-04 + +- Fixes for PHP 8.4: `session_set_save_handler` accepts object, removed `E_STRICT` reference. +- Removed github action with php code sniffer. It's quite painful to work with. Need to migrate to something newer, that will affect code base as little as possible. + ### 2024-11-16 - Inflector fix: str_place with null. diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index de892f6be..30873d726 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -302,10 +302,6 @@ class ErrorHandler { $error = 'Notice'; $log = LOG_NOTICE; break; - case E_STRICT: - $error = 'Strict'; - $log = LOG_NOTICE; - break; case E_DEPRECATED: case E_USER_DEPRECATED: $error = 'Deprecated'; diff --git a/lib/Cake/Model/Datasource/CakeSession.php b/lib/Cake/Model/Datasource/CakeSession.php index e67731429..3cf7f24de 100644 --- a/lib/Cake/Model/Datasource/CakeSession.php +++ b/lib/Cake/Model/Datasource/CakeSession.php @@ -23,6 +23,8 @@ App::uses('Hash', 'Utility'); App::uses('Security', 'Utility'); +App::uses('SessionHandlerAdapter', 'Model/Datasource'); + /** * Session class for CakePHP. @@ -591,12 +593,7 @@ class CakeSession { $handler = static::_getHandler($sessionConfig['handler']['engine']); if (!function_exists('session_status') || session_status() !== PHP_SESSION_ACTIVE) { session_set_save_handler( - array($handler, 'open'), - array($handler, 'close'), - array($handler, 'read'), - array($handler, 'write'), - array($handler, 'destroy'), - array($handler, 'gc') + new SessionHandlerAdapter($handler) ); } } diff --git a/lib/Cake/Model/Datasource/SessionHandlerAdapter.php b/lib/Cake/Model/Datasource/SessionHandlerAdapter.php new file mode 100644 index 000000000..473701184 --- /dev/null +++ b/lib/Cake/Model/Datasource/SessionHandlerAdapter.php @@ -0,0 +1,43 @@ +cakeSessionHandler->close(); + } + + public function destroy(string $id) + { + return $this->cakeSessionHandler->destroy($id); + } + + public function gc(int $max_lifetime) + { + return $this->cakeSessionHandler->gc($max_lifetime); + } + + public function open(string $path, string $name) + { + //Cake interface ignores these parameters. + return $this->cakeSessionHandler->open(); + } + + public function read(string $id) + { + return $this->cakeSessionHandler->read($id); + } + + public function write(string $id, string $data) + { + return $this->cakeSessionHandler->write($id, $data); + } +}