From b08688ccb01819017f627292988939a9b21d6d41 Mon Sep 17 00:00:00 2001 From: Abel Hoogeveen Date: Wed, 24 Nov 2021 20:22:35 +0100 Subject: [PATCH] The PHP 8.0 update, introducing version 1.3.0. Mostly a compatibility update, with some general beautification. The following important changes have been made: --- .drone.yml | 31 +++++++++++++++++-- composer.json | 7 ++--- .../Exception/ObjectStorageException.php | 4 ++- .../ObjectStorage/ObjectStorageCache.php | 14 ++++----- .../ObjectStorage/Provider/FileProvider.php | 8 ++--- test/bootstrap.php | 3 +- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/.drone.yml b/.drone.yml index 7bb2952..9aac83e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: commands: - composer install - - name: dummyprovidertest + - name: dummyprovidertest74 image: registry.i15.nl/i15/fuzephp:7.4-alpine commands: - docker-php-ext-enable xdebug @@ -20,7 +20,7 @@ steps: environment: OBJECTSTORAGE_PROVIDER: DummyProvider - - name: fileprovidertest + - name: fileprovidertest74 image: registry.i15.nl/i15/fuzephp:7.4-alpine commands: - docker-php-ext-enable xdebug @@ -28,7 +28,7 @@ steps: environment: OBJECTSTORAGE_PROVIDER: FileProvider - - name: redisprovidertest + - name: redisprovidertest74 image: registry.i15.nl/i15/fuzephp:7.4-alpine commands: - docker-php-ext-enable xdebug @@ -37,5 +37,30 @@ steps: OBJECTSTORAGE_PROVIDER: RedisProvider OBJECTSTORAGE_REDIS_HOST: cache + - name: dummyprovidertest80 + image: registry.i15.nl/i15/fuzephp:8.0-alpine + commands: + - docker-php-ext-enable xdebug + - vendor/bin/phpunit -c test/phpunit.xml + environment: + OBJECTSTORAGE_PROVIDER: DummyProvider + + - name: fileprovidertest80 + image: registry.i15.nl/i15/fuzephp:8.0-alpine + commands: + - docker-php-ext-enable xdebug + - vendor/bin/phpunit -c test/phpunit.xml + environment: + OBJECTSTORAGE_PROVIDER: FileProvider + + - name: redisprovidertest80 + image: registry.i15.nl/i15/fuzephp:8.0-alpine + commands: + - docker-php-ext-enable xdebug + - vendor/bin/phpunit -c test/phpunit.xml + environment: + OBJECTSTORAGE_PROVIDER: RedisProvider + OBJECTSTORAGE_REDIS_HOST: cache + image_pull_secrets: - dockerconfig \ No newline at end of file diff --git a/composer.json b/composer.json index cc3b012..e516257 100644 --- a/composer.json +++ b/composer.json @@ -1,16 +1,15 @@ { "name": "fuzeworks/objectstorage", - "minimum-stability": "stable", "license": ["MIT"], "authors": [ { "name": "Abel Hoogeveen", - "email": "abel@i15.nl" + "homepage": "https://i15.nl" } ], "require": { "php": ">=7.4.0", - "fuzeworks/core": "~1.2", + "fuzeworks/core": "~1.3.0", "psr/simple-cache": "1.0.1" }, "suggest": { @@ -18,7 +17,7 @@ }, "require-dev": { "phpunit/phpunit": "^9", - "fuzeworks/tracycomponent": "~1.2" + "fuzeworks/tracycomponent": "~1.3.0" }, "autoload": { "psr-4": { diff --git a/src/FuzeWorks/ObjectStorage/Exception/ObjectStorageException.php b/src/FuzeWorks/ObjectStorage/Exception/ObjectStorageException.php index 958840f..05adc82 100644 --- a/src/FuzeWorks/ObjectStorage/Exception/ObjectStorageException.php +++ b/src/FuzeWorks/ObjectStorage/Exception/ObjectStorageException.php @@ -35,6 +35,8 @@ namespace FuzeWorks\ObjectStorage\Exception; -class ObjectStorageException extends \FuzeWorks\Exception\CoreException +use FuzeWorks\Exception\CoreException; + +class ObjectStorageException extends CoreException { } \ No newline at end of file diff --git a/src/FuzeWorks/ObjectStorage/ObjectStorageCache.php b/src/FuzeWorks/ObjectStorage/ObjectStorageCache.php index 02e59ae..7a93ae5 100644 --- a/src/FuzeWorks/ObjectStorage/ObjectStorageCache.php +++ b/src/FuzeWorks/ObjectStorage/ObjectStorageCache.php @@ -65,7 +65,7 @@ class ObjectStorageCache implements CacheInterface return is_null($res) ? $default : $res; } - public function set($key, $value, $ttl = null) + public function set($key, $value, $ttl = null): bool { $meta = [ 'time' => time(), @@ -75,12 +75,12 @@ class ObjectStorageCache implements CacheInterface return $this->provider->save('fwcache_' . $key, $value, $meta); } - public function delete($key) + public function delete($key): bool { return $this->provider->deleteItem('fwcache_' . $key); } - public function clear() + public function clear(): bool { // Fetch the index set $index = $this->provider->getIndex(); @@ -93,7 +93,7 @@ class ObjectStorageCache implements CacheInterface return true; } - public function getMultiple($keys, $default = null) + public function getMultiple($keys, $default = null): array { $out = []; foreach ($keys as $key) @@ -104,7 +104,7 @@ class ObjectStorageCache implements CacheInterface return $out; } - public function setMultiple($values, $ttl = null) + public function setMultiple($values, $ttl = null): bool { foreach ($values as $key => $value) $this->set($key, $value, $ttl); @@ -112,7 +112,7 @@ class ObjectStorageCache implements CacheInterface return true; } - public function deleteMultiple($keys) + public function deleteMultiple($keys): bool { foreach ($keys as $key) $this->delete($key); @@ -120,7 +120,7 @@ class ObjectStorageCache implements CacheInterface return true; } - public function has($key) + public function has($key): bool { $this->testTTL($key); return $this->provider->hasItem('fwcache_' . $key); diff --git a/src/FuzeWorks/ObjectStorage/Provider/FileProvider.php b/src/FuzeWorks/ObjectStorage/Provider/FileProvider.php index f0d4b06..3b9129f 100644 --- a/src/FuzeWorks/ObjectStorage/Provider/FileProvider.php +++ b/src/FuzeWorks/ObjectStorage/Provider/FileProvider.php @@ -37,7 +37,6 @@ namespace FuzeWorks\ObjectStorage\Provider; use FuzeWorks\ObjectStorage\Exception\ObjectStorageException; use FuzeWorks\ObjectStorage\iObjectStorageProvider; use FuzeWorks\Core; -use Traversable; /** * FileProvider @@ -83,7 +82,7 @@ class FileProvider implements iObjectStorageProvider public function init(array $providerConfig): bool { // First load the directory from the providerConfig - $directory = isset($providerConfig['storage_directory']) ? $providerConfig['storage_directory'] : null; + $directory = $providerConfig['storage_directory'] ?? null; // Check if the directory exists if (!file_exists($directory) || !is_dir($directory)) @@ -236,12 +235,11 @@ class FileProvider implements iObjectStorageProvider * * @param string $path File path * @param string $data Data to write - * @param string $mode fopen() mode (default: 'wb') * @return bool */ - private function write_file(string $path, string $data, string $mode = 'wb'): bool + private function write_file(string $path, string $data): bool { - if ( ! $fp = @fopen($path, $mode)) + if ( ! $fp = @fopen($path, 'wb')) return false; flock($fp, LOCK_EX); diff --git a/test/bootstrap.php b/test/bootstrap.php index 9bd0d20..7452e2c 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -36,6 +36,7 @@ require_once(dirname(__DIR__) . '/vendor/autoload.php'); use FuzeWorks\Configurator; +use FuzeWorks\ObjectStorage\ObjectStorageComponent; use FuzeWorks\Priority; $configurator = new Configurator(); @@ -48,7 +49,7 @@ $configurator->setLogDirectory(__DIR__ . '/temp'); $configurator->setTimeZone('Europe/Amsterdam'); // And the star of the show: ObjectStorageComponent -$configurator->addComponent(new \FuzeWorks\ObjectStorage\ObjectStorageComponent()); +$configurator->addComponent(new ObjectStorageComponent()); // Add the test config file $configurator->addDirectory(dirname(__FILE__), 'config', Priority::HIGH);